Exemplo n.º 1
0
def exit_program(signal, frame):
    if signal == -1:  # immediate termination due to -h or bad parameter
        lib.scheduler.stop()
        sys.exit(0)

    log.attachline()
    log.info('Terminating all connections...')
    for c in lib.connections:
        for con in c.connectors[::-1]:
            con.close()  # for Paramiko, TODO for every type?

    log.info('Killing all the threads...')

    # stop the scheduler (will stop all threads)
    lib.scheduler.stop()
    # wait for scheduler termination
    while lib.scheduler.is_alive():
        time.sleep(0.1)
    log.info('Cleaning databases...')
    lib.db['dict'].clean()
    lib.db['vuln'].clean()
    lib.db['checksum'].clean()
    # disconnect from databases
    log.info('Disconnecting from databases...')
    for db in lib.db.values():
        if db:
            db.close()
    log.info('%s out.' % lib.appname)
    sys.exit(0 if signal is None else 1)
Exemplo n.º 2
0
	def dump(self, query=''):
		keys = [x for x in query.split(' ') if len(x)>0]
		# print the knowledge base/selected branch
		if len(keys) == 0:
			#log.attachline(json.dumps(self.kb, indent=4)) # not working in python3
			KB.get_structure(self.kb)
		else:
			# find the desired branch
			result = self.search(keys, parent=False, silent=False)
			log.attachline(' > '.join(keys[:result[1]+1])+':', log.Color.PURPLE)
			#log.attachline(json.dumps(result[0], indent=4))
			KB.get_structure(result[0])
Exemplo n.º 3
0
def main():
    global_parameters['UUID'] = get_local_uuid()
    lib.active_session = db['analysis'].get_last_session()
    if lib.active_session is None:
        # Cannot get any session ID =>
        # analysis.db is not accessible =>
        # 'install script has not been executed'
        log.err('Cannot get session ID. Did you run correct installation script?')
        exit_program(-1, None)
        
    db['analysis'].create_session(lib.active_session)
    log.info('Currently working with session #%d.' % lib.active_session)
    # check if already admin
    if is_admin():
        log.ok('Administrator privileges already granted on \'%s\'.' % (global_parameters['ACTIVEROOT']), dbnote=DBNOTE_UNIQUE)
    # if input from file, load commands into queue
    if args.input_file is not None:
        if os.access(args.input_file[0], os.R_OK):
            with open(args.input_file[0], 'r') as f:
                lib.commands = [x if x not in QUIT_STRINGS else 'force_exit' for x in f.read().splitlines()]
                lib.from_input_file = True
        else:
            log.err('Input file cannot be read!')

    # run all input commands
    while len(lib.commands) > 0:
        c = lib.commands[0]
        del lib.commands[0]
        if lib.from_input_file:
            log.prompt()            # print prompt
            log.attachline(c)       # print command
        execute_command(c)          # run the command

    lib.from_input_file = False
        
    # main loop
    while True:
        # input from stdin, piped or redirected
        log.prompt()
        if lib.python_version[0] == '2':
            func = raw_input
        elif lib.python_version[0] == '3':
            func = input
        else:
            log.err('Undefined python version (%s).' % lib.python_version)
            break
        # add command into queue
        #lib.commands.append(func())
        try:
            execute_command(func())
        except EOFError as e: # Ctrl+D => exit
            exit_program(None, None)
Exemplo n.º 4
0
 def dump(self, query=''):
     keys = [x for x in query.split(' ') if len(x) > 0]
     # print the knowledge base/selected branch
     if len(keys) == 0:
         #log.attachline(json.dumps(self.kb, indent=4)) # not working in python3
         KB.get_structure(self.kb)
     else:
         # find the desired branch
         result = self.search(keys, parent=False, silent=False)
         log.attachline(' > '.join(keys[:result[1] + 1]) + ':',
                        log.Color.PURPLE)
         #log.attachline(json.dumps(result[0], indent=4))
         KB.get_structure(result[0])
