Пример #1
0
        def put(self,
                email,
                request_body,
                update_user_url=config.UPDATE_USER_URL,
                expected_to_fail=False):
            """
            Sends a PUT request in order to update a user.

            Args:
                email (str): user email.
                request_body (dict): request body to update a user.
                update_user_url (str): the URL to update a user.
                expected_to_fail (bool): is the put operation expect to give an error from the API.

            Returns:
                tuple[str, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            update_user_url = update_user_url.format(email=email)
            logger.info(f"Send PUT request, URL: {update_user_url}")

            convert_func = convert if expected_to_fail else to_utf8

            return execute_rest_api_request(url=update_user_url,
                                            api_func=self._test_client.put,
                                            request_body=request_body,
                                            convert_func=convert_func)
Пример #2
0
        def run_exploit(self,
                        instance_id,
                        target,
                        execute_exploit_body_request,
                        execute_exploit_url=config.EXECUTE_EXPLOIT_URL):
            """
            Sends a POST request in order to run an exploit.

            Args:
                instance_id (str): instance ID.
                target (str): target IP/DNS.
                execute_exploit_body_request (dict): a body request to run an exploit.
                execute_exploit_url (str): the url to run the exploit.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            execute_exploit_url = execute_exploit_url.format(
                instance_id=instance_id, target=target)
            logger.info(
                f"Send POST request, URL: {execute_exploit_url}, REQUEST: {execute_exploit_body_request}"
            )

            return execute_rest_api_request(
                url=execute_exploit_url,
                api_func=self._test_client.post,
                request_body=execute_exploit_body_request)
Пример #3
0
        def get_many(self):
            """
            Sends a GET request to retrieve all the docker server instances available.

            Returns:
                tuple[list[dict], int]: a tuple containing the body response as a first arg,
                    and status code as second arg.
            """
            get_all_docker_servers_url = config.GET_ALL_DOCKER_SERVERS_URL
            logger.info(f"Send GET request, URL: {get_all_docker_servers_url}")

            return execute_rest_api_request(url=get_all_docker_servers_url,
                                            api_func=self._test_client.get)
Пример #4
0
        def get_many(self, get_all_users_url=config.GET_ALL_USERS_URL):
            """
            Sends a GET request in order to get all the users.

            Args:
                get_all_users_url (str): the URL to get all the users.

            Returns:
                tuple[list[dict], int]: a tuple containing the body response as a first arg,
                and status code as second arg.
            """
            logger.info(f"Send GET request, URL: {get_all_users_url}")

            return execute_rest_api_request(url=get_all_users_url,
                                            api_func=self._test_client.get)
Пример #5
0
        def get_one(self, instance_id):
            """
            Sends a GET request to retrieve a docker server instance.

            Args:
                instance_id (str): instance ID.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            get_docker_server_url = config.GET_DOCKER_SERVER_URL.format(
                instance_id=instance_id)
            logger.info(f"Send GET request, URL: {get_docker_server_url}")

            return execute_rest_api_request(url=get_docker_server_url,
                                            api_func=self._test_client.get)
Пример #6
0
        def get_one(self, email, password, get_user_url=config.GET_USER_URL):
            """
            Sends a GET request in order to get a user.

            Args:
                email (str): user email.
                password (str): user password.
                get_user_url (str): the URL to get the user.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            get_user_url = get_user_url.format(email=email, password=password)
            logger.info(f"Send GET request, URL: {get_user_url}")

            return execute_rest_api_request(url=get_user_url,
                                            api_func=self._test_client.get)
Пример #7
0
        def get_many(self, instance_id):
            """
            Sends a GET request to retrieve all the containers available.

            Args:
                instance_id (str): instance ID.

            Returns:
                tuple[list[dict], int]: a tuple containing the body response as a first arg,
                    and status code as second arg.
            """
            get_all_containers_url = config.GET_CONTAINERS_URL.format(
                instance_id=instance_id)
            logger.info(f"Send GET request, URL: {get_all_containers_url}")

            return execute_rest_api_request(url=get_all_containers_url,
                                            api_func=self._test_client.get)
