
Struts2와 PowerShell을 사용하여 CVE-2017-5638 OGNL Injection 취약점을 재현
이 저장소는 SC3010 컴퓨터 보안 과정 프로젝트의 일부입니다.
CVE-2017-5638, Apache Struts 2(버전 2.3.52.3.31 및 2.52.5.10)의 치명적인 원격 코드 실행 취약점을 재현합니다. 이 취약점은 2017년 Equifax 데이터 유출 사건에서 악용되어 약 1억 4700만 명의 개인 기록을 유출한 것으로 유명합니다.
이 취약점은 단일 설계 결함에서 비롯됩니다. Apache Struts가 multipart/form-data 업로드 요청을 파싱하지 못할 때, Content-Type 헤더의 원시 값을 (살균 처리 없이) 오류 메시지에 포함시켜 문자열로 만든 후 OGNL 표현식 평가기에 전달합니다. 따라서 Content-Type 헤더 내에 OGNL 표현식을 넣은 공격자는 서버 측에서 Tomcat 프로세스 사용자 권한으로 이를 실행하게 됩니다.
이 저장소는 다음을 포함합니다:
SC3010-Computer-Security/
├── simulation/
│ ├── backend/ # Vulnerable Apache Struts2 2.3.28 server (Java/Maven)
│ └── attack-script/ # Exploit script for CVE-2017-5638
│ └── exploit_cve_2017_5638.ps1 # PowerShell (cross-platform)
├── struts-src-code/ # Apache Struts2 reference source + legal notices
│ ├── licenses/ # LICENSE, NOTICE, and component licenses
│ └── src/
│ ├── struts2-core/ # Request pipeline classes + vulnerable JakartaMultiPartRequest
│ ├── xwork2/ # ActionContext.java, OgnlUtil.java
│ └── ognl/ # OgnlContext.java
├── diagrams/ # State-machine + sequence diagrams, annotated OGNL payload
└── _notes/ # Background reading
아래 다이어그램은 Struts2 요청 파이프라인의 각 결정 분기를 보여줍니다. 빨간색 경로는 공격자가 강제로 따르는 경로이고, 회색 → ... 분기는 익스플로잇 중에 적용되지 않는 안전한 경로입니다.
flowchart TD
Start([Attacker sends HTTP POST /upload.action<br/>Content-Type: %{OGNL_PAYLOAD}.multipart/form-data])
Start --> PIPE
PIPE["<b>Struts2 filter → wrap → parse pipeline</b><br/>doFilter() → PrepareOperations.wrapRequest()<br/>→ Dispatcher.wrapRequest() → new MultiPartRequestWrapper()"]
PIPE --> D_CT{"Content-Type contains<br/>"multipart/form-data"?"}
D_CT -- "No → normal request ..." --> OUT_NORM([non-upload path ...])
D_CT -- "Yes (attacker appends<br/>.multipart/form-data to payload)" --> PARSE
PARSE[/"<b>JakartaMultiPartRequest.parse()</b><br/>→ Commons FileUpload.parseRequest()"/]
PARSE --> D_VALID{"FileUpload can parse<br/>Content-Type?"}
D_VALID -- "Yes → normal file upload ..." --> OUT_OK([files extracted, action executes ...])
D_VALID -- "No — malformed Content-Type<br/>throws InvalidContentTypeException<br/>(message = raw Content-Type string)" --> CATCH
CATCH["parse() catch block<br/>calls buildErrorMessage(e, {})"]
CATCH --> FIND
FIND[/"<b>buildErrorMessage()</b><br/>→ LocalizedTextUtil.findText(class, errorKey, locale, e.getMessage(), args)"/]
FIND --> D_KEY{"Resource bundle has key<br/>struts.messages.upload.error.*?"}
D_KEY -- "Yes → safe localised message ..." --> OUT_SAFE([error displayed safely ...])
D_KEY -- "No — falls back to<br/>e.getMessage() as the default<br/>(attacker's raw Content-Type)" --> TRANSLATE
TRANSLATE["TextParseUtil.translateVariables()<br/>scans string for %{...} expressions"]
TRANSLATE --> D_OGNL{"String contains<br/>%{...} OGNL expression?"}
D_OGNL -- "No → plain error string ..." --> OUT_PLAIN([safe error message ...])
D_OGNL -- "Yes — evaluates OGNL<br/>inside attacker content" --> SANDBOX
SANDBOX[/"<b>OGNL sandbox bypass</b><br/>#ognlUtil.getExcludedClasses().clear()<br/>#ognlUtil.getExcludedPackageNames().clear()"/]
SANDBOX --> ACCESS
ACCESS[/"<b>Unrestricted reflection</b><br/>#context.setMemberAccess(DEFAULT_MEMBER_ACCESS)"/]
ACCESS --> RCE
RCE[/"<b>RCE</b><br/>Runtime.getRuntime().exec(cmd)"/]
RCE --> Done([Command executed as Tomcat process user])
style Start fill:#d32f2f,color:#fff
style Done fill:#d32f2f,color:#fff
style OUT_NORM fill:#9e9e9e,color:#fff
style OUT_OK fill:#9e9e9e,color:#fff
style OUT_SAFE fill:#9e9e9e,color:#fff
style OUT_PLAIN fill:#9e9e9e,color:#fff
style SANDBOX fill:#b71c1c,color:#fff
style ACCESS fill:#b71c1c,color:#fff
style RCE fill:#b71c1c,color:#fff
style CATCH fill:#e65100,color:#fff
style TRANSLATE fill:#e65100,color:#fff
분기 설명이 포함된 전체 상태 머신은 diagrams/cve-2017-5638-state-machine.md를 참조하세요.
시퀀스 다이어그램 보기 및 주석이 달린 OGNL 페이로드 분석은 diagrams/cve-2017-5638-attack-chain.md를 참조하세요.
이 저장소는 학술적 보안 연구 목적으로 Apache Struts 2.3.28 소스 코드의 일부를 재현합니다.
Apache Struts는 Copyright © 2000–2016 The Apache Software Foundation입니다.
Apache License, Version 2.0에 따라 라이선스가 부여됩니다.
라이선스 사본은struts-src-code/licenses/LICENSE.txt에서 확인할 수 있습니다.
Apache License에서 요구하는 전체 저작권 표시는struts-src-code/licenses/NOTICE.txt에 있습니다.
Apache Struts 2는 각각 자체 라이선스가 적용되는 추가 타사 구성 요소를 번들로 포함합니다:
| 구성 요소 | 라이선스 파일 |
|---|---|
| OGNL (Object-Graph Navigation Library) |
struts-src-code/licenses/OGNL-LICENSE.txt |
| XWork | struts-src-code/licenses/XWORK-LICENSE.txt |
| FreeMarker | struts-src-code/licenses/FREEMARKER-LICENSE.txt |