当前位置:网站首页>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注入
边栏推荐
- Actual combat of microservices | discovery and invocation of original ecosystem implementation services
- [staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
- Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
- Avoid breaking changes caused by modifying constructor input parameters
- hystrix 实现请求合并
- oracle删除表空间及用户
- 告别996,IDEA中必装插件有哪些?
- 微服务实战|手把手教你开发负载均衡组件
- Safety production early warning system software - Download safety production app software
- [go practical basis] how to set the route in gin
猜你喜欢

Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method

Programmers with ten years of development experience tell you, what core competitiveness do you lack?

Matplotlib swordsman line - first acquaintance with Matplotlib

深入剖析JVM是如何执行Hello World的

Customize redis connection pool

微服务实战|Eureka注册中心及集群搭建

Matplotlib剑客行——容纳百川的艺术家教程

【Go实战基础】如何安装和使用 gin

概念到方法,绝了《统计学习方法》——第三章、k近邻法

Matplotlib剑客行——初相识Matplotlib
随机推荐
Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method
一篇详解带你再次重现《统计学习方法》——第二章、感知机模型
以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
Programmers with ten years of development experience tell you, what core competitiveness do you lack?
京东高级工程师开发十年,编写出:“亿级流量网站架构核心技术”
hystrix 实现请求合并
Win10 uses docker to pull the redis image and reports an error read only file system: unknown
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
Insight into cloud native | microservices and microservice architecture
微服务实战|声明式服务调用OpenFeign实践
Typeerror: X () got multiple values for argument 'y‘
Pyspark de duplication dropduplicates, distinct; withColumn、lit、col; unionByName、groupBy
Matplotlib剑客行——布局指南与多图实现(更新)
Knife4j 2. Solution to the problem of file control without selection when uploading x version files
【Go实战基础】gin 如何验证请求参数
MySql报错:unblock with mysqladmin flush-hosts
Chrome browser tag management plug-in – onetab