def dummy_cb(job, host, conn, template_test): # Warning: Assertions raised in this function happen in a subprocess! # Create a log object. log = Log() conn.data_received_event.connect(log.collect) # Connect and load the test template. conn.connect(host.get_address(), host.get_tcp_port()) test_name = host.get_address() if host.get_protocol() == 'ios': dirname = os.path.join(test_dir, test_name) else: dirname = os.path.dirname(test_name) tmpl = os.path.join(dirname, 'test.exscript') expected = os.path.join(dirname, 'expected') # Go. conn.login(flush=True) try: template.eval_file(conn, tmpl, slot=10) except Exception as e: print(log.data) raise log.data = log.data.replace('\r\n', '\n') if sys.version_info[0] == 2: with open(expected) as fp: expected_data = fp.read() else: with open(expected, newline='') as fp: expected_data = fp.read() #open(expected, 'w').write(log.data) #open('output', 'w').write(log.data) #open('exp', 'w').write(expected_data) template_test.assertEqual(log.data, expected_data)
def dummy_cb(job, host, conn, template_test): # Warning: Assertions raised in this function happen in a subprocess! # Create a log object. log = Log() conn.data_received_event.connect(log.collect) # Connect and load the test template. conn.connect(host.get_address(), host.get_tcp_port()) test_name = host.get_address() if host.get_protocol() == 'ios': dirname = os.path.join(test_dir, test_name) else: dirname = os.path.dirname(test_name) tmpl = os.path.join(dirname, 'test.exscript') expected = os.path.join(dirname, 'expected') # Go. conn.login(flush = True) try: template.eval_file(conn, tmpl, slot = 10) except Exception, e: print log.data raise
def dummy_cb(job, host, conn, template_test): # Warning: Assertions raised in this function happen in a subprocess! # Create a log object. log = Log() conn.data_received_event.connect(log.collect) # Connect and load the test template. conn.connect(host.get_address(), host.get_tcp_port()) test_name = host.get_address() if host.get_protocol() == 'ios': dirname = os.path.join(test_dir, test_name) else: dirname = os.path.dirname(test_name) tmpl = os.path.join(dirname, 'test.exscript') expected = os.path.join(dirname, 'expected') # Go. conn.login(flush=True) try: template.eval_file(conn, tmpl, slot=10) except Exception, e: print log.data raise
def do_something(job, host, conn): assert conn.guess_os() == 'shell' conn.execute('ls -1') eval_file(conn, 'template.exscript', foobar='hello-world')
def do_something(conn): assert conn.guess_os() == 'shell' conn.execute('ls -1') eval_file(conn, 'template.exscript', foobar='hello-world')
def main(): args = args_parser() print_banner() host = args.host port = args.port username = args.username password = args.password ssh = args.ssh telnet = args.telnet category = args.category plugin = args.plugin if plugin and (category == None): sys.exit(RED + '\n[!] No category\n' + ENDC) # Set host if host == None: host = raw_input('set host' + BLUE + ' > ' + ENDC) # Set service if (ssh == False) and (telnet == False): service = raw_input('set service [ssh|telnet]' + BLUE + ' > ' + ENDC) if service.lower() == 'ssh': ssh = True elif service.lower() == 'telnet': telnet = True if ssh: conn = SSH2() elif telnet: conn = Telnet() else: sys.exit(RED + '\n[!] Bad service type. Options: [ssh|telnet]\n' + ENDC) # Set username if username == None: username = raw_input('set username' + BLUE + ' > ' + ENDC) # Set password if password == None: password = getpass.getpass('set password' + BLUE + ' > ' + ENDC) # Create account account = Account(username, password) # Connect and login conn.connect(host, port) conn.login(account) # Try to disable history for current shell session conn.execute('unset HISTFILE') # Print info about used Exscript driver driver = conn.get_driver() print BLUE + '\n[i] Using driver: ' + ENDC + driver.name # Set logs directory logs_path = LOGS_PATH + '/' + host + '-' + str(int(time.time())) if category: print BLUE + '\n[i] Plugins category: ' + ENDC + category + '\n' dict_categories = {} dict_plugins = {} # Run single plugin if plugin: try: eval_file(conn, INSTALL_PATH + '/plugins/' + category + '/' + plugin) dict_plugins[plugin] = conn.response print ' %-20s' % (plugin) + '[' + GREEN + 'ok' + ENDC + ']' except: print ' %-20s' % (plugin) + '[' + RED + 'ko' + ENDC + ']' pass dict_categories[category] = dict_plugins # Run plugins by single category else: for plugin in sorted(os.listdir(INSTALL_PATH + '/plugins/' + category)): try: eval_file(conn, INSTALL_PATH + '/plugins/' + category + '/' + plugin) dict_plugins[plugin] = conn.response print ' %-20s' % (plugin) + '[' + GREEN + 'ok' + ENDC + ']' except: print ' %-20s' % (plugin) + '[' + RED + 'ko' + ENDC + ']' pass dict_categories[category] = dict_plugins # Run all plugins by category if (category == None) and (plugin == None): dict_categories = {} for category in sorted(os.listdir(INSTALL_PATH + '/plugins')): print BLUE + '\n[i] Plugins category: ' + ENDC + category + '\n' dict_plugins = {} for plugin in sorted(os.listdir(INSTALL_PATH + '/plugins/' + category)): try: eval_file(conn, INSTALL_PATH + '/plugins/' + category + '/' + plugin) dict_plugins[plugin] = conn.response print ' %-20s' % (plugin) + '[' + GREEN + 'ok' + ENDC + ']' except: print ' %-20s' % (plugin) + '[' + RED + 'ko' + ENDC + ']' pass dict_categories[category] = dict_plugins # Exit and close remote connection conn.send('exit\r') conn.close() # Generate report html_report(dict_categories, logs_path) print BLUE + '\n[i] Report saved to: ' + ENDC + logs_path + '/index.html\n'
def main(): args = args_parser() print_banner() host = args.host port = args.port username = args.username password = args.password privatekey = args.privatekey passphrase = args.passphrase keytype = args.keytype ssh = args.ssh telnet = args.telnet category = args.category plugin = args.plugin if plugin and (category == None): sys.exit(RED + '\n[!] No category\n' + ENDC) # Set host if host == None: host = raw_input('set host' + BLUE + ' > ' + ENDC) # Set service if (ssh == False) and (telnet == False): service = raw_input('set service [ssh|telnet]' + BLUE + ' > ' + ENDC) if service.lower() == 'ssh': ssh = True elif service.lower() == 'telnet': telnet = True if ssh: conn = SSH2() elif telnet: conn = Telnet() else: sys.exit(RED + '\n[!] Bad service type. Options: [ssh|telnet]\n' + ENDC) # Set username if username == None: username = raw_input('set username' + BLUE + ' > ' + ENDC) # Set password if (password == None) and (privatekey == None): password = getpass.getpass('set password (leave blank to enter a private key)' + BLUE + ' > ' + ENDC) #set privatekey if (password == None): #set privatekey if (privatekey == None): privatekey = getpass.getpass('set private key path' + BLUE + ' > ' + ENDC) #set passphrase if (passphrase == None): passphrase = getpass.getpass('set private key passphrase (optional)' + BLUE + ' > ' + ENDC) #set keytype if (keytype == None): keytype = raw_input('set keytype (optional)' + BLUE + ' > ' + ENDC) if (keytype != "") and (passphrase != ""): key = PrivateKey.from_file(privatekey, password=passphrase, keytype=keytype) elif (keytype != ""): key = PrivateKey.from_file(privatekey, password=passphrase) else: key = PrivateKey.from_file(privatekey) else: key = None # Create account account = Account(username, password, key = key) # Connect and login conn.connect(host, port) conn.login(account) # Try to disable history for current shell session conn.execute('unset HISTFILE') # Print info about used Exscript driver driver = conn.get_driver() print BLUE + '\n[i] Using driver: ' + ENDC + driver.name # Set logs directory logs_path = LOGS_PATH + '/' + host + '-' + str(int(time.time())) if category: print BLUE + '\n[i] Plugins category: ' + ENDC + category + '\n' dict_categories = {} dict_plugins = {} # Run single plugin if plugin: try: eval_file(conn, INSTALL_PATH + '/plugins/' + category + '/' + plugin) dict_plugins[plugin] = conn.response print ' %-20s' % (plugin) + '[' + GREEN + 'ok' + ENDC + ']' except: print ' %-20s' % (plugin) + '[' + RED + 'ko' + ENDC + ']' pass dict_categories[category] = dict_plugins # Run plugins by single category else: for plugin in sorted(os.listdir(INSTALL_PATH + '/plugins/' + category)): try: eval_file(conn, INSTALL_PATH + '/plugins/' + category + '/' + plugin) dict_plugins[plugin] = conn.response print ' %-20s' % (plugin) + '[' + GREEN + 'ok' + ENDC + ']' except: print ' %-20s' % (plugin) + '[' + RED + 'ko' + ENDC + ']' pass dict_categories[category] = dict_plugins # Run all plugins by category if (category == None) and (plugin == None): dict_categories = {} for category in sorted(os.listdir(INSTALL_PATH + '/plugins')): print BLUE + '\n[i] Plugins category: ' + ENDC + category + '\n' dict_plugins = {} for plugin in sorted(os.listdir(INSTALL_PATH + '/plugins/' + category)): try: eval_file(conn, INSTALL_PATH + '/plugins/' + category + '/' + plugin) dict_plugins[plugin] = conn.response print ' %-20s' % (plugin) + '[' + GREEN + 'ok' + ENDC + ']' except: print ' %-20s' % (plugin) + '[' + RED + 'ko' + ENDC + ']' pass dict_categories[category] = dict_plugins # Exit and close remote connection conn.send('exit\r') conn.close() # Generate report html_report(dict_categories, logs_path) print BLUE + '\n[i] Report saved to: ' + ENDC + logs_path + '/index.html\n'