Пример #8
0
        def get_payload(self,
                        instance_id,
                        payload_name,
                        get_payload_url=config.GET_PAYLOAD_URL):
            """
            Sends a GET request in order to get payload information from metasploit.

            Args:
                instance_id (str): instance ID.
                payload_name (str): payload name.
                get_payload_url (str): get payload information url.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            get_payload_url = get_payload_url.format(instance_id=instance_id,
                                                     payload_name=payload_name)
            logger.info(f"Send GET request, URL: {get_payload_url}")

            return execute_rest_api_request(url=get_payload_url,
                                            api_func=self._test_client.get)
Пример #9
0
        def scan_ports(self,
                       instance_id,
                       target_host,
                       scan_ports_url=config.SCAN_PORTS_URL):
            """
            Sends a GET request in order to scan ports on a remote host.

            Args:
                instance_id (str): instance ID.
                target_host (str): target host remote IP/DNS.
                scan_ports_url (str): scan ports url.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            scan_ports_url = scan_ports_url.format(instance_id=instance_id,
                                                   target_host=target_host)
            logger.info(f"Send GET request, URL: {scan_ports_url}")

            return execute_rest_api_request(url=scan_ports_url,
                                            api_func=self._test_client.get)
Пример #10
0
        def post(self,
                 create_user_body_request,
                 create_user_url=config.CREATE_USER_URL):
            """
            Sends a POST request in order to create a user.

            Args:
                create_user_body_request (dict): a body request to create a new user.
                create_user_url (str): the URL to create the user.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            logger.info(
                f"Send POST request, URL: {create_user_url}, REQUEST: {create_user_body_request}"
            )

            return execute_rest_api_request(
                url=create_user_url,
                api_func=self._test_client.post,
                request_body=create_user_body_request)
Пример #11
0
        def delete(self, instance_id, expected_to_fail=False):
            """
            Sends a DELETE request to delete a docker server instance.

            Args:
                instance_id (str): instance ID.
                expected_to_fail (bool): True if deleting the instance expects to fail.

            Returns:
                tuple[str, int]: a tuple containing the body response as first arg, and status code as second arg.
            """
            delete_docker_server_url = config.DELETE_DOCKER_SERVER_URL.format(
                instance_id=instance_id)
            logger.info(
                f"Send DELETE request, URL: {delete_docker_server_url}")

            convert_func = convert if expected_to_fail else to_utf8

            return execute_rest_api_request(url=delete_docker_server_url,
                                            api_func=self._test_client.delete,
                                            convert_func=convert_func)
Пример #12
0
        def post(self,
                 instance_id,
                 create_msfrpcd_container_url=config.
                 CREATE_MSFRPCD_CONTAINER_URL):
            """
            Sends a POST request in order to create a metasploit based image container.

            Args:
                instance_id (str): instance ID that the container will be created on.
                create_msfrpcd_container_url (str): URL for the POST request to create the container.

            Returns:
                tuple[dict, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            create_msfrpcd_container_url = create_msfrpcd_container_url.format(
                instance_id=instance_id)
            logger.info(
                f"Send POST request, URL: {create_msfrpcd_container_url}")

            return execute_rest_api_request(url=create_msfrpcd_container_url,
                                            api_func=self._test_client.post)
Пример #13
0
        def delete(self,
                   email,
                   delete_user_url=config.DELETE_USER_URL,
                   expected_to_fail=False):
            """
            Sends a DELETE request in order to delete a user.

            Args:
                email (str): user email.
                delete_user_url (str): the URL to delete a user.
                expected_to_fail (bool): is the delete operation expect to give an error from the API.

            Returns:
                tuple[str, int]: a tuple containing the body response as a first arg, and status code as second arg.
            """
            delete_user_url = delete_user_url.format(email=email)
            logger.info(f"Send DELETE request, URL: {delete_user_url}")

            convert_func = convert if expected_to_fail else to_utf8

            return execute_rest_api_request(url=delete_user_url,
                                            api_func=self._test_client.delete,
                                            convert_func=convert_func)