def test_transform_more_complex_response(self): transform = EtreeTransform() result = transform('<foo id="bar"><lorem/><ipsum/></foo>') self.assertTrue(etree.iselement(result)) self.assertEqual(result.tag, 'foo') self.assertEqual(result.get('id'), 'bar') self.assertEqual(len(result), 2)
def is_running(taskid): connection = UnixSocketConnection() transform = EtreeTransform() with Gmp(connection, transform=transform) as gmp: # Login -> change to default admin password gmp.authenticate('scanner', 'scanner') taskxml = gmp.get_task(taskid) if get_status(taskxml) == 'Running': return True return False
def get_newprogress(taskid): connection = UnixSocketConnection() transform = EtreeTransform() with Gmp(connection, transform=transform) as gmp: # Login -> change to default admin password gmp.authenticate('scanner', 'scanner') taskxml = gmp.get_task(taskid) if is_requested(taskid): return 0 if is_running(taskid): return int(get_progress(taskxml))
def main(): logging.basicConfig(filename='openvas-error.log', level=logging.ERROR) logging.basicConfig(filename='openvas-debug.log', level=logging.DEBUG) path = '/usr/local/var/run/gvmd.sock' connection = UnixSocketConnection(path=path) transform = EtreeTransform() openvas_remote = OpenvasRemote(path, connection, transform) username = str(sys.arg[1]) password = str(sys.arg[2]) #==================Please comment out the next 4 lines after running this python script once=================================== id = openvas_remote.create_target('TestTarget',['192.168.112.137'], username, password) task_id = openvas_remote.create_task('OpenVasTestTask', openvas_remote.get_full_and_fast_config_id(), id, openvas_remote.get_default_openvas_scanner_id(), username , password) report_id = openvas_remote.start_task(task_id, username, password) print('replace this id: ' + report_id + ' in report id in this code file to get the report in a json format')
def __init__(self): connection = UnixSocketConnection(path=config['OPENVAS_SOCKET']) transform = EtreeTransform() self.gmp = Gmp(connection, transform=transform) self.storage_service = StorageService() # Login try: self.gmp.authenticate(config['OPENVAS_USERNAME'], config['OPENVAS_PASSWORD']) except: print(f'[{self.name}] Not able to connect to the {self.name}: ', sys.exc_info()) return
def __init__(self): connection = TLSConnection(hostname=config['HOST_NAME'], port=config['PORT'], certfile=None, cafile=None, keyfile=None, password=None, timeout=25) transform = EtreeTransform() self.gmp = Gmp(connection, transform=transform) self.storage_service = StorageService() # Login try: self.gmp.authenticate(config['OPENVAS_USERNAME'], config['OPENVAS_PASSWORD']) except: print(f'[{self.name}] Not able to connect to the {self.name}: ', sys.exc_info()) return
def scan(target_name, ipList, config_id): thread_list = [] connection = UnixSocketConnection() transform = EtreeTransform() with Gmp(connection, transform=transform) as gmp: gmp.authenticate('scanner', 'scanner') # #target creation custome_port_table(ipList) #target creation with custome port list with open("ports/ports.txt", "r") as f: inhoud2 = f.read() #Creating a new portlist portListName = target_name.replace( ' ', '-').lower() + "_" + datetime.now().strftime("%d/%m/%Y_%H:%M:%S") superCooleLijst = gmp.create_port_list(portListName, inhoud2) pretty_print(superCooleLijst) superCooleLijstID = get_id(superCooleLijst) target = gmp.create_target(target_name, hosts=ipList, port_list_id=superCooleLijstID) target_id = get_id(target) # task creation # arguments: target_name, config_id, target_id, scanner_id task = gmp.create_task(target_name, config_id, target_id, '08b69003-5fc2-4037-a479-93b440211c73') task_id = get_id(task) #task start gmp.start_task(task_id) return task_id #for cli version (old) print("task started succesfully!")
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', datefmt='[%Y-%m-%d %H:%M:%S]', level=options.loglevel.upper()) if len(args) != 2: parser.print_help() sys.exit() hosts = args[0] outputfile = args[1] logging.info('Hosts: {}'.format(hosts)) logging.info('Outputfile: {}'.format(outputfile)) connection = TLSConnection() transform = EtreeTransform() logging.info('Connecting to GMP') with Gmp(connection, transform=transform) as gmp: gmp.authenticate('admin', 'admin') logging.info('Authenticated') # Get the base config based on the provided name config = gmp.get_configs(filter="name=\"{}\"".format(options.scan_config), details=True) config_exists = len(config.xpath("//config")) == 1 if not config_exists: logging.error('Selected config "%s" does not exist' % options.scan_config) sys.exit()
def test_transform_response(self): transform = EtreeTransform() result = transform('<foo/>') self.assertTrue(etree.iselement(result))
def _connect(self): conn = TLSConnection(hostname=self._config.host, port=self._config.port) with Gmp(connection=conn, transform=EtreeTransform()) as gmp: gmp.authenticate(self._config.username, self._config.password) yield gmp