zoukankan      html  css  js  c++  java
  • modsecookie

    Cookie parsing added添加cookie解析

    现在你可以使用新的可选的过滤器变量(COOKIE_name, COOKIE_NAMES, COOKIE_VALUES)分析cookies。虽然之前你就可以查看cookie(cookie就是HTTP头),但是功能有限。现在ModSecurity可以分析cookie。

    假设你想通过PHP会话cookie阻止XSS攻击,这个过滤器会确保cookie正常:

    SecFilterSelective COOKIE_PHPSESSID "^[0-9a-z]+$"

    COOKIE_NAMES和COOKIE_VALUES将会分别检测所有的cookie名字和值。

     

    ModSecurity Cookie and Link Protection Patch  

    ModSecurity Cookie以及链路保护补丁18 August 2006

    六月份,关于mod-security-users邮件列表,发生了一件重大事件:Daniel Fernndez Bleda and Carles Bonamusa Prez从Internet Security Auditors贡献了大量代码。针对ModSecurity 1.9.4的这个补丁,使用hash加密实现cookie以及链路的保护。现在可以从download from the ModSecurity web site获取这个补丁。请注意代码现在还没有上市,只能用于测试。我期待这段代码能尽快融入到官方代码库(为2.0.0之后的稳定版本发布做好准备)

     

    Helping Protect Cookies with HTTPOnly Flag使用HTTPOnly标志保护Cookies安全

    如果你不熟悉HTTPOnly cookie标志或者不明白网络应用为什么要使用它,请参考以下资源:

    本质内容是:虽然cookie选项标志对防止XSS攻击没有任何帮助,但是他能阻止#1 XSS攻击,即能防止盗取SessionIDs。虽然HTTPOnly并不是一个很厉害的新技术,但是它的潜力很大。注意必须同时满足两个条件,才能实现它的潜力:

    • Web应用 –能为所有的Set-Cookie响应头的SessionIDs附上“HTTPOnly”标志
    • Web浏览器 – 对cookie数据确定并执行安全约束,这样javascript就不能访问它的内容。

    目前使用HTTPOnly标志进行安全防护还存在挑战,因为HTTPOnly还没有在web应用和web浏览器上得到广泛的应用。例如:受你的web应用平台的限制,你可能需要一个复杂的机制来实现这个特性。例如:

    - 在Java,你可以参考OWASP网站提供的例子: http://www.owasp.org/index.php/HTTPOnly#Using_Java_to_Set_HTTPOnly, 虽然对平台添加的JSESSIONID来说,效果不是很好。Jim Manico努力尝试并让 Apache Tomcat开发者在HTTPOnly支持上执行他提供的补丁- http://manicode.blogspot.com/2008/08/httponly-in-tomcat-almost.html. 关键是不同的web应用开发平台太多了,在每一个需要保护的web应用里面寻找支持不是一件容易的事情。

    对浏览器来说-间断性的使用HTTPOnly。这就是为什么OWAS内在安全组开始建立一个HTTPOnly的RFC规格说明书- http://groups.google.com/group/ietf-httponly-wg. 希望这个组能够带动各种浏览器开发人员。

    那么,看到这儿你可能会问,- Ryan,这是一则有趣的消息,但是为什么要发表在 ModSecurity站点上呢?针对这一主题,web应用防火墙能做什么呢?我会说 – 好问题,非常高兴你会问这个问题。

    在web应用安全空间里面我的一个pet peevs是和WAF结合在一起的stigma。大部分时候,每个人只关注典型WAF部署条件下的消极的安全防护和攻击阻断方面,而没有意识到WAFs时为HTTP设计的高度专业化的工具。根据你的情况,你可能并不想进行攻击阻断。还有许多其他的用处-作为一个战略性反应工具,它可以处理潜在的弱点。当后端/受保护的web应用服务器向外分发缺少HTTPOnly标志的 SessionIDs时候,可以实现监听。这样可以提高警觉,通知合适的人去检查一下编辑网络语言编码是否可能把这一特性加进来。ModSecurity使用以下规则来做这件事情-

    # Identifies SessiondIDs without HTTPOnly flag
    #
    SecRule RESPONSE_HEADERS:/Set-Cookie2?/ "!(?i:;? ?httponly;?)" "chain,phase:3,t:none,pass,log,auditlog,msg:'AppDefect: Missing HttpOnly Cookie Flag.'"
      SecRule MATCHED_VAR "(?i:(j?sessionid|(php)?sessid|(asp|jserv|jw)?session[-_]?(id)?|cf(id|token)|sid))" "t:none"

    尽管这条规则对问题的识别以及报警非常有用,很多组织更愿意采取下一步尝试解决这个问题。如果web应用不能把HTTPOnly cookie标志选项进行内部添加,实际上你可以采取modsecurity+Apache实现这一个目的。ModSecurity能够设置Apache读取/使用的环境数据。在这种情况下,我们可以稍微调整一下之前的规则,使用“setenv”动作之后,再添加一个额外的Apache“header”命令,“header”命令会使用新的包含HTTPOnly标志的Set-Cookie数据来重写数据-

    # Identifies SessiondIDs without HTTPOnly flag and sets the "http_cookie" ENV
    # Token for Apache to read
    SecRule RESPONSE_HEADERS:/Set-Cookie2?/ "!(?i:;? ?httponly;?)" "chain,phase:3,t:none,pass,nolog"
      SecRule MATCHED_VAR "(?i:(j?sessionid|(php)?sessid|(asp|jserv|jw)?session[-_]?(id)?|cf(id|token)|sid))" "t:none,setenv:http_cookie=%{matched_var}"

    # Now we use the Apache Header directive to set the new data

    Header set Set-Cookie "%{http_cookie}e; HTTPOnly" env=http_cookie

    这条规则集的结果就是:ModSecurity+Apache在定义的set-cookie数据上面增加HTTPOnly标志。谢谢你从Breach来到Brian Rectanus并与我合作使Header指令语法正确。

    有一点要提醒-你必须理解web应用是怎么设置SessionIDs,也就是说创建了服务器

    - make sure that you understand how the web application is handling setting SessionIDs meaning if they are created server-side vs. client-side (in javascript).  This rule set will work fine if the SessionIDs are generated server-side.  If they are created client-side, however, this will disrupt session management.

     

    Fixing Both Missing HTTPOnly and Secure Cookie Flags

    Cookie既缺少HTTPOnly标志也缺少Secure标志时的修复

    In a previous post I showed how you can use both ModSecurity and Apache together to identify/modify SessionIDs that are missing the HTTPOnly flag.  I received some feedback where people were asking how to accomplish the same thing but for the "Secure" cookie flag which instructs the browser to *only* send the SessionID back over an SSL connection. 

    我在以前的帖子中说过,怎么把modsecurity和Apache结合使用来识别/修改那些没有HTTPOnly标志的SessionIDs。我收到很多的人的回复,都问及,如果是”Secure”cookie标志的话,怎么完成同样的事情,即怎么把modsecurity和Apache结合使用来识别/修改那些没有”Secure”cookie标志的SessionIDs。并命令浏览器通过SSL通信“只”发送SessionID。

     

     

     

    #

    # First we want to capture Set-Cookie SessionID data for later inspection

    SecRule RESPONSE_HEADERS:/Set-Cookie2?/ "(?i:(j?sessionid|(php)?sessid|(asp|jserv|jw)?session[-_]?(id)?|cf(id|token)|sid))" "phase:3,t:none,pass,nolog,setvar:tx.sessionid=%{matched_var}"

     

    #

    # We now check the saved SessionID data for the HTTPOnly flag and set an Apache

    # ENV variable if it is missing.

    SecRule TX:SESSIONID "!(?i:;? ?httponly;?)" "phase:3,t:none,setenv:httponly_cookie=%{matched_var},pass,log,auditlog,msg:'AppDefect: Missing HttpOnly Cookie Flag.'"

     

    #

    # Next we check the saved SessionID data for the Secure flag (if this is an SSL session)

    # and set an Apache ENV variable if it is missing.

    SecRule SERVER_PORT "@streq 443" "chain,phase:3,t:none,pass,log,auditlog,msg:'AppDefect: Missing Secure Cookie Flag.'"

     SecRule TX:SESSIONID "!(?i:;? ?secure;?)" "t:none,setenv:secure_cookie=%{matched_var}"

     

    #

    # The final check is to see if BOTH of the HTTPOnly and Secure cookie flags are missing

    # and set an Apache ENV variable if they are missing.

    SecRule TX:SESSIONID "!(?i:;? ?httponly;?)" "chain,phase:3,t:none,pass,log,auditlog,msg:'AppDefect: Missing HttpOnly and Secure Cookie Flag.'"

     SecRule SERVER_PORT "@streq 443" "chain,t:none"

      SecRule TX:SESSIONID "!(?i:;? ?secure;?)" "t:none,setenv:secure_httponly_cookie=%{matched_var}"

     

    #

    # This last section executes the Apache Header command to

    # add the appropriate Cookie flags 

    Header set Set-Cookie "%{httponly_cookie}e; HTTPOnly" env=httponly_cookie

    Header set Set-Cookie "%{secure_cookie}e; Secure" env=secure_cookie

    Header set Set-Cookie "%{secure_httponly_cookie}e; Secure; HTTPOnly" env=secure_httponly_cookie

    如果有一天我们淹没在茫茫人海中,庸碌一生,那一定是我们没有努力活得丰盛
  • 相关阅读:
    通过修改manifest文件来解决Vista/Win7/Win8/win10下应用程序兼容性问题
    windows下django开发环境配置
    Django网站实例效果
    手动下载Linux安装包perf
    【Nginx】负载配置
    【VIM】常用命令
    【CentOS7】SCP服务器间传文件
    【CentOS7】目录统计du命令
    【CentOS7】安装GraphicsMagick
    【Nginx】限流配置
  • 原文地址:https://www.cnblogs.com/xiachj/p/4112197.html
Copyright © 2011-2022 走看看