栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

使用http动词篡改的认证旁路

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用http动词篡改的认证旁路

文章目录
  • 一、漏洞描述
  • 二、解决建议
  • 三、解决方法
    • Springboot 配置文件增加配置
    • 编写配置类
    • 编写过滤器

提示:以下是本篇文章正文内容,下面案例可供参考

一、漏洞描述

可能会升级用户特权并通过 Web 应用程序获取管理许可权可能会收集有关 Web 应用程序的敏感信息,如用户名、密码、机器名和/或敏感文件位置。
测试结果似乎指示存在脆弱性,因为“测试响应”与“原始响应”完全相同,这表明动词篡改能够绕过站点认证。

二、解决建议

增加拦截器,判断请求方式是否合法,合法则放行。

三、解决方法 Springboot 配置文件增加配置
# 信息安全
security:
  #http请求方式配置
  http:
    #是否开启(开启:true 关闭:false)
    enable: false
    #允许的请求方式
    allow:
      - POST
      - GET
编写配置类
@Component
@Configuration
@ConfigurationProperties(prefix = "security")
public class SecurityConfig implements InitializingBean, DisposableBean {


    private static Logger logger = LoggerFactory.getLogger(AspctConfig.class);
    

    
    private HttpConfig http;

    
    private XssConfig xss;

    public HttpConfig getHttp() {
        return http;
    }

    public void setHttp(HttpConfig http) {
        this.http = http;
    }

    public XssConfig getXss() {
        return xss;
    }

    public void setXss(XssConfig xss) {
        this.xss = xss;
    }

    @Override
    public void destroy() throws Exception {

    }

    @Override
    public void afterPropertiesSet() throws Exception {

    }

    
    @Bean
    @ConditionalOnProperty(prefix = "security", name = "http.enable", havingValue = "true")
    public FilterRegistrationBean httpFilterRegistration() {
        logger.info("hhtp过滤器初始化");
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setName("httpFilter");
        registration.setOrder(3);
        registration.addUrlPatterns("
public class HttpConfig {

    
    private boolean enable;

    
    private List allow;


    public boolean isEnable() {
        return enable;
    }

    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    public List getAllow() {
        return allow;
    }

    public void setAllow(List allow) {
        this.allow = allow;
    }
}

编写过滤器
public class HttpFilter implements Filter {


    private static Logger LOGGER = LoggerFactory.getLogger(CsrfFilter.class);
    
    FilterConfig filterConfig = null;

    private SecurityConfig security;


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        security = SpringUtils.getBean(SecurityConfig.class);
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        String method = request.getMethod();
        if (isExcludeMethod(method)) {
            filterChain.doFilter(servletRequest, servletResponse);
            return;
        } else {
            servletResponse.setContentType("application/json; charset=UTF-8");
            servletResponse.getWriter().write(JacksonUtil.writeValueAsString(new ReturnT<>(ReturnT.FAIL_CODE, "不支持的请求方式!")));
            LOGGER.error("不支持的请求方式", method);
        }
    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }

    
    private boolean isExcludeMethod(String method) {
        if (security.getHttp().getAllow() == null || security.getHttp().getAllow().isEmpty()) {
            return false;
        }
        return security.getHttp().getAllow().stream().map(pattern -> Pattern.compile("^" + pattern)).map(p -> p.matcher(method))
                .anyMatch(Matcher::find);
    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/963237.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号