Sqli-labs是一个练习SQL注入
的很好的一个平台,可以直接下载后使用。注意由于充满漏洞,推荐在虚拟机中使用,并使用host-only
模式,不要让其联网。
平台搭建
我这里是采用了虚拟机
+win10
+phpStudy
,然后直接将下载的sqli-labs-master
放到www
文件夹中即可。
Basic Challenges
每个less
都有提示会告诉你是什么类型的题,我们也能看到后台源码,所以比较好去理解。
less-1
简单的'
绕过
|
|
发现正常运行,即注入成功。
之后是比较基础的脱裤步骤,具体操作可以看我的另一篇文章SQL注入总结总结了基本步骤。本例练习一下脱裤,之后如果不是有一些特殊方式,就不再贴出来了。
获取字段数
|
|
发现到4之后会报错,即字段数为3
获得显示位
|
|
可以看到显示位为2,3
,则其他信息可以通过在2,3
位显示而被我们得到。
得到当前数据库、版本等信息
|
|
查选库,获取所有数据库名
|
|
得到所有数据库:information_schema,challenges,mysql,performance_schema,security
获取某个数据库的表名
|
|
其中0x7365637572697479
为security
的hex()
值
获取列名
|
|
可以看到获得了id,username,password
这三个字段
获取内容
|
|
less-2
|
|
试探之后发现成功执行or 1=1
所以显示的结果是id=1
的内容,因为第二次试探发现有limit 0,1
所以成功绕过。
less-3
|
|
根据报错,发现有个括号,直接闭合
less-4
|
|
发现返回的信息是:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"2"") LIMIT 0,1' at line 1
可以得出它是将我们的内容("id")
这样了,所以需要闭合两个,payload如下:
|
|
less-5
|
|
绕过成功,发现虽然没有显示位,但是有返回报错信息的。这里提供两种方式,一种是使用报错注入
,另一种根据页面不同变化进行字符猜解
。
报错注入:
这样直接就有错误信息了
字符猜解:
|
|
这里写了一个脚本,使用线程池发送请求,获取所有数据库、表、列名内容(去除了默认数据库的内容)。使用二分搜索进行字符猜解,范围是0-255
,可根据实际情况修改,payload也可根据不同环境进行修改。
less-6
同less-5 只不过改为双引号"
即可。以下内容用于判断我们双引号注入成功了。
|
|
less-7
这道题要求使用outfile
,具体基础知识可以看sql-injection总结/outfile里面关于outfile load_file
部分内容。