Reputation: 879
How do I mitigate the Struts 2 malicious Content-Type
attack without updating my Java code?
Attack details S2-045.
Upvotes: 2
Views: 1270
Reputation: 10349
You can add this one to your httpd.conf or inside your virtualhost, after you've enabled mod_rewrite:
# MITIGATE CVE-2017-5638
RewriteCond %{HTTP:Content-type} [$\#()%}{'"] [OR]
RewriteCond %{HTTP:Content-Disposition} [$\#()%}{'"] [OR]
RewriteCond %{HTTP:Content-Length} [$\#()%}{'"]
RewriteRule . "-" [F,L]
Upvotes: 0
Reputation: 36
I would add the '%', '}', and '{' characters to the condition as well as they are also not valid Content-type header entries and are present in the POC exploit payload for this vulnerability.
RewriteCond %{HTTP:Content-type} [$\#()%}{]
RewriteRule . [F,L]
Sorry if I got the syntax wrong as I have not tested this entry yet.
P.S. I would even venture to add the '@', '?' and ';' characters, but those may break an application if filtered as I think they are actually technically allowed, but I have never seen those in a content-type header in any of our application implementations.
Upvotes: 2
Reputation: 879
Apache's mod_rewrite can filter out the bad content type.
More advanced checks can be made - but this checks for characters we don't expect to see in the incoming content-type header:
RewriteCond %{HTTP:Content-type} [$\#()]
RewriteRule . [F,L]
Upvotes: 0