简介
redis是一种key-value键值对的非关系型数据库,默认运行在6379端口
它启动时不会像Apache一样,以一种www-data低权限身份运行。而是以运行者的身份,例如用root权限直接运行redis时,redis的权限就是root权限
其次它的默认配置是无需密码的,也就造成了默认的未授权访问
redis还支持本地存储,也就导致了任意文件写入。从而可以写入私钥,利用私钥直接ssh登录服务器。
操作系统:ubuntu 16.04
ip :192.168.85.128
安装redis
操作系统: centos 6.5
ip :192.168.85.132
下载编译redis
修改下配置文件,不然默认虽然是无密码,但是会有protected模式,导致无法从外部主机连接
bind 127.0.0.1前面加上#号 protected-mode设为no
启动redis
现在下先在本地生成一对密钥
这样就可以在~/.ssh目录下生成一对id_rsa、id_rsa.pub
然后连接靶机redis
这样,我们就把公钥写入对方的服务器了,直接用生成的私钥连接即可
假如报了如下错误
运行下如下两句即可
先开一个终端监听本地的23333端口
利用之前类似的文件写入,写入定时命令
需要等待一会,一般一分钟之内吧,nc就能收到反弹回来的shell了
当redis权限较低,上面两种方法都行不通的时候,可以尝试往web服务中写入一句话,获取webshell
这样,就能在根目录下生成shell.php。访问一下
之前能看到,默认情况下虽然是没有密码,但是会开启protected保护模式
在这情况下,我们尝试连接一下对方redis
kingkk@ubuntu:~/test/redis$ redis-cli -h 192.168.85.132192.168.85.132:6379> infoDENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
可以看到保护模式拒绝了redis的远程连接,所以经常redis都是配合着ssrf这个可以伪造身份的攻击方式一起进行攻击