一、前言
前段时间,在做内网影响程度评估的时候写了扫描利用小脚本,
扫描后统计发现,内网中60%开放了redis6379端口的主机处于可以被利用的危险状态,因为都是一些默认配置造成的
考虑到本社区大部分开发者都会使用redis,特此分享下以便大家可以对自己公司的内网进行一个排查。
二、漏洞介绍
Redis 默认情况下,会绑定在 0.0.0.0:6379,这样将会将 Redis 服务暴露到公网上,如果在没有开启认证的情况下,可以导致任意用户在可以访问目标服务器的情况下未授权访问 Redis 以及读取 Redis 的数据。攻击者在未授权访问 Redis 的情况下可以利用 Redis 的相关方法,可以成功在 Redis 服务器上写入公钥,进而可以使用对应私钥直接登录目标服务器。
入侵特征:
- Redis 可能执行过 FLUSHALL 方法,整个 Redis 数据库被清空
- 在 Redis 数据库中新建了一个名为 crackit(网上流传的命令指令) 的键值对,内容为一个 SSH 公钥。
- 在 /root/.ssh 文件夹下新建或者修改了 authorized_keys 文件,内容为 Redis 生成的 db 文件,包含上述公钥
三、修复建议
1.禁止一些高危命令
修改 redis.conf 文件,添加
来禁用远程修改 DB 文件地址
2.以低权限运行 Redis 服务
为 Redis 服务创建单独的用户和家目录,并且配置禁止登陆
3.为 Redis 添加密码验证
修改 redis.conf 文件,添加
4.禁止外网访问 Redis
修改 redis.conf 文件,添加或修改
使得 Redis 服务只在当前主机可用
四、扫描工具
1 使用说明
最后,将会生成几个txt文件记录结果
其中:
runasroot.txt 表示redis无认证,且以root运行
noauth.txt 表示redis无认证,但以普通用户运行
rootshell.txt 已写入公钥,可直接以证书登录root用户
像这样:
ssh -i id_rsa root@x.x.x.x
2 工具源代码
就贴下代码吧,各位大牛请在家长陪同下观看
五、相关参考
- http://zone.wooyun.org/content/23858
- https://blog.islandzero.net/2015/11/11/redis-crackit/
- http://blog.knownsec.com/2015/11/analysis-of-redis-unauthorized-of-expolit/
如果代码有写得不合理的地方,还望指出哈