5 ms·
Wow, article is from March 2017. Summary: Attacker sends a malformed Content-Type header on file upload, which throws an exception due to the Content-Type bein
by kbaker 9y ago
Wow, article is from March 2017.
Summary: Attacker sends a malformed Content-Type header on file upload, which throws an exception due to the Content-Type being unknown. But, in the exception text is the direct, unsanitized user input from the header.
There is not a specific text localization handler for struts.messages.upload.error.InvalidContentTypeException, so a generic exception handler ends up being used to process the exception. This generic handler turns out to parse the unsanitized user input as OGNL markup, running the attacker code when processing the exception text.
Some effort is made to blacklist loading other Java libraries in the text rendering context, however it was easily defeated by emptying the blacklist in the attacking code before calling the blacklisted modules.
- amigoingtodie 9y agoBeautiful summary. Thank you.
- samstave 9y agoAgreed - great write up, but can you expand on this a bit more please?
- deleted 9y ago[deleted]
- kbaker 9y agoAh, I probably should have used a TL;DR tag - my original comment is just a really condensed summary of the awesome but super detailed article, which even shows and explains the Struts code in question, example requests and responses, stack traces from the exception, and the exception logs. Even in the comments are some logs that look like evidence of an actual in-the-wild RCE attempt! So maybe check there for more explanation... all credit for the research and investigation goes to the article's author. It was really a good 'deep dive' into the internals of Struts to see how such a subtle bug could be turned into RCE.
- nerdponx 9y agoThis generic handler turns out to parse the unsanitized user input as OGNL markup The article is pretty dense and I don't understand this point. I can maybe understand why you'd want to parse the output of an exception message, but why would you ever want to be executing what you parse?
- greglindahl 9y agoI don't know either, so I googled [OGNL] and the instant answer snippet was > OGNL stands for Object-Graph Navigation Language; it is an expression language for getting and setting properties of Java objects, plus other extras such as list projection and selection and lambda expressions. You use the same expression for both getting and setting the value of a property. Which makes it pretty clear.
- nerdponx 9y agoI still don't get it. Why would you want to execute that kind of markup in an error handler?
- markbnj 9y agoRendering the exception message into an output template for display perhaps.
- ComodoHacker 9y agoTo substitute variables in a localized error message template.
- deskamess 9y agoDoes generating that substitute value imply launching a shell command?
- ComodoHacker 9y agoNo. But template expression language used in Struts is quite expressive. :) There's some defensive system to prevent access to arbitrary classes, but the attacker managed to overcome it in a clever way.
- MichaelGG 9y agoSo basically they called eval() on an error message, to put it bluntly? Nice reminder that no matter how safe the language, people will do nutty stuff with it.