Exemplo n.º 5
0
def main():
    global_parameters['UUID'] = get_local_uuid()
    lib.active_session = db['analysis'].get_last_session()
    db['analysis'].create_session(lib.active_session)
    log.info('Currently working with session #%d.' % lib.active_session)
    # check if already admin
    if is_admin():
        log.ok('Administrator privileges already granted on \'%s\'.' % (global_parameters['ACTIVEROOT']), dbnote=DBNOTE_UNIQUE)
    # if input from file, load commands into queue
    if args.input_file is not None:
        if os.access(args.input_file[0], os.R_OK):
            with open(args.input_file[0], 'r') as f:
                lib.commands = f.read().splitlines()
                lib.from_input_file = True
        else:
            log.err('Input file cannot be read!')

    # run all input commands
    while len(lib.commands) > 0:
        c = lib.commands[0]
        del lib.commands[0]
        if lib.from_input_file:
            log.prompt()            # print prompt
            log.attachline(c)       # print command
        execute_command(c)          # run the command

    lib.from_input_file = False
        
    # main loop
    while True:
        # input from stdin
        log.prompt()
        if lib.python_version[0] == '2':
            func = raw_input
        elif lib.python_version[0] == '3':
            func = input
        else:
            log.err('Undefined python version (%s).' % lib.python_version)
            break
        # add command into queue
        #lib.commands.append(func())
        execute_command(func())
Exemplo n.º 6
0
def exit_program(signal, frame):
    if signal == -1: # immediate termination due to -h or bad parameter
        lib.scheduler.stop()
        sys.exit(0)
    
    log.attachline()
    log.info('Killing all the threads...')
    # stop the scheduler (will stop all threads)
    lib.scheduler.stop()
    # wait for scheduler termination
    while lib.scheduler.isAlive():
        time.sleep(0.1)
    log.info('Cleaning databases...')
    lib.db['dict'].clean()
    # disconnect from databases
    log.info('Disconnecting from databases...')
    for dbname in lib.db.keys():
        if lib.db[dbname]:
            lib.db[dbname].close()
    log.info('%s out.' % lib.appname)
    sys.exit(0)
Exemplo n.º 7
0
 def get_structure(data, tab=0):
     """ print a given Knowledge Base branch """
     # dictionary
     if type(data) is dict:
         log.attachline(' ' * tab + '{')
         for key in natural_sort(data):
             log.attachline(' ' * tab + '  ' + key + ':')
             KB.get_structure(data[key], tab + 4)
         log.attachline(' ' * tab + '}')
     # list
     elif type(data) is list and len(data) > 0:
         log.attachline(' ' * tab + '[')
         KB.get_structure(data[0], tab + 4)
         log.attachline(' ' * tab + ']')
     # unicode string
     elif type(data) is str:
         for line in data.splitlines():
             log.attachline(' ' * tab + line)
     # bytes, transform to unicode string
     elif type(data) is bytes:
         data = data.decode('utf-8')
         for line in data.splitlines():
             log.attachline(' ' * tab + line)
Exemplo n.º 8
0
	def get_structure(data, tab = 0):
		""" print a given Knowledge Base branch """
		# dictionary
		if type(data) is dict:
			log.attachline(' ' * tab + '{')
			for key in natural_sort(data):
				log.attachline(' ' * tab + '  ' + key + ':')
				KB.get_structure(data[key], tab + 4)
			log.attachline(' ' * tab + '}')
		# list
		elif type(data) is list and len(data) > 0:
			log.attachline(' ' * tab + '[')
			KB.get_structure(data[0], tab+4)
			log.attachline(' ' * tab + ']')
		# unicode string
		elif type(data) is str:
			for line in data.splitlines():
				log.attachline(' ' * tab + line)
		# bytes, transform to unicode string
		elif type(data) is bytes:
			data = data.decode('utf-8')
			for line in data.splitlines():
				log.attachline(' ' * tab + line)