def parse(template_file=None, payload_file=None, signature=None, output_file=None, *args, **kwargs): esprint('Checking input files') helpers.validate_input_files([template_file, payload_file]) esprint('Parsing the payload file') with open(payload_file) as infile: payload = infile.read() esprint('Opening and parsing the template file') inserted = False with open(template_file) as template: lines = [] for line in template: if signature == line.strip(): esprint('Inserting the payload.') line = payload inserted = True lines.append(line) if not inserted: esprint("""WARNING: Signature never detected! Payload was not inserted. Note that the signature must be on its own line with no other content.""") esprint('Writing the output file') with open(output_file, 'w') as outfile: for line in lines: outfile.write(line)
def parse(hash_files=None, cracked_delimiter=':', cracked_files=None, cracked_hashes=None, match_string=None, process_count=4, output_file=None, *args, **kwargs): if hash_files: helpers.validate_input_files(hash_files) if cracked_files: helpers.validate_input_files(cracked_files) if cracked_hashes: esprint(f'Loading cracked hashes: {",".join(cracked_hashes)}') cracked = [ parse_cracked(cracked_hash, cracked_delimiter) for cracked_hash in cracked_hashes ] elif cracked_files: esprint(f'Loading hashes from cracked files') for cracked_file in cracked_files: with open(cracked_file) as cfile: cracked = [ parse_cracked(c.strip(), cracked_delimiter) for c in cfile if c and c != '\n' ] elif match_string: esprint(f'Handling static string search') cracked = [CrackedHash(match_string, 'STATIC_STRING_SEARCH')] # TODO: Implement multiprocessing # Currently having an issue with pickling the find_match function #pool = Pool(process_count) #global results if output_file: output_file = open(output_file, 'w') try: for cracked_hash in cracked: for hash_file in hash_files: with open(hash_file) as hash_file: for line in hash_file: line = line.strip() if cracked_hash == line or cracked_hash.__eq__( line, True): s = cracked_hash.translate_match(line) print(s) if output_file: output_file.write(s + '\n') finally: if output_file: output_file.close()
elif arg.__class__ == MutuallyExclusiveArgumentGroup: group = sub.add_mutually_exclusive_group( *arg.pargs, **arg.kwargs) add_args(group, arg) else: sub.add_argument(*arg.pargs, **arg.kwargs) args = ap.parse_args() if args.module == 'module_table': print('|Module|Description|\n|--|--|') for handle, module in modules.handles.items(): h = ' '.join(module.help.strip().split('\n')) print(f'|{handle}|{h}|') exit() if 'input_file' in args: helpers.validate_input_file(args.input_file) elif 'input_files' in args: helpers.validate_input_files(args.input_files) esprint(f'Executing module: {args.module}') modules.handles[args.module].parse(**vars(args)) esprint('Module execution complete. Exiting.')