def main(workspace='', args=None, parser=None): parser.add_argument('interface_id', help='Interface ID') parser.add_argument('name', help='Service Name') parser.add_argument('ports', help='Service ports, as a comma separated list') parser.add_argument('--protocol', help='Service protocol', default='tcp') parser.add_argument('--status', help='Service status', default='running') parser.add_argument('--version', help='Service version', default='unknown') parser.add_argument('--description', help='Service description', default='') parser.add_argument('--dry-run', action='store_true', help='Do not touch the database. Only print the object ID') parsed_args = parser.parse_args(args) ports = filter(None, parsed_args.ports.split(',')) obj = factory.createModelObject(models.Service.class_signature, parsed_args.name, workspace, protocol=parsed_args.protocol, ports=ports, status=parsed_args.status, version=parsed_args.version, description=parsed_args.description, parent_id=parsed_args.interface_id ) old = models.get_service(workspace, obj.getID()) if old is None: if not parsed_args.dry_run: models.create_service(workspace, obj) else: print "A service with ID %s already exists!" % obj.getID() return 2, None return 0, obj.getID()
def main(workspace='', args=None, parser=None): parser.add_argument('host_id', help='Service Parent Host ID') parser.add_argument('name', help='Service Name') parser.add_argument('ports', help='Service ports, as a comma separated list') parser.add_argument('--protocol', help='Service protocol', default='tcp') parser.add_argument('--status', help='Service status', default='open') parser.add_argument('--version', help='Service version', default='unknown') parser.add_argument('--description', help='Service description', default='') parser.add_argument( '--dry-run', action='store_true', help='Do not touch the database. Only print the object ID') parsed_args = parser.parse_args(args) ports = filter(None, parsed_args.ports.split(',')) res_ids = [] #new service or old services ids affected by the command for port in ports: params = { 'name': parsed_args.name, 'port': port, 'protocol': parsed_args.protocol, 'host_id': parsed_args.host_id } obj = factory.createModelObject(models.Service.class_signature, parsed_args.name, workspace, protocol=parsed_args.protocol, ports=[port], status=parsed_args.status, version=parsed_args.version, description=parsed_args.description, parent_id=parsed_args.host_id) old = models.get_service(workspace, **params) if old is None: if not parsed_args.dry_run: models.create_service(workspace, obj) old = models.get_service(workspace, **params) else: print("A service with ID %s already exists!" % old.getID()) res_ids.append(old.getID()) return 0, res_ids
def main(workspace='', args=None, parser=None): parser.add_argument('interface_id', help='Interface ID') parser.add_argument('name', help='Service Name') parser.add_argument('ports', help='Service ports, as a comma separated list') parser.add_argument('--protocol', help='Service protocol', default='tcp') parser.add_argument('--status', help='Service status', default='running') parser.add_argument('--version', help='Service version', default='unknown') parser.add_argument('--description', help='Service description', default='') parser.add_argument( '--dry-run', action='store_true', help='Do not touch the database. Only print the object ID') parsed_args = parser.parse_args(args) ports = filter(None, parsed_args.ports.split(',')) obj = factory.createModelObject(models.Service.class_signature, parsed_args.name, workspace, protocol=parsed_args.protocol, ports=ports, status=parsed_args.status, version=parsed_args.version, description=parsed_args.description, parent_id=parsed_args.interface_id) old = models.get_service(workspace, obj.getID()) if old is None: if not parsed_args.dry_run: models.create_service(workspace, obj) else: print "A service with ID %s already exists!" % obj.getID() return 2, None return 0, obj.getID()
def save_objs(workspace_name): """ This function uses a set to avoid hitting too much couchdb. Wifi packets usually are repeated, for example for beacons. :param workspace_name: :return: """ order = ['Host', 'Interface', 'Service', 'Vulnerability'] saved_ids = set() tmp = created_objs iterable = tmp.items() for type in order: for key, objs in iterable: if key == type: try: if key == 'Host': print('Total {0}: {1}'.format(key, len(objs))) for obj in objs: if obj.id in saved_ids: models.update_host(workspace_name, obj) else: models.create_host(workspace_name, obj) saved_ids.add(obj.id) if key == 'Service': print('Total {0}: {1}'.format(key, len(objs))) for obj in objs: if obj.id in saved_ids: models.update_service(workspace_name, obj) else: models.create_service(workspace_name, obj) saved_ids.add(obj.id) if key == 'Vulnerability': print('Total {0}: {1}'.format(key, len(objs))) for obj in objs: if obj.id in saved_ids: models.update_vuln(workspace_name, obj) else: models.create_vuln(workspace_name, obj) if key == 'Interface': print('Total {0}: {1}'.format(key, len(objs))) for obj in objs: if obj.id in saved_ids: models.update_interface(workspace_name, obj) else: models.create_interface(workspace_name, obj) saved_ids.add(obj.id) except ConflictInDatabase as e: print('Document already exists skipping.') print(e) continue except CantCommunicateWithServerError as e: print('error') print(e) except ResourceDoesNotExist as e: print('Missing DB {0}'.format(workspace_name)) print(e) continue except Exception as e: print(e)
def process_wigle_sqlite(workspace_name, wigle_filename): try: import sqlite3 except ImportError: print( 'For using wigle import, sqlite3 is required. Please install it with: pip install sqlite3' ) conn = sqlite3.connect(wigle_filename) cursor = conn.execute( 'SELECT bssid, ssid, capabilities, bestlat, bestlon from network') for network in cursor: bssid = network[0] essid = network[1] capability = network[2].lower() lat = network[4] lng = network[3] access_point = access_point_data[bssid] if 'wpa' in capability and 'wpa2' not in capability: encryption = 'wpa' if 'wpa2' in capability: encryption = 'wpa2' if 'wep' in capability: encryption = 'wep' if 'open' in capability: encryption = 'open' access_point['essid'] = essid access_point['bssid'] = bssid access_point['encryption'] = encryption access_point['lat'] = lat access_point['lng'] = lng create_host_interface_and_vuln(workspace_name, access_point) map_file = draw_map() map_file.seek(0) now_timestamp = time.time() host = factory.createModelObject(models.Host.class_signature, 'War driving results', workspace_name=workspace_name, parent_id=None) interface = factory.createModelObject(models.Interface.class_signature, '', workspace_name, mac=bssid, ipv4_address='', ipv4_gateway='', ipv4_mask='', ipv4_dns='', ipv6_address='', ipv6_gateway='', ipv6_prefix='', ipv6_dns='', network_segment='', parent_id=host.id) service = factory.createModelObject(models.Service.class_signature, encryption, workspace_name, protocol='802.11', status='open', description='Access point encryption', ports=[0], version='', service='open', parent_id=interface.id) try: models.create_host(workspace_name, host) except ConflictInDatabase: pass try: models.create_interface(workspace_name, interface) except ConflictInDatabase: pass try: models.create_service(workspace_name, service) except ConflictInDatabase: pass name = 'Wardriving Map' description = 'See evidence for war driving map.' parent_id = host.id raw_obj = { "metadata": { "update_time": now_timestamp, "update_user": "", "update_action": 0, "creator": "UI Web", "create_time": now_timestamp, "update_controller_action": "UI Web New", "owner": "" }, "obj_id": "0c41d85f6dc71044518eea211bfbd12f2bad6f73", "owner": "", "parent": parent_id, "type": "Vulnerability", "ws": "wifi", "confirmed": True, "data": "", "desc": description, "easeofresolution": "", "impact": { "accountability": False, "availability": False, "confidentiality": False, "integrity": False }, "name": name, "owned": False, "policyviolations": [], "refs": [], "resolution": "", "severity": "info", "status": "opened", "_attachments": { "map.png": { "content_type": "image/png", "data": b64encode(map_file.read()) } }, "protocol": "", "version": "" } obj = models.ModelBase(raw_obj, workspace_name) obj.setID(parent_id, name, description) vuln_id = obj.id raw_obj.update({"_id": vuln_id}) try: _save_to_couch(workspace_name, vuln_id, **raw_obj) except ConflictInDatabase: pass map_file.close()
def main(workspace="", args=None, parser=None): WORKSPACE = workspace parser.add_argument("--csv", help="Csv file to import") parsed_args = parser.parse_args(args) if not parsed_args.csv: print "Error: Give a CSV file to import with --csv" return 2, None try: file_csv = open(parsed_args.csv, "r") except: print "Error: Unreadeable CSV file, check the path" raise counter = 0 csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"') for register in csv_reader: host, interface, service, vulnerability, vulnerability_web = parse_register(register) # Set all IDs and create objects if host is not None: host.setID(None) if not models.get_host(WORKSPACE, host.getID()): counter += 1 print "New host: " + host.getName() models.create_host(WORKSPACE, host) if interface is not None: interface.setID(host.getID()) if not models.get_interface(WORKSPACE, interface.getID()): counter += 1 print "New interface: " + interface.getName() models.create_interface(WORKSPACE, interface) if service is not None: service.setID(interface.getID()) if not models.get_service(WORKSPACE, service.getID()): counter += 1 print "New service: " + service.getName() models.create_service(WORKSPACE, service) # Check if Service exist, then create the vuln with parent Service. # If not exist the Service, create the vuln with parent Host. if vulnerability is not None: if service is None: vulnerability.setID(host.getID()) else: vulnerability.setID(service.getID()) if not models.get_vuln(WORKSPACE, vulnerability.getID()): counter += 1 print "New vulnerability: " + vulnerability.getName() models.create_vuln(WORKSPACE, vulnerability) elif vulnerability_web is not None: vulnerability_web.setID(service.getID()) if not models.get_web_vuln(WORKSPACE, vulnerability_web.getID()): counter += 1 print "New web vulnerability: " + vulnerability_web.getName() models.create_vuln_web(WORKSPACE, vulnerability_web) print "[*]", counter, "new Faraday objects created." file_csv.close() return 0, None
def main(workspace="", args=None, parser=None): WORKSPACE = workspace parser.add_argument("--csv", help="Csv file to import") parsed_args = parser.parse_args(args) if not parsed_args.csv: print "Error: Give a CSV file to import with --csv" return 2, None try: file_csv = open(parsed_args.csv, "r") except: print "Error: Unreadeable CSV file, check the path" raise counter = 0 csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"') for register in csv_reader: host, service, vulnerability, vulnerability_web = parse_register(register) # Set all IDs and create objects if host is not None: old_host = models.get_host(WORKSPACE, ip=host.getName()) if not old_host: counter += 1 print "New host: " + host.getName() models.create_host(WORKSPACE, host) host = models.get_host(WORKSPACE, ip=host.getName()) if service is not None: service.setParent(host.getID()) service_params = { 'name': service.getName(), 'port': service.getPorts()[0], 'protocol': service.getProtocol(), 'host_id': service.getParent() } old_service = models.get_service(WORKSPACE, **service_params) if not old_service: counter += 1 print "New service: " + service.getName() models.create_service(WORKSPACE, service) service = models.get_service(WORKSPACE, **service_params) # Check if Service exist, then create the vuln with parent Service. # If not exist the Service, create the vuln with parent Host. if vulnerability is not None: if host and not service: parent_type = 'Host' parent_id = host.getID() if host and service: parent_type = 'Service' parent_id = service.getID() vulnerability.setParent(parent_id) vulnerability.setParentType(parent_type) vuln_params = { 'name': vulnerability.getName(), 'description': vulnerability.getDescription(), 'parent_type': parent_type, 'parent': parent_id, } if not models.get_vuln(WORKSPACE, **vuln_params): counter += 1 print "New vulnerability: " + vulnerability.getName() models.create_vuln(WORKSPACE, vulnerability) elif vulnerability_web is not None: vuln_web_params = { 'name': vulnerability_web.getName(), 'description': vulnerability_web.getDescription(), 'parent': service.getID(), 'parent_type': 'Service', 'method': vulnerability_web.getMethod(), 'parameter_name': vulnerability_web.getParams(), 'path': vulnerability_web.getPath(), 'website': vulnerability_web.getWebsite(), } vulnerability_web.setParent(service.getID()) if not models.get_web_vuln(WORKSPACE, **vuln_web_params): counter += 1 print "New web vulnerability: " + vulnerability_web.getName() models.create_vuln_web(WORKSPACE, vulnerability_web) print "[*]", counter, "new Faraday objects created." file_csv.close() return 0, None
def main(workspace="", args=None, parser=None): WORKSPACE = workspace parser.add_argument("--csv", help="Csv file to import") parsed_args = parser.parse_args(args) if not parsed_args.csv: print "Error: Give a CSV file to import with --csv" return 2, None try: file_csv = open(parsed_args.csv, "r") except: print "Error: Unreadeable CSV file, check the path" raise counter = 0 csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"') for register in csv_reader: host, interface, service, vulnerability, vulnerability_web = parse_register( register) # Set all IDs and create objects if host is not None: host.setID(None) if not models.get_host(WORKSPACE, host.getID()): counter += 1 print "New host: " + host.getName() models.create_host(WORKSPACE, host) if interface is not None: interface.setID(host.getID()) if not models.get_interface(WORKSPACE, interface.getID()): counter += 1 print "New interface: " + interface.getName() models.create_interface(WORKSPACE, interface) if service is not None: service.setID(interface.getID()) if not models.get_service(WORKSPACE, service.getID()): counter += 1 print "New service: " + service.getName() models.create_service(WORKSPACE, service) # Check if Service exist, then create the vuln with parent Service. # If not exist the Service, create the vuln with parent Host. if vulnerability is not None: if service is None: vulnerability.setID(host.getID()) else: vulnerability.setID(service.getID()) if not models.get_vuln(WORKSPACE, vulnerability.getID()): counter += 1 print "New vulnerability: " + vulnerability.getName() models.create_vuln(WORKSPACE, vulnerability) elif vulnerability_web is not None: vulnerability_web.setID(service.getID()) if not models.get_web_vuln(WORKSPACE, vulnerability_web.getID()): counter += 1 print "New web vulnerability: " + vulnerability_web.getName() models.create_vuln_web(WORKSPACE, vulnerability_web) print "[*]", counter, "new Faraday objects created." file_csv.close() return 0, None
def main(workspace="", args=None, parser=None): WORKSPACE = workspace parser.add_argument("--csv", help="Csv file to import") parsed_args = parser.parse_args(args) if not parsed_args.csv: print "Error: Give a CSV file to import with --csv" return 2, None try: file_csv = open(parsed_args.csv, "r") except: print "Error: Unreadeable CSV file, check the path" raise counter = 0 csv_reader = csv.DictReader(file_csv, delimiter=",", quotechar='"') for register in csv_reader: try: host, service, vulnerability, vulnerability_web = parse_register(register) # Set all IDs and create objects if host is not None: old_host = models.get_host(WORKSPACE, ip=host.getName()) if not old_host: counter += 1 print "New host: " + host.getName() try: models.create_host(WORKSPACE, host) except Exception as ex: import ipdb; ipdb.set_trace() host = models.get_host(WORKSPACE, ip=host.getName()) if service is not None: service.setParent(host.getID()) service_params = { 'name': service.getName(), 'port': service.getPorts()[0], 'protocol': service.getProtocol(), 'host_id': service.getParent() } old_service = models.get_service(WORKSPACE, **service_params) if not old_service: counter += 1 print "New service: " + service.getName() models.create_service(WORKSPACE, service) service = models.get_service(WORKSPACE, **service_params) # Check if Service exist, then create the vuln with parent Service. # If not exist the Service, create the vuln with parent Host. if vulnerability is not None: if host and not service: parent_type = 'Host' parent_id = host.getID() if host and service: parent_type = 'Service' parent_id = service.getID() vulnerability.setParent(parent_id) vulnerability.setParentType(parent_type) vuln_params = { 'name': vulnerability.getName(), 'description': vulnerability.getDescription(), 'parent_type': parent_type, 'parent': parent_id, } if not models.get_vuln(WORKSPACE, **vuln_params): counter += 1 print "New vulnerability: " + vulnerability.getName() models.create_vuln(WORKSPACE, vulnerability) elif vulnerability_web is not None: vuln_web_params = { 'name': vulnerability_web.getName(), 'description': vulnerability_web.getDescription(), 'parent': service.getID(), 'parent_type': 'Service', 'method': vulnerability_web.getMethod(), 'parameter_name': vulnerability_web.getParams(), 'path': vulnerability_web.getPath(), 'website': vulnerability_web.getWebsite(), } vulnerability_web.setParent(service.getID()) if not models.get_web_vuln(WORKSPACE, **vuln_web_params): counter += 1 print "New web vulnerability: " + vulnerability_web.getName() models.create_vuln_web(WORKSPACE, vulnerability_web) except ConflictInDatabase: print('Conflict in Database, skiping csv row') except CantCommunicateWithServerError as ex: print(register) print('Error', ex) print "[*]", counter, "new Faraday objects created." file_csv.close() return 0, None