def main(workspace='', args=None, parser=None): parser.add_argument('-y', '--yes', action="store_true") parsed_args = parser.parse_args(args) try: vulns = models.get_all_vulns(workspace) except ResourceDoesNotExist: print ("Invalid workspace name: ", workspace) return 1, None if not parsed_args.yes: if not query_yes_no("Are you sure you want to change the status to closed of all the vulns in workspace %s" % workspace, default='no'): return 1, None count = 0 for vuln in vulns: old_status = vuln.status # Valid status if vuln.status != "closed": vuln.status = "closed" count += 1 if vuln.class_signature == "Vulnerability": models.update_vuln(workspace, vuln) elif vuln.class_signature == "VulnerabilityWeb": models.update_vuln_web(workspace, vuln) print (vuln.name, ": Status changed from", old_status,"to closed successfully") print ("End of process:", count, "vulnerabilities changed to closed") return 0, None
def update_vulnerability(ws, vuln, key, value, _server): if key == 'template': cwe = get_cwe(value, _server) if cwe is None: logger.error("%s: cwe not found" % value) return False vuln.name = cwe['name'] vuln.description = cwe['description'] vuln.desc = cwe['description'] vuln.resolution = cwe['resolution'] logger.info("Applying template '%s' to vulnerability '%s' with id '%s'" % (value, vuln.name, vuln.id)) elif key == 'confirmed': value = value == 'True' vuln.confirmed = value logger.info("Changing property %s to %s in vulnerability '%s' with id %s" % (key, value, vuln.name, vuln.id)) elif key == 'owned': value = value == 'True' vuln.owned = value logger.info("Changing property %s to %s in vulnerability '%s' with id %s" % (key, value, vuln.name, vuln.id)) else: to_add = True if key.startswith('-'): key = key.strip('-') to_add = False field = get_field(vuln, key) if field is not None: if isinstance(field, str) or isinstance(field, unicode): setattr(vuln, key, value) logger.info( "Changing property %s to %s in vulnerability '%s' with id %s" % (key, value, vuln.name, vuln.id)) else: set_array(field, value, add=to_add) action = 'Adding %s to %s list in vulnerability %s with id %s' % (value, key, vuln.name, vuln.id) if not to_add: action = 'Removing %s from %s list in vulnerability %s with id %s' % ( value, key, vuln.name, vuln.id) logger.info(action) try: if vuln.class_signature == "Vulnerability": models.update_vuln(ws, vuln) elif vuln.class_signature == "VulnerabilityWeb": models.update_vuln_web(ws, vuln) except ConflictInDatabase: logger.error("There was a conflict trying to save '%s' with ID: %s" % (vuln.name, vuln.id)) return False except Exception as error: logger.error(error) return False logger.info("Done") return True
def main(workspace='', args=None, parser=None): parser.add_argument('-y', '--yes', action="store_true") parsed_args = parser.parse_args(args) try: vulns = models.get_all_vulns(workspace) except ResourceDoesNotExist: print("Invalid workspace name: ", workspace) return 1, None if not parsed_args.yes: if not query_yes_no( "Are you sure you want to change the status to closed of all the vulns in workspace %s" % workspace, default='no'): return 1, None count = 0 for vuln in vulns: old_status = vuln.status # Valid status if vuln.status != "closed": vuln.status = "closed" count += 1 if vuln.class_signature == "Vulnerability": models.update_vuln(workspace, vuln) elif vuln.class_signature == "VulnerabilityWeb": models.update_vuln_web(workspace, vuln) print(vuln.name, ": Status changed from", old_status, "to closed successfully") print("End of process:", count, "vulnerabilities changed to closed") return 0, None
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 test_persistence_server_update_vuln(self, getInstanceConfigurationMock): fo = self.first_object conf_mock = Mock() getInstanceConfigurationMock.return_value = conf_mock port = 5985 conf_mock.getDBSessionCookies.return_value = None conf_mock.getAPIUrl.return_value = 'http://localhost:{0}'.format(port) conf_mock.getServerURI.return_value = 'http://localhost:{0}'.format(port) conf_mock.getAPIUsername.return_value = 'faraday' conf_mock.getAPIPassword.return_value = 'mocked_password' vuln = {'desc': fo.description, 'data': fo.data, 'severity': fo.severity, 'refs': list(fo.references), 'confirmed': fo.confirmed, 'resolution': fo.resolution, 'status': fo.status, 'policyviolations': list(fo.policy_violations)} v = models.Vuln(vuln, self.workspace.name) v.id = fo.id resp = {u'status': u'closed', u'_rev': u'', u'parent_type': v.getParentType(), u'owned': v.isOwned(), u'owner': v.getParent(), u'query': u'', u'refs': v.getRefs(), u'impact': {u'integrity': False, u'confidentiality': False, u'availability': False, u'accountability': False}, u'confirmed': v.getConfirmed(), u'severity': v.getSeverity(), u'service': None, u'policyviolations': v.getPolicyViolations(), u'params': u'', u'type': u'Vulnerability', u'method': u'', u'metadata': {u'update_time': u'2018-05-23T17:03:27.880196+00:00', u'update_user': u'<User: faraday>', u'update_action': 0, u'creator': u'Nmap', u'create_time': u'2018-05-18T16:30:26.011851+00:00', u'update_controller_action': u'', u'owner': u'faraday', u'command_id': 22}, u'website': u'', u'issuetracker': {}, u'description': v.getDesc(), u'tags': [], u'easeofresolution': None, u'hostnames': [], u'pname': u'', u'date': u'2018-05-18T16:30:26.011851+00:00', u'path': u'', u'data': v.getData(), u'response': u'', u'desc': v.getDesc(), u'name': v.getName(), u'obj_id': str(v.getID()), u'request': u'', u'_attachments': {}, u'target': u'192.168.10.103', u'_id': v.getID(), u'resolution': v.getResolution() } responses.add(responses.PUT, 'http://localhost:{0}/_api/v2/ws/{1}/vulns/{2}/'.format(port,self.workspace.name, v.id), json=resp, status=200) a = requests.put('http://localhost:{0}/_api/v2/ws/{1}/vulns/{2}/'.format(port,self.workspace.name, v.id)) models.update_vuln(self.workspace.name, v)