Пример #1
0
        def post(self,
                 instance_id,
                 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.
                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)
            logger.info(
                f"Send POST request, URL: {execute_exploit_url}, REQUEST: {execute_exploit_body_request}"
            )

            return execute_rest_api_func(
                url=execute_exploit_url,
                api_func=self._test_client.post,
                request_body=execute_exploit_body_request)
Пример #2
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[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_func(url=get_all_users_url, api_func=self._test_client.get)
Пример #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_func(url=get_all_docker_servers_url,
                                         api_func=self._test_client.get)
Пример #4
0
        def delete(self, username, delete_user_url=config.DELETE_USER_URL):
            """
            Sends a DELETE request in order to delete a user.

            Args:
                username (str): user name.
                delete_user_url (str): the URL to delete a user.

            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(username=username)
            logger.info(f"Send DELETE request, URL: {delete_user_url}")

            return execute_rest_api_func(url=delete_user_url, api_func=self._test_client.delete)
Пример #5
0
        def get_one(self, username, password, get_user_url=config.GET_USER_URL):
            """
            Sends a GET request in order to get a user.

            Args:
                username (str): user name.
                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(username=username, password=password)
            logger.info(f"Send GET request, URL: {get_user_url}")

            return execute_rest_api_func(url=get_user_url, api_func=self._test_client.get)
Пример #6
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_func(
                url=create_user_url, api_func=self._test_client.post, request_body=create_user_body_request
            )
Пример #7
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_func(url=get_docker_server_url,
                                         api_func=self._test_client.get)
Пример #8
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_func(url=get_all_containers_url,
                                         api_func=self._test_client.get)
Пример #9
0
        def delete(self, instance_id, container_id):
            """
            Sends a DELETE request to delete a single container.

            Args:
                instance_id (str): instance ID
                container_id (str): container ID.

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

            return execute_rest_api_func(url=delete_container_url,
                                         api_func=self._test_client.delete,
                                         convert_func=to_utf8)
Пример #10
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_func(url=create_msfrpcd_container_url,
                                         api_func=self._test_client.post)
Пример #11
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_func(url=get_payload_url,
                                         api_func=self._test_client.get)
Пример #12
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_func(url=scan_ports_url,
                                         api_func=self._test_client.get)