
Utilizzo di Struts2 e PowerShell per ricreare la vulnerabilità OGNL Injection CVE-2017-5638.
Questo repository fa parte del progetto del corso SC3010 Computer Security.
Ricrea CVE-2017-5638, una vulnerabilità critica di Remote Code Execution in Apache Struts 2 (versioni 2.3.5–2.3.31 e 2.5–2.5.10), tristemente sfruttata nella violazione dei dati Equifax del 2017 per esfiltrare dati personali di circa 147 milioni di persone.
La vulnerabilità nasce da un singolo difetto di progettazione: quando Apache Struts non riesce a analizzare una richiesta di upload multipart/form-data, costruisce un messaggio di errore incorporando l'intestazione Content-Type grezza — senza sanificarla — in una stringa che viene poi passata attraverso il valutatore di espressioni OGNL. Un attaccante che inserisce un'espressione OGNL nell'intestazione Content-Type riesce quindi a farla eseguire lato server come utente del processo Tomcat.
Questo repository contiene:
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
Il diagramma seguente mostra ogni ramo decisionale nella pipeline di richiesta di Struts2. Il percorso rosso è quello che l'attaccante forza; i rami grigi → ... sono percorsi sicuri che non si applicano durante l'exploit.
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:#fffPer la macchina a stati completa con spiegazioni dei rami, vedi diagrams/cve-2017-5638-state-machine.md.
Per una vista del diagramma di sequenza e l'analisi annotata del payload OGNL, vedi diagrams/cve-2017-5638-attack-chain.md.
Questo repository riproduce porzioni del codice sorgente di Apache Struts 2.3.28 per scopi di ricerca accademica sulla sicurezza.
Apache Struts è Copyright © 2000–2016 The Apache Software Foundation.
Concesso in licenza secondo la Apache License, Version 2.0.
Una copia della licenza è disponibile all'indirizzostruts-src-code/licenses/LICENSE.txt.
L'avviso di attribuzione completo richiesto dalla Apache License si trova instruts-src-code/licenses/NOTICE.txt.
Apache Struts 2 include componenti aggiuntivi di terze parti, ciascuno governato dalla propria licenza:
| Component | License file |
|---|---|
| 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 |