def test_basic(tmpworkdir): # pylint: disable=unused-argument """manymap module execution test""" test_a = { 'id': str(uuid4()), 'module': 'manymap', 'params': '-sV', 'targets': ['invalid', 'tcp://127.0.0.1:1', 'udp://[::1]:2'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) assert result == 0 assert 'Host: 127.0.0.1 (localhost)' in file_from_zip( '%s.zip' % test_a['id'], 'output-1.gnmap').decode('utf-8') assert '# Nmap done at' in file_from_zip('%s.zip' % test_a['id'], 'output-2.gnmap').decode('utf-8')
def test_basic(tmpworkdir, test_dummy_a): # pylint: disable=unused-argument """dummy module execution test""" result = agent_main(['--assignment', json.dumps(test_dummy_a), '--debug']) assert result == 0 assert test_dummy_a['targets'][0] in file_from_zip( '%s.zip' % test_dummy_a['id'], 'assignment.json').decode('utf-8')
def import_file(path): """import nmap data from file or archive""" if is_zip(path): data = file_from_zip(path, 'output.xml').decode('utf-8') else: with open(path, 'r') as ftmp: data = ftmp.read() NmapParser._data_to_storage(data)
def test_basic(tmpworkdir): # pylint: disable=unused-argument """nmap module execution test""" test_a = { 'id': str(uuid4()), 'config': { 'module': 'nmap', 'args': '-sL', 'timing_perhost': 1 }, 'targets': ['127.0.0.1', '::1', '[ip6-localhost]'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) assert result == 0 assert 'Host: 127.0.0.1 (localhost)' in file_from_zip( f'{test_a["id"]}.zip', 'output.gnmap').decode('utf-8') assert 'Host: ::1 (localhost)' in file_from_zip( f'{test_a["id"]}.zip', 'output6.gnmap').decode('utf-8')
def import_file(path): """import all nmap data from file or achive""" if is_zip(path): with ZipFile(path) as fzip: for ftmp in [fname for fname in fzip.namelist() if re.match(r'output\-[0-9]+\.xml', fname)]: NmapParser._data_to_storage(file_from_zip(path, ftmp).decode('utf-8')) else: with open(path, 'r') as ftmp: ManymapParser._data_to_storage(ftmp.read())
def parse_path(path): """parse data from path""" hosts, notes = [], [] data = json.loads(file_from_zip(path, 'output.json')) for addr, via in data.items(): hosts.append(ParsedHost(handle={'host': addr}, address=addr)) notes.append(ParsedNote(handle={'host': addr}, xtype='six_dns_discover.via', data=json.dumps(via))) return hosts, [], [], notes
def parse_path(path): """parse path and returns list of hosts/addresses""" hosts = [] with ZipFile(path) as fzip: for ftmp in [fname for fname in fzip.namelist() if re.match(r'output\-[0-9]+\.txt', fname)]: for addr in file_from_zip(path, ftmp).decode('utf-8').splitlines(): hosts.append(ParsedHost(handle={'host': addr}, address=addr)) return hosts, [], [], []
def parse_path(cls, path): """parse data from path""" pidb = ParsedItemsDb() with ZipFile(path) as fzip: for fname in filter(lambda x: re.match(cls.ARCHIVE_PATHS, x), fzip.namelist()): pidb += cls._parse_data( file_from_zip(path, fname).decode('utf-8')) return pidb
def parse_path(cls, path): """parse path and returns list of hosts/addresses""" pidb = ParsedItemsDb() with ZipFile(path) as fzip: for fname in filter(lambda x: re.match(cls.ARCHIVE_PATHS, x), fzip.namelist()): for addr in file_from_zip(path, fname).decode('utf-8').splitlines(): pidb.hosts.upsert(ParsedHost(address=addr)) return pidb
def test_basic(tmpworkdir): # pylint: disable=unused-argument """nmap module execution test""" test_a = { 'id': str(uuid4()), 'module': 'nmap', 'params': '-sL', 'targets': ['127.0.0.1'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) assert result == 0 assert 'Host: 127.0.0.1 (localhost)' in file_from_zip( '%s.zip' % test_a['id'], 'output.gnmap').decode('utf-8')
def test_run_with_liveserver(tmpworkdir, live_server, apikey, test_dummy_target): # pylint: disable=unused-argument """test basic agent's networking codepath; fetch, execute, pack and upload assignment""" result = agent_main([ '--server', live_server.url(), '--apikey', apikey, '--debug', '--queue', str(test_dummy_target.queue_id), '--oneshot' ]) assert result == 0 job = Job.query.filter(Job.queue_id == test_dummy_target.queue_id).one() assert test_dummy_target.target in file_from_zip( job.output_abspath, 'assignment.json').decode('utf-8')
def test_basic(tmpworkdir): # pylint: disable=unused-argument """dix_dns_discover test""" test_a = { 'id': str(uuid4()), 'config': { 'module': 'six_dns_discover', 'delay': 1 }, 'targets': ['127.0.0.1', '0.0.0.0'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) assert result == 0 assert '::1' in json.loads(file_from_zip(f'{test_a["id"]}.zip', 'output.json').decode('utf-8'))
def parse_path(path): """parse data from path""" pidb = ParsedItemsDb() data = json.loads(file_from_zip(path, 'output.json')) for addr, via in data.items(): host = ParsedHost(address=addr) note = ParsedNote(host_handle=host.handle, xtype='six_dns_discover.via', data=json.dumps(via)) pidb.hosts.upsert(host) pidb.notes.upsert(note) return pidb
def parse_path(cls, path): """parse data from path""" if is_zip(path): hosts, services, vulns, notes = Pdict(), Pdict(), Pdict(), Pdict() with ZipFile(path) as fzip: for ftmp in [fname for fname in fzip.namelist() if re.match(cls.ARCHIVE_PATHS, fname)]: thosts, tservices, tvulns, tnotes = NmapParser._parse_data(file_from_zip(path, ftmp).decode('utf-8')) for storage, items in [(hosts, thosts), (services, tservices), (vulns, tvulns), (notes, tnotes)]: for item in items: storage.upsert(item) return list(hosts.values()), list(services.values()), list(vulns.values()), list(notes.values()) return NmapParser._parse_data(Path(path).read_text())
def test_basic(tmpworkdir): # pylint: disable=unused-argument """dummy module execution test""" test_a = { 'id': str(uuid4()), 'config': { 'module': 'dummy', 'args': '--static_assignment' }, 'targets': ['target1'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) assert result == 0 assert test_a['targets'][0] in file_from_zip( f'{test_a["id"]}.zip', 'assignment.json').decode('utf-8')
def test_basic(tmpworkdir): # pylint: disable=unused-argument """jarm module execution test""" test_a = { 'id': str(uuid4()), 'config': { 'module': 'jarm', 'delay': 0 }, 'targets': ['tcp://127.0.0.1:1', 'udp://127.0.0.1:1'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) assert result == 0 assert \ 'JARM: 00000000000000000000000000000000000000000000000000000000000000' \ in file_from_zip(f'{test_a["id"]}.zip', 'output-0.out').decode('utf-8')
def test_run_with_liveserver(tmpworkdir, live_server, apikey, dummy_target): # pylint: disable=unused-argument """test basic agent's networking codepath; fetch, execute, pack and upload assignment""" result = agent_main([ '--server', url_for('index_route', _external=True), '--apikey', apikey, '--queue', Queue.query.get(dummy_target.queue_id).name, '--caps', 'cap1', 'cap2', '--oneshot', '--debug', ]) assert result == 0 job = Job.query.filter(Job.queue_id == dummy_target.queue_id).one() assert dummy_target.target in file_from_zip( job.output_abspath, 'assignment.json').decode('utf-8')
def test_basic(tmpworkdir): # pylint: disable=unused-argument """six_enum_discover test""" test_a = { 'id': str(uuid4()), 'config': { 'module': 'six_enum_discover', 'rate': 100 }, 'targets': ['::1'] } result = agent_main(['--assignment', json.dumps(test_a), '--debug']) # travis does not support ipv6 on bionic if 'TRAVIS' in os.environ: assert result == 1 return assert result == 0 assert '::1' in file_from_zip(f'{test_a["id"]}.zip', 'output-0.txt').decode('utf-8')