java跨站点脚本编制_跨站点请求伪造 跨站点脚本编制 通过框架钓鱼漏洞 | 学步园...

1、跨站点请求伪造 跨站点脚本编制 通过框架钓鱼漏洞

主要是通过在url或参数中添加脚本如:

1、URL中添加

2、参数value=

添加一个过滤器对特殊字符进行拦截

package com.xxx.sys.filter;

import java.io.IOException;

import java.util.Enumeration;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

/**

* 非法字符过滤器

* 1.所有非法字符配置在web.xml中,如需添加新字符,请自行配置

* 2.请注意请求与相应时的编码格式设置,否则遇到中文时,会出现乱码(GBK与其子集应该没问题)

* @author lee

*

*/

public class CharFilter implements Filter {

private Logger log = Logger.getLogger(CharFilter.class);

private String encoding;

private String[] legalNames;

private String[] illegalChars;

public void init(FilterConfig filterConfig) throws ServletException {

encoding = filterConfig.getInitParameter("encoding");

legalNames = filterConfig.getInitParameter("legalNames").split(",");

illegalChars = filterConfig.getInitParameter("illegalChars").split(",");

}

public void destroy() {

encoding = null;

legalNames = null;

illegalChars = null;

}

public void doFilter(ServletRequest request, ServletResponse response,

FilterChain filterChain) throws IOException, ServletException {

HttpServletRequest req = (HttpServletRequest)request;

HttpServletResponse res = (HttpServletResponse) response;

//必须手动指定编码格式

req.setCharacterEncoding(encoding);

String tempURL = req.getRequestURI();

log.info(tempURL);

Enumeration params = req.getParameterNames();

//是否执行过滤 true:执行过滤 false:不执行过滤

boolean executable = true;

//非法状态 true:非法 false;不非法

boolean illegalStatus = false;

String illegalChar = "";

//对参数名与参数进行判断

w:while(params.hasMoreElements()){

String paramName = (String) params.nextElement();

executable = true;

//密码不过滤

if(paramName.toLowerCase().contains("password")){

executable = false;

}else{

//检查提交参数的名字,是否合法,即不过滤其提交的值

f:for(int i=0;i

if(legalNames[i].equals(paramName)){

executable = false;

break f;

}

}

}

if(executable){

String[] paramValues = req.getParameterValues(paramName);

f1:for(int i=0;i

String paramValue = paramValues[i];

f2:for(int j=0;j

illegalChar = illegalChars[j];

if(paramValue.indexOf(illegalChar) != -1){

illegalStatus = true;//非法状态

break f2;

}

}

if(illegalStatus){

break f1;

}

}

}

if(illegalStatus){

break w;

}

}

//对URL进行判断

for(int j=0;j

illegalChar = illegalChars[j];

if(tempURL.indexOf(illegalChar) != -1){

illegalStatus = true;//非法状态

break;

}

}

if(illegalStatus){

//必须手动指定编码格式

res.setContentType("text/html;charset="+encoding);

res.setCharacterEncoding(encoding);

res.getWriter().print("");

}else{

filterChain.doFilter(request, response);

}

}

}

web.xml code

charFilter

com.xxx.sys.filter.CharFilter

encoding

UTF-8

legalNames

content1,ver,historyURL,listURL

illegalChars

|,$,@,',",\',\",,(,),+,CR,LF,\",",\,http

文章如果对你有帮助,

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值