def module_cmdline(cmd_line, file_hash): html = "" cmd = Commands() split_commands = cmd_line.split(';') for split_command in split_commands: split_command = split_command.strip() if not split_command: continue root, args = parse(split_command) try: if root in cmd.commands: cmd.commands[root]['obj'](*args) html += print_output(cmd.output) del (cmd.output[:]) elif root in __modules__: # if prev commands did not open a session open one on the current file if file_hash: path = get_sample_path(file_hash) __sessions__.new(path) module = __modules__[root]['obj']() module.set_commandline(args) module.run() html += print_output(module.output) del (module.output[:]) else: html += '<p class="text-danger">{0} is not a valid command</p>'.format( cmd_line) except: html += '<p class="text-danger">We were unable to complete the command {0}</p>'.format( cmd_line) __sessions__.close() return html
def module_cmdline(cmd_line, sha256): json_data = '' cmd = Commands() split_commands = cmd_line.split(';') for split_command in split_commands: split_command = split_command.strip() if not split_command: continue root = '' args = [] # Split words by white space. words = split_command.split() # First word is the root command. root = words[0] # If there are more words, populate the arguments list. if len(words) > 1: args = words[1:] try: if root in cmd.commands: cmd.commands[root]['obj'](*args) if cmd.output: json_data += str(cmd.output) del(cmd.output[:]) elif root in __modules__: # if prev commands did not open a session open one on the current file if sha256: path = get_sample_path(sha256) __sessions__.new(path) module = __modules__[root]['obj']() module.set_commandline(args) module.run() json_data += str(module.output) del(module.output[:]) else: json_data += "{'message':'{0} is not a valid command'.format(cmd_line)}" except: json_data += "{'message':'Unable to complete the command: {0}'.format(cmd_line)}" __sessions__.close() return json_data
def module_cmdline(project=None, cmd_line=None, file_hash=None): html = "" cmd = Commands() split_commands = cmd_line.split(';') for split_command in split_commands: split_command = split_command.strip() if not split_command: continue root, args = parse(split_command) try: if root in cmd.commands: cmd_to_run = cmd.commands[root]['obj'] cmd_to_run(*args) cmd_instance = cmd_to_run.__self__ html += print_output(cmd_instance.output) del (cmd_instance.output[:]) elif root in __modules__: # if prev commands did not open a session open one on the current file if file_hash: __project__.open(project) path = get_sample_path(file_hash, __project__) __sessions__.new(path) module = __modules__[root]['obj']() module.set_commandline(args) module.run() html += print_output(module.output) if cfg.modules.store_output and __sessions__.is_set(): Database().add_analysis(file_hash, split_command, module.output) del (module.output[:]) else: html += '<p class="text-danger">{0} is not a valid command</p>'.format( cmd_line) except Exception: html += '<p class="text-danger">We were unable to complete the command {0}</p>'.format( cmd_line) __sessions__.close() return html
def __init__(self): # This will keep the main loop active as long as it's set to True. self.active = True self.cmd = Commands()