

Struts2漏洞笔记之S2-005 - osword's blog
source link: https://zhzhdoai.github.io/2020/12/24/Struts2%E6%BC%8F%E6%B4%9E%E7%AC%94%E8%AE%B0%E4%B9%8BS2-005/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
引用_memberAccess修改当前沙箱对静态方法调用限制
Struts 2.0.0 - Struts 2.1.8.1
xwork 2.0.4 与 xwork 2.0.6补丁对比
官方针对S2-003漏洞修补主要操刀xwork上,对比struts 2.0.11.2 与 struts2 2.0.12版本中的xowrk包.
ParametersInterceptor中对当前值栈重新初始化valueStack,向当前newStack中新增一个securityMemberAccess
对象而该对象中定义了字段allowStaticMethodAccess
、excludeProperties
、acceptProperties
作为新的沙箱进一步限制静态方法执行
在work 2.0.6版本中字段allowStaticMethodAccess
默认设置为true并不是影响方法执行关键字段。跟进java.Runtime.getRuntime执行逻辑中.会经过isMethodAccessible方法判断,在该if语句中需要使得判断为false 才能够执行invokeMethod方法.即isMethodAccessible返回true
继续跟进SecurityMemberAccess:;isAccessible方法,分析逻辑,这里需要使得isAcceptableProperty执行后返回true,跟进该方法后发现isAccepted方法返回true,只要使得isExcluded返回false即可。这里需要修改this.acceptProperties为空才满足条件,而该字段可以通过Ognl表达式引用外部对象修改.
了解外部引用对象逻辑需要跟进ASTVarRef::geValueBody=>OgnlContext::get
,通过#_memberAccess
就能够获取SecurityMemberAccess
对象,就能够进一步修改this.acceptProperties=false
最后payload如下,当前版本可以不用设置allowStaticMethodAccess为true,为了保证poc稳定性可以加上.
(%27\u0023context[\%27xwork.MethodAccessor.denyMethodExecution\%27]\u003dfalse%27)(bla)(bla)&(%27\u0023_memberAccess.excludeProperties\[email protected]@EMPTY_SET%27)(bla)(bla)&(%27\u0023myret\[email protected]@getRuntime().exec(\%27open\u0020/System/Applications/Calculator.app\%27)%27)(bla)(bla)
Struts2 2.2.1 版本中直接加强正则匹配,先知非法字符串.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK