def create_user(self, access_req): try: # Create User create_user_URL = self.nessus_host + "/users" usrLst = access_req['userList'] for user in usrLst: userinfo = user.split(',') # uname,name,email pswd = Utilities.gen_code() payload = {'username': userinfo[0], 'password': pswd, 'permissions': '32', 'name': userinfo[1], 'email': userinfo[2], 'type': 'local'} response = self.makeRequest(create_user_URL, json.dumps(payload), self.headers) json_rep = json.loads(response.decode("utf-8")) # print(json_rep) if self.status_code == 200: Utilities.printSuccess("Created user: "******"Nessus\nUsername:"******"\nPassword:"******"User creation Failure: Invalid field request") return False if self.status_code == 403: Utilities.printError("User creation Failure: No permission to create a user") return False if self.status_code == 409: Utilities.printError("User creation Failure: Duplicate username") return False except Exception as e: Utilities.printException(str(e))
def addUser(self, access_req): # print("addUser Module") usrLst = access_req['userList'] for user in usrLst: usrSaveRequest = Element('UserSaveRequest', attrib={'session-id': self.session_id}) userinfo = user.split(',') # uname,name,email pswd = Utilities.gen_code() usrConfig_elem = SubElement(usrSaveRequest, 'UserConfig', attrib={'id': '-1', 'role-name': 'user', 'authsrcid': '-1', 'enabled': '1', 'name': userinfo[0], 'fullname': userinfo[1], 'email': userinfo[2], 'password': pswd}) sites_elem = SubElement(usrConfig_elem, 'UserSite') site_elem = SubElement(sites_elem, 'site', attrib={'id': self.site_id}) site_elem.text = access_req['site_name'] xmlTree = ElementTree(usrSaveRequest) f = BytesIO() xmlTree.write(f, encoding='utf-8', xml_declaration=True) # required so that xml declarations will come up in generated XML usrSaveReqXML = f.getvalue().decode("utf-8") # converts bytes to string # print(usrSaveReqXML) responseXML = self.makeRequest(self.reqURL, usrSaveReqXML, self.headers) # print(responseXML) tree = ElementTree(fromstring(responseXML)) root = tree.getroot() addUserReq = root.get('success') if (addUserReq == "1"): Utilities.printSuccess("Created user: "******"Nexpose\nUsername:"******"\nPassword:"******"User creation failed: " + msg) return False
def addUser(self, access_req): # print("addUser Module") usrLst = access_req['userList'] for user in usrLst: usrSaveRequest = Element('UserSaveRequest', attrib={'session-id': self.session_id}) userinfo = user.split(',') # uname,name,email pswd = Utilities.gen_code() usrConfig_elem = SubElement(usrSaveRequest, 'UserConfig', attrib={ 'id': '-1', 'role-name': 'user', 'authsrcid': '-1', 'enabled': '1', 'name': userinfo[0], 'fullname': userinfo[1], 'email': userinfo[2], 'password': pswd }) sites_elem = SubElement(usrConfig_elem, 'UserSite') site_elem = SubElement(sites_elem, 'site', attrib={'id': self.site_id}) site_elem.text = access_req['site_name'] xmlTree = ElementTree(usrSaveRequest) f = BytesIO() xmlTree.write( f, encoding='utf-8', xml_declaration=True ) # required so that xml declarations will come up in generated XML usrSaveReqXML = f.getvalue().decode( "utf-8") # converts bytes to string # print(usrSaveReqXML) responseXML = self.makeRequest(self.reqURL, usrSaveReqXML, self.headers) # print(responseXML) tree = ElementTree(fromstring(responseXML)) root = tree.getroot() addUserReq = root.get('success') if (addUserReq == "1"): Utilities.printSuccess("Created user: "******"Nexpose\nUsername:"******"\nPassword:"******"User creation failed: " + msg) return False
def create_user(self, access_req): try: # Create User create_user_URL = self.nessus_host + "/users" usrLst = access_req['userList'] for user in usrLst: userinfo = user.split(',') # uname,name,email pswd = Utilities.gen_code() payload = { 'username': userinfo[0], 'password': pswd, 'permissions': '32', 'name': userinfo[1], 'email': userinfo[2], 'type': 'local' } response = self.makeRequest(create_user_URL, json.dumps(payload), self.headers) json_rep = json.loads(response.decode("utf-8")) # print(json_rep) if self.status_code == 200: Utilities.printSuccess("Created user: "******"Nessus\nUsername:"******"\nPassword:"******"User creation Failure: Invalid field request") return False if self.status_code == 403: Utilities.printError( "User creation Failure: No permission to create a user" ) return False if self.status_code == 409: Utilities.printError( "User creation Failure: Duplicate username") return False except Exception as e: Utilities.printException(str(e))