Ejemplo n.º 1
0
    def change_local_system_ip(self, username: str, old_local_ip: str, new_local_ip: str) -> dict:
        if not self.username_exists(username):
            return {'success': False, 'error': "You are not logged in to access this resource."}
        if not APIUtils.validate('ipaddress', old_local_ip):
            return {'success': False, 'error': "Please provide a valid old Local IP Address."}
        if not APIUtils.validate('ipaddress', new_local_ip):
            return {'success': False, 'error': "Please provide a valid new Local IP Address."}

        # "Warning"? Issue in pylint: https://github.com/MongoEngine/mongoengine/issues/858
        user = User.objects(username=username)[0]
        oldlocalexists = LocalSystem.objects(
            userId=user, localIP=old_local_ip).count() > 0
        newlocalexists = LocalSystem.objects(
            userId=user, localIP=new_local_ip).count() > 0
        if not oldlocalexists:
            return {
                'success': False,
                'error': "A system with this IP does not exists in your IP Pool."
                }
        if newlocalexists:
            return {
                'success': False,
                'error': "A system with this IP is already exists in your IP Pool."
                }
        localsys: LocalSystem = LocalSystem.objects(
            userId=user, localIP=old_local_ip)[0]
        localsys.localIP = new_local_ip
        localsys.save()
        return {'success': True, 'message': "Local System's IP changed successfully!"}
    def remove_local_system(self, username: str, local_ip: str) -> dict:
        if not self.username_exists(username):
            return {
                'success': False,
                'error': "You are not logged in to access this resource."
            }
        if not APIUtils.validate('ipaddress', local_ip):
            return {
                'success': False,
                'error': "Please provide a valid IP Address."
            }

        # "Warning"? Issue in pylint: https://github.com/MongoEngine/mongoengine/issues/858
        user = User.objects(username=username)[0]
        localexists = LocalSystem.objects(userId=user,
                                          localIP=local_ip).count() > 0
        if not localexists:
            return {
                'success': False,
                'error':
                "A system with this IP does not exists in your IP Pool."
            }
        localsys: LocalSystem = LocalSystem.objects(userId=user,
                                                    localIP=local_ip)
        localsys.delete()
        return {
            'success': True,
            'message': "Local System deleted successfully!"
        }
    def add_local_system(self, username: str, local_ip: str) -> dict:
        if not self.username_exists(username):
            return {
                'success': False,
                'error': "You are not logged in to access this resource."
            }
        if not APIUtils.validate('ipaddress', local_ip):
            return {
                'success': False,
                'error': "Please provide a valid IP Address."
            }

        # "Warning"? Issue in pylint: https://github.com/MongoEngine/mongoengine/issues/858
        user = User.objects(username=username)[0]
        localexists = LocalSystem.objects(userId=user,
                                          localIP=local_ip).count() > 0
        if localexists:
            return {
                'success': False,
                'error':
                "A system with this IP is already added to your IP Pool."
            }
        localsys = LocalSystem()
        localsys.userId = user
        localsys.localIP = local_ip
        localsys.os = "Unknown"
        localsys.openPorts = {}
        localsys.systemUp = False
        localsys.save()

        return {'success': True, 'message': "Local System added successfully!"}
Ejemplo n.º 4
0
 def change_agent_ip(self, username: str, ipaddr: str) -> dict:
     if not self.username_exists(username):
         return {"success": False, "error": "Username does not exist!"}
     if (ipaddr is not None) and not APIUtils.validate("ipaddress", ipaddr):
         return {"success": False, "error": "IP Address is invalid! Please provide a valid IPv4 Address."}
     # "Warning"? Issue in pylint: https://github.com/MongoEngine/mongoengine/issues/858
     user: User = User.objects(username=username)[0]
     user.publicIP = ipaddr
     ipverify = str(uuid4())
     user.publicIPVerifier = ipverify
     user.verifiedPublicIP = True
     user.save()
     return {
         "success": True,
         "message": "Please verify IP Ownership by creating a file named the given code in root of web server of that IP Address.",
         "code": ipverify}