当前位置:网站首页>web安全与防御
web安全与防御
2022-07-02 06:34:00 【niceyz】
一、钓鱼网站之XSS攻击原理分析
将表单提交的脚本:<script>for(var i=0;i<3;i++){alert("弹死你"+i);}</script> 中的特殊字符进行转义,禁止脚本执行。
pom.xml引入common-lang包
<dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency>
/** * xss过滤器 * Created by yz on 2018/4/9. */ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { private HttpServletRequest request; public XssHttpServletRequestWrapper(HttpServletRequest request) { super(request); this.request = request; } /** * 将request中的value值重写一下,将一些脚本参数 非法参数转换成html元素执行 * @param name * @return */ @Override public String getParameter(String name) { String value = this.request.getParameter(name); if(!StringUtils.isEmpty(value)){ System.out.println("转换前 value:"+value); value = StringEscapeUtils.escapeHtml(value); System.out.println("转换后 value:"+value); } return value; } }
import org.springframework.stereotype.Component; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import java.io.IOException; /** * Created by yz on 2018/4/9. */ @Component public class XssFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { System.out.println("初始化方法..."); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { System.out.println("正常拦截请求..."); HttpServletRequest req = (HttpServletRequest) request; XssHttpServletRequestWrapper xssWrapper = new XssHttpServletRequestWrapper(req); filterChain.doFilter(xssWrapper,response); } /** * 只执行一次 */ @Override public void destroy() { System.out.println("销毁请求..."); } }
/** * Created by yz on 2018/4/9. */ @Controller public class IndexController { @RequestMapping("/index") public ModelAndView index(HttpServletRequest request){ String name = request.getParameter("name"); System.out.println(name); ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("name",name); modelAndView.setViewName("index"); return modelAndView; } }
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Created by yz on 2018/4/9. */ @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class); } }
index.jsp
<%@ page contentType="text/html; charset=UTF-8" language="java"%> <html> <body> <h2>Hello World!</h2> <form name="form" method="post" action="<%=request.getContextPath() %>/index"> <input type="text" name="name"> <input type="submit" name="submit" value="提交"> </form> name:${ name} <h3>我是A页面</h3> <img alt="" src="/log.png"> </body> </html>
二、web安全之图片防盗链
三、表单操作数据库SQL注入
边栏推荐
- 微服务实战|微服务网关Zuul入门与实战
- 「面试高频题」难度大 1.5/5,经典「前缀和 + 二分」运用题
- Hystrix implements request consolidation
- 概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
- 分布式锁的这三种实现方式,如何在效率和正确性之间选择?
- Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
- Attributes of classfile
- Learn combinelatest through a practical example
- Cartoon rendering - average normal stroke
- [go practical basis] how can gin get the request parameters of get and post
猜你喜欢
别找了,Chrome浏览器必装插件都在这了
【Go实战基础】gin 如何自定义和使用一个中间件
知识点很细(代码有注释)数构(C语言)——第三章、栈和队列
Flink-使用流批一体API统计单词数量
Mysql 多列IN操作
I've taken it. MySQL table 500W rows, but someone doesn't partition it?
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
Statistical learning methods - Chapter 5, decision tree model and learning (Part 1)
Chrome video download Plug-in – video downloader for Chrome
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
随机推荐
Chrome browser tag management plug-in – onetab
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
VIM操作命令大全
Redis zadd导致的一次线上问题排查和处理
Redis installation and deployment (windows/linux)
Bold prediction: it will become the core player of 5g
cmd窗口中中文呈现乱码解决方法
CSDN Q & A_ Evaluation
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
Discussion on improving development quality and reducing test bug rate
以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
「面试高频题」难度大 1.5/5,经典「前缀和 + 二分」运用题
Matplotlib剑客行——没有工具用代码也能画图的造型师
深入剖析JVM是如何执行Hello World的
Chrome user script manager tempermonkey monkey
概率还不会的快看过来《统计学习方法》——第四章、朴素贝叶斯法
There is a problem with MySQL installation (the service already exists)
Don't look for it. All the necessary plug-ins for Chrome browser are here
一篇详解带你再次重现《统计学习方法》——第二章、感知机模型