i春秋——“百度杯”CTF比赛 十月场——Login

根据页面源码提示的 test1 test1 登录

 

刷新此页面并抓包,有个show=0值得关注

 

在发送的包的header中加一句show:1,即可得到member.php的源码

 

 1 <?php
 2     include 'common.php';
 3     $requset = array_merge($_GET, $_POST, $_SESSION, $_COOKIE);
 4     class db
 5     {
 6         public $where;
 7         function __wakeup()
 8         {
 9             if(!empty($this->where))
10             {
11                 $this->select($this->where);
12             }
13         }
14 
15         function select($where)
16         {
17             $sql = mysql_query('select * from user where '.$where);
18             return @mysql_fetch_array($sql);
19         }
20     }
21 
22     if(isset($requset['token']))
23     {
24         $login = unserialize(gzuncompress(base64_decode($requset['token'])));
25         $db = new db();
26         $row = $db->select('user=\''.mysql_real_escape_string($login['user']).'\'');
27         if($login['user'] === 'ichunqiu')
28         {
29             echo $flag;
30         }else if($row['pass'] !== $login['pass']){
31             echo 'unserialize injection!!';
32         }else{
33             echo "(╯‵□′)╯︵┴─┴ ";
34         }
35     }else{
36         header('Location: index.php?error=1');
37     }
38 
39 ?>

 

array array_merge ( array $array1 [, array $... ] ) //将一个或多个数组的单元合并起来,一个数组中的值附加在前一个数组的后面。返回作为结果的数组。
string gzuncompress ( string $data [, int $length = 0 ] ) //此函数解压缩字符串。与
gzcompress()对应
mysql_real_escape_string() //函数转义 SQL 语句中使用的字符串中的特殊字符:
\x00 \n \r \ ' " \x1a

 特别注意array_merge() 如果输入的数组中有相同的字符串键名,则该键名后面的值将覆盖前一个值。然而,如果数组包含数字键名,后面的值将不会覆盖原来的值,而是附加到后面。

 

接着看题,根据源码,只要提交符合条件的token就可拿到flag,但我们并没有在post,get,cookie中提交token,然而服务器却返回"(╯‵□′)╯︵┴─┴",说明token是在SESSION中,那我们只要在cookie里覆盖token即可

 

于是构造

 

然后在cookie中提交

posted @ 2018-10-13 14:58  淚笑  阅读(587)  评论(0编辑  收藏  举报