def scan(input_file, output_file, uuid, drop=True, interactive=False): context = {} context['scan_id'] = uuid context['drop_database'] = True context['resource_path'] = RESOURCE_PATH context['input_file'] = path.abspath(input_file) context['output_file'] = path.abspath(output_file) tmpl = TEMPLATE_ENV.get_template(TEMPLATE_FILE) fd = tempfile.NamedTemporaryFile(prefix='scan') fd.write(tmpl.render(context)) fd.flush() # TODO If there is an error in the script then this will just keep # running. We need to either prevent metasploit from dropping to # interactive console or detect the prompt. args = [METASPLOIT, '-m', MODULE_PATH, '-r', fd.name] if not interactive: # TODO this file needs to be saved somewhere or read back to # the user for logging. fd1 = tempfile.NamedTemporaryFile(prefix='scan-output') args.extend(['-o', fd1.name]) subprocess.call(" ".join(args), shell=True)
def export_servers(servers, fd): context = {'hosts': servers, 'now': datetime.now(pytz.timezone("UTC"))} tmpl = TEMPLATE_ENV.get_template(TEMPLATE_FILE) fd.write(tmpl.render(context))