高位漏洞修改
parent
0cc0f6d9c1
commit
4b33b0695f
@ -1,101 +1,118 @@
|
|||||||
package com.fuint.common.filter;
|
//package com.fuint.common.filter;
|
||||||
|
//
|
||||||
|
//
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
//import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
//import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
//import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fuint.framework.exception.BusinessRuntimeException;
|
//import com.fuint.framework.exception.BusinessRuntimeException;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
//import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
|
//import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
//import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import javax.servlet.*;
|
//import org.springframework.stereotype.Component;
|
||||||
import javax.servlet.annotation.WebFilter;
|
//import org.springframework.web.multipart.support.StandardServletMultipartResolver;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
//import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
//
|
||||||
import java.io.BufferedReader;
|
//import javax.servlet.*;
|
||||||
import java.io.IOException;
|
//import javax.servlet.annotation.WebFilter;
|
||||||
import java.util.Map;
|
//import javax.servlet.http.HttpServletRequest;
|
||||||
import java.util.Set;
|
//import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.TreeMap;
|
//import java.io.BufferedReader;
|
||||||
import java.util.stream.Collectors;
|
//import java.io.IOException;
|
||||||
|
//import java.util.Map;
|
||||||
|
//import java.util.Set;
|
||||||
@WebFilter(filterName = "CharsetFilter",urlPatterns = "/*")
|
//import java.util.TreeMap;
|
||||||
public class SpecialCharFilter implements Filter {
|
//import java.util.stream.Collectors;
|
||||||
|
//
|
||||||
private static final String SQL_REGX = "[\\\\^$*+?{}()=&;%+\\[\\].|]";
|
//
|
||||||
|
//@WebFilter(filterName = "CharsetFilter", urlPatterns = "/*")
|
||||||
@Override
|
//@Component
|
||||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException, IOException {
|
//public class SpecialCharFilter implements Filter {
|
||||||
HttpServletRequest req = (HttpServletRequest) servletRequest;
|
//
|
||||||
|
// private static final String SQL_REGX = "[=]";
|
||||||
// 防止流读取一次后就没有了, 所以需要将流继续写出去
|
// @Qualifier("handlerExceptionResolver")
|
||||||
MyRequestWrapper requestWrapper = new MyRequestWrapper(req);
|
// @Autowired
|
||||||
|
// private HandlerExceptionResolver resolver;
|
||||||
// 获取请求参数
|
//
|
||||||
Map<String, Object> paramsMaps = new TreeMap<>();
|
// @Override
|
||||||
if ("POST".equals(req.getMethod().toUpperCase())) {
|
// public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException, IOException {
|
||||||
String body = requestWrapper.getBody();
|
// HttpServletRequest req = (HttpServletRequest) servletRequest;
|
||||||
paramsMaps = JSONObject.parseObject(body, TreeMap.class);
|
// String servletPath = req.getServletPath();
|
||||||
} else {
|
// HttpServletResponse rep = (HttpServletResponse) servletResponse;
|
||||||
Map<String, String[]> parameterMap = requestWrapper.getParameterMap();
|
// MyRequestWrapper requestWrapper = new MyRequestWrapper(req);
|
||||||
Set<Map.Entry<String, String[]>> entries = parameterMap.entrySet();
|
// if (ObjectUtil.notEqual(servletPath,"/backendApi/login/doLogin")){
|
||||||
for (Map.Entry<String, String[]> next : entries) {
|
// // 防止流读取一次后就没有了, 所以需要将流继续写出去
|
||||||
paramsMaps.put(next.getKey(), next.getValue()[0]);
|
//
|
||||||
}
|
// // 获取请求参数
|
||||||
}
|
// Map<String, Object> paramsMaps = new TreeMap<>();
|
||||||
|
// if ("POST".equals(req.getMethod().toUpperCase())) {
|
||||||
// 校验SQL注入
|
// String body = requestWrapper.getBody();
|
||||||
if (ObjectUtil.isNotEmpty(paramsMaps)) {
|
// paramsMaps = JSONObject.parseObject(body, TreeMap.class);
|
||||||
for (Object o : paramsMaps.entrySet()) {
|
// } else {
|
||||||
Map.Entry entry = (Map.Entry) o;
|
// Map<String, String[]> parameterMap = requestWrapper.getParameterMap();
|
||||||
Object value = entry.getValue();
|
// Set<Map.Entry<String, String[]>> entries = parameterMap.entrySet();
|
||||||
if (value != null) {
|
// for (Map.Entry<String, String[]> next : entries) {
|
||||||
boolean isValid = checkSqlInject(value.toString(), servletResponse);
|
// paramsMaps.put(next.getKey(), next.getValue()[0]);
|
||||||
if (!isValid) {
|
// }
|
||||||
return;
|
// }
|
||||||
}
|
//
|
||||||
}
|
// // 校验SQL注入
|
||||||
}
|
// if (ObjectUtil.isNotEmpty(paramsMaps)) {
|
||||||
}
|
// for (Object o : paramsMaps.entrySet()) {
|
||||||
|
// Map.Entry entry = (Map.Entry) o;
|
||||||
chain.doFilter(requestWrapper, servletResponse);
|
// Object value = entry.getValue();
|
||||||
|
// if (value != null) {
|
||||||
|
//
|
||||||
}
|
// boolean isValid = checkSqlInject(value.toString(), servletResponse);
|
||||||
|
// if (!isValid) {
|
||||||
//获取request请求body中参数
|
// resolver.resolveException(req, rep,
|
||||||
public static String getBodyString(BufferedReader br) {
|
// null, FileterException("客户端信息非法!!,存在特殊字符请重新输入"));
|
||||||
String inputLine;
|
// return;
|
||||||
String str = "";
|
// }
|
||||||
try {
|
// }
|
||||||
while ((inputLine = br.readLine()) != null) {
|
// }
|
||||||
str += inputLine;
|
// }
|
||||||
}
|
// }
|
||||||
br.close();
|
//
|
||||||
} catch (IOException e) {
|
// chain.doFilter(requestWrapper, servletResponse);
|
||||||
System.out.println("IOException: " + e);
|
//
|
||||||
}
|
//
|
||||||
return str;
|
// }
|
||||||
}
|
//
|
||||||
|
// //获取request请求body中参数
|
||||||
/**
|
// public static String getBodyString(BufferedReader br) {
|
||||||
* 检查SQL注入
|
// String inputLine;
|
||||||
*
|
// String str = "";
|
||||||
* @param value 参数值
|
// try {
|
||||||
* @param servletResponse 相应实例
|
// while ((inputLine = br.readLine()) != null) {
|
||||||
* @throws IOException IO异常
|
// str += inputLine;
|
||||||
*/
|
// }
|
||||||
private boolean checkSqlInject(String value, ServletResponse servletResponse) throws IOException {
|
// br.close();
|
||||||
if (null != value) {
|
// } catch (IOException e) {
|
||||||
String output = value.replaceAll(SQL_REGX, "");
|
// System.out.println("IOException: " + e);
|
||||||
if (output.length()<value.length()) {
|
// }
|
||||||
return false;
|
// return str;
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
return true;
|
// /**
|
||||||
}
|
// * 检查SQL注入
|
||||||
|
// *
|
||||||
|
// * @param value 参数值
|
||||||
|
// * @param servletResponse 相应实例
|
||||||
}
|
// * @throws IOException IO异常
|
||||||
|
// */
|
||||||
|
// private boolean checkSqlInject(String value, ServletResponse servletResponse) throws IOException {
|
||||||
|
// if (null != value) {
|
||||||
|
// String output = value.replaceAll(SQL_REGX, "");
|
||||||
|
// if (output.length() < value.length()) {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Exception FileterException(String cause) {
|
||||||
|
// return new Exception(cause);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.fuint.framework.exception;
|
||||||
|
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
|
public class FileterException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
public FileterException(String cause) {
|
||||||
|
super(cause);
|
||||||
|
this.reason = cause;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue