Web系统安全问题整理(暴露版本号/重放)

一、系统暴露Tomcat、Nginx版本号

解决办法:

  1. 进入tomcat的lib目录找到catalina.jar
  2. 进入catalina.jar的org/apache/catalina/util 编辑配置文件ServerInfo.properties
  3. 修改ServerInfo.properties中的参数为
 server.info=Apache Tomcat   
  server.number=0.0.0.0 
  server.built=Nov 7 2016 20:05:27 UTC
  1. 修改nginx.conf配置文件
http {    
	server_tokens off;   #默认是注释掉的
 }

二、防重放

理解:重放漏洞是指不法分子抓取你的增加/修改报文,不断重新请求对应的URL造成数据重复添加操作。
思路:增加一个拦截器,拦截全部增加、修改操作,在方法请求处理之前增加一个唯一标识(UUID等)保存至缓存与request header中,在拦截器中获取两个值进行比较,相同则安全。
代码如下:
封装ajax

function ajax(obj) {
    obj = $.extend({
        contentType: "application/x-www-form-urlencoded; charset=UTF-8"
    }, obj);
    var successFun = obj.success;
    var result;
    var recevieMsgFun = obj.recevieMsg;
    obj.success = function (data, textstatus, request) {
        var tempToken = request.getResponseHeader('token');
        if (tempToken != null && tempToken != '' && tempToken != undefined) {
            window.tokenValue = tempToken;
        }
        if (typeof successFun === "function") {
            successFun(data);
        } else {
            result = data;
        }
        if(typeof recevieMsgFun!="function") {
            alert(data);
        }
        else {
            if(message && message.messageList && message.messageList.length > 0)
            {
                recevieMsgFun(message.messageList);
            }
        }
    }
    var errorFun = obj.error;
    obj.error = function (data) {
        if (typeof errorFun === "function") {
            errorFun(data);
        }
        if (data.responseText && data.responseText.indexOf("{") === 0) {
            if (typeof recevieMsgFun != "function") {
                eval("data=" + data.responseText);
                alert(data);
            }
        }
        var tempToken = data.getResponseHeader("token");
        if (tempToken != null && tempToken != '' && tempToken != undefined) {
            window.tokenValue = tempToken;
        }

    }

    obj.beforeSend = function (request) {
        request.setRequestHeader("token", window.tokenValue);
    }

    $.ajax(obj);
    return result;
}

自定义防重放拦截器 spring配置文件

<mvc:interceptor>
   <mvc:mapping path="/**"/>
   <bean class="****.RefererInterceptor">
   <property name="includeUrls">
   <list> 
   </list>
   </property>
   </bean>
</mvc:interceptor>

RefererInterceptor.java

public class RefererInterceptor implements HandlerInterceptor {
   private Log logger = LogFactory.getLog(this.getClass());
   private final static String TOKEN_NAMESPACE = "TOKEN_NAMESPACE";
 
   private List<String> includeUrls;

   @Override
   public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
         throws Exception {}

   @Override
   public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
         throws Exception {}

   @Override
   public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception {
      /**
       * 新增、删除、修改操作时进行token验证
       */
      if(isIncludeUrl(request)){     
         String token = UUID.randomUUID().toString();
         request.getSession(false).setAttribute("token", token);
         String sessionId = request.getSession().getId();
         CacheService cacheService = CacheServiceFactory.getInstance();     
         String serverToken = cacheService.getVal(TOKEN_NAMESPACE, sessionId);
         cacheService.putVal(TOKEN_NAMESPACE, sessionId, token);
         response.addHeader("token", token);
         request.setAttribute("token", token);
         String headerToken = request.getHeader("token");

         if (EmptyUtils.isEmpty(headerToken)) {
            headerToken = request.getParameter("token");
         }
         
         if (EmptyUtils.isEmpty(headerToken)  || serverToken == null || !serverToken.equals(headerToken)) {
            
            logger.error(request.getRequestURI() + "请求的token已失效"  + "  serverToken = "  +serverToken   + "  headerToken = "  + headerToken);
            return false;
         }
      }
      return true;
   }

   private boolean isIncludeUrl(HttpServletRequest request) {
      if (!EmptyUtils.isAnyoneEmpty(includeUrls)) {
         String requestPath = request.getRequestURI();
         for (String urlRegex : includeUrls) {
            Pattern p = Pattern.compile(urlRegex);
            if (p.matcher(requestPath).find()) {
               return true;
            }
         }
      }
      return false;
   }
   
   public List<String> getIncludeUrls() {
      return includeUrls;
   }
   public void setIncludeUrls(List<String> includeUrls) {
      this.includeUrls = includeUrls;
   }
}

后续更新XSS注入与越权等安全问题。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值