CarbonBlackLiveResponseCloud

VMware Carbon Black Endpoint Standard Live Response is a feature that enables security operators to collect information and take action on remote endpoints in real time. These actions include the ability to upload, download, and remove files, retrieve and remove registry entries, dump contents of physical memory, and execute and terminate processes.

Endpoint · Carbon Black Endpoint Standard

Details

IDCarbonBlackLiveResponseCloud
ProviderBroadcom
CategoryEndpoint
From Version5.5.0
Docker Imagedemisto/carbon-black-cloud:1.0.0.10120494
Supported ModulesAgentix XSIAM

README

Enables security operators to collect information and take action on remote endpoints in real time. These actions include the ability to upload, download, and remove files, retrieve and remove registry entries, dump contents of physical memory, and execute and terminate processes.

Configure CarbonBlackLiveResponseCloud on Cortex XSOAR

Creating an API Key

  1. To create an API Key, go to Settings > API Access > API Keys tab in the Carbon Black Cloud web page.
  2. Select Add API Key from the far right.
  3. Give the API Key a unique name, and select the Live Response access level.
  4. Click Save. You will be provided with your API Key Credentials:
  • API Secret Key
  • API ID
  1. Go to Settings > API Access and copy the ORG KEY from the top left corner of the page.
  2. Set up Carbon Black Cloud Live Response integration instance with the ORG KEY and created API Secret Key and API ID.

Getting the device ID

You can access the device ID in one of the following ways.

  • In Cortex XSOAR:
    1. Create an instance of the Carbon Black Defense integration.
    2. Run the cbd-device-search command.
    3. Locate the ID according to its name.
  • From the Carbon Black Cloud web page:
    1. Click Endpoints.
    2. Search for and click the device name. The device ID will appear at the top of the page in the format device:<the device ID>.

Set up integration instance

  1. Navigate to Settings > Integrations > Servers & Services.
  2. Search for CarbonBlackLiveResponseCloud.
  3. Click Add instance to create and configure a new integration instance.

    Parameter Description Required
    Your server URL The URL used to access the Carbon Black Cloud. True
    Custom Key The custom key to use for the connection. True
    Custom Id The custom ID to use for the connection. True
    Organization Key The organization key to use for the connection. True
    Trust any certificate (not secure)   False
    Use system proxy settings   False
  4. Click Test to validate the URLs, token, and connection.

Commands

You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

cbd-lr-file-put


Creates a new file on the remote machine with the specified data.

Base Command

cbd-lr-file-put

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
destination_path File path to create on the remote endpoint. Required
file_id The file entry ID in the War Room. Required

Context Output

There is no context output for this command.

Command Example

!cbd-lr-file-put device_id="1234567" destination_path="C:\test\test.txt" file_id=142@5

Human Readable Output

File: 142@5 is successfully put to the remote destination C:\test\test_file.txt

cbd-lr-file-get


Retrieves the contents of the specified file on the remote machine.

Base Command

cbd-lr-file-get

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
source_path Path of the file to be retrieved. Required
timeout Timeout for the operation. Optional
delay The amount of time in seconds to wait before a command complete. Optional

Context Output

{
    "File": {
        "EntryID": "260@3c9bd2a0-9eac-465b-8799-459df4997b2d",
        "Extension": "txt",
        "Info": "text/plain; charset=utf-8",
        "MD5": "db7375b2e67da548049e0a5e500b41eb",
        "Name": "test_file.txt",
        "SHA1": "36017cdf63594765ea755c65765702522ca2031c",
        "SHA256": "9dc4d8e2cf56b9d8ec0a074151eb2a97fff3f2d633ccc166d9f8fa3e489fac8a",
        "SHA512": "6b2390577ca26841d66aa9d9a3faadbb9921fefef49d9eae4f68851014e780578eb17d6443415ea1e592572701e42aac4141e09334a425c8bc6a1f5792a98c4f",
        "SSDeep": "3:H0sKFQO:HKSO",
        "Size": 17,
        "Type": "ASCII text, with no line terminators"
    }
}

Command Example

!cbd-lr-file-get device_id="the actually device ID" source_path="C:\\test\\test_file.txt" delay=2 timeout=30

Human Readable Output

cbd-lr-file-delete


Deletes the specified file name on the remote machine.

Base Command

cbd-lr-file-delete

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
source_path Path of the file to be deleted. Required

Context Output

There is no context output for this command.

Command Example

!cbd-lr-file-delete device_id="the actually device ID" source_path="C:\test\test_file.txt"

Human Readable Output

The file: C:\test\test_file.txt was deleted successfully.

cbd-lr-directory-listing


Lists the contents of a directory on the remote machine.

Base Command

cbd-lr-directory-listing

Input

Argument Name Description Required      
device_id The device (endpoint) ID. Required      
directory_path The directory path. This parameter should end with the path separator or have some filter pattern, e.g., *.txt. Required limit The maximum number of returned directory entries. Default is 100. Optional

Context Output

Path Type Description
CarbonBlackDefenseLR.Directory.content Data List of dicts, each describing a directory entry.
CarbonBlackDefenseLR.Directory.device_id String The device (endpoint) ID
CarbonBlackDefenseLR.Directory.directory_path String The path of the listed directory.

Command Example

!cbd-lr-directory-listing device_id="the actually device ID" directory_path="C:\test\"

Context Example

{
    "CarbonBlackDefenseLR": {
        "Directory": {
            "content": [
                {
                    "alternate_name": "",
                    "attributes": [
                        "DIRECTORY"
                    ],
                    "create_time": 1616331959,
                    "filename": ".",
                    "last_access_time": 1619593780,
                    "last_write_time": 1619593761,
                    "size": 0
                },
                {
                    "alternate_name": "",
                    "attributes": [
                        "DIRECTORY"
                    ],
                    "create_time": 1616331959,
                    "filename": "..",
                    "last_access_time": 1619593780,
                    "last_write_time": 1619593761,
                    "size": 0
                },
                {
                    "alternate_name": "A_TEST~1.EXE",
                    "attributes": [
                        "ARCHIVE"
                    ],
                    "create_time": 1619532122,
                    "filename": "a_test_process.exe",
                    "last_access_time": 1619532122,
                    "last_write_time": 1618464943,
                    "size": 839112
                },
                {
                    "alternate_name": "MEMDUM~1",
                    "attributes": [
                        "DIRECTORY"
                    ],
                    "create_time": 1618324107,
                    "filename": "memdump_test",
                    "last_access_time": 1619532952,
                    "last_write_time": 1619532951,
                    "size": 0
                }
            ],
            "device_id": "the actually device ID"
        }
    }
}

Human Readable Output

Carbon Black Defense Live Response Directory content

Name Type Date Modified Size
. Directory 1970-01-19T17:53:20.000Z 0
.. Directory 1970-01-19T17:53:20.000Z 0
a_test_process.exe File 1970-01-19T17:34:24.000Z 839112
memdump_test Directory 1970-01-19T17:52:12.000Z 0

cbd-lr-reg-sub-keys


Enumerates the subkeys of the specified registry key on the remote machine.

Base Command

cbd-lr-reg-sub-keys

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
reg_path The registry key to enumerate. Required

Context Output

Path Type Description
CarbonBlackDefenseLR.RegistrySubKeys.key String The parent registry key.
CarbonBlackDefenseLR.RegistrySubKeys.sub_keys Data The subkeys.
CarbonBlackDefenseLR.RegistrySubKeys.device_id String The device (endpoint) ID.

Command Example

!cbd-lr-reg-sub-keys reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\TEST device_id="the actually device ID"

Human Readable Output

The key: HKEY_LOCAL_MACHINE\SOFTWARE\TEST does not contain any sub keys

cbd-lr-reg-get-values


Enumerates all registry values from the specified registry key on the remote machine.

Base Command

cbd-lr-reg-get-values

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
reg_path The registry key to enumerate. Required

Context Output

Path Type Description
CarbonBlackDefenseLR.RegistryValues.key String The registry key.
CarbonBlackDefenseLR.RegistryValues.values Data The registry values of the given key.
CarbonBlackDefenseLR.RegistryValues.device_id String The device (endpoint) ID.

Command Example

!cbd-lr-reg-get-values reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\TEST device_id="the actually device ID"

Context Example

{
    "CarbonBlackDefenseLR": {
        "RegistryValues": {
            "key": "HKEY_LOCAL_MACHINE\SOFTWARE\TEST",
            "device_id": "the actually device ID",
            "values": [
                {
                    "value_data": "val_1,val_2",
                    "value_name": "TEST_VAL",
                    "value_type": "pbREG_MULTI_SZ"
                }
            ]
        }
    }
}

Human Readable Output

Carbon Black Defense Live Response Registry key values

Name Type Data
TEST_VAL pbREG_MULTI_SZ val_1,val_2

cbd-lr-reg-key-create


Creates a new registry key on the remote machine.

Base Command

cbd-lr-reg-key-create

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
reg_path The registry key to create. Required

Context Output

There is no context output for this command.

Command Example

!cbd-lr-reg-key-create device_id="the actually device ID" reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\TEST

Human Readable Output

Reg key: HKEY_LOCAL_MACHINE\SOFTWARE\TEST, was created successfully.

cbd-lr-reg-key-delete


Deletes a registry key on the remote machine. The key must be without any subkeys.

Base Command

cbd-lr-reg-key-delete

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
reg_path The registry key to delete. Required
force True, to force delete the registry key with all subkeys if they exist. Default is False. Optional

Context Output

There is no context output for this command.

Command Example

!cbd-lr-reg-key-delete reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\TEST device_id="the actually device ID"

Human Readable Output

Registry key: HKEY_LOCAL_MACHINE\SOFTWARE\TEST was deleted successfully.

cbd-lr-reg-value-delete


Deletes a registry value on the remote machine.

Base Command

cbd-lr-reg-value-delete

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
reg_path The registry value to delete. Required

Context Output

There is no context output for this command.

Command Example

!cbd-lr-reg-value-delete device_id="the actually device ID" reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\TEST\TEST_VAL

Human Readable Output

Registry value: HKEY_LOCAL_MACHINE\SOFTWARE\TEST\TEST_VAL was deleted successfully.

cbd-lr-reg-value-set


Sets a registry value on the specified registry key on the remote machine.

Base Command

cbd-lr-reg-value-set

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
reg_path The path of the key + the path of the value e.g., HKLM\SYSTEM\CurrentControlSet\services\ACPI\testvalue. Required
value_data The value data. Required
value_type The type of value. Examples: REG_DWORD, REG_MULTI_SZ, REG_SZ. Possible values are: REG_BINARY, REG_DWORD, REG_QWORD, REG_EXPAND_SZ, REG_MULTI_SZ, REG_SZ, REG_SZ. Required
overwrite If True, any existing value will be overwritten. Default is True. Optional

Context Output

There is no context output for this command.

Command Example

!cbd-lr-reg-value-set reg_path=HKEY_LOCAL_MACHINE\SOFTWARE\TEST\TEST_VAL device_id="the actually device ID" value_data=[\"val_1\",\"val_2\"] value_type=REG_MULTI_SZ

Human Readable Output

Value was set to the reg key: HKEY_LOCAL_MACHINE\SOFTWARE\TEST\TEST_VAL successfully.

cbd-lr-ps


Lists the currently running processes on the remote machine.

Base Command

cbd-lr-ps

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
limit The maximum number of returned processes. Default is 100. Optional

Context Output

Path Type Description
CarbonBlackDefenseLR.Processes.processes String A list of dicts describing the processes
CarbonBlackDefenseLR.Processes.device_id String The device (endpoint) ID

Command Example

!cbd-lr-ps device_id="the actually device ID"

Context Example

{
    "CarbonBlackDefenseLR": {
        "Processes": {
            "processes": [
                {
                    "command_line": "",
                    "create_time": 132629811990478,
                    "parent": 0,
                    "parent_create_time": 0,
                    "path": "SYSTEM",
                    "pid": 4,
                    "sid": "S-1-5-18",
                    "username": "NT AUTHORITY\SYSTEM"
                },
                {
                    "command_line": "",
                    "create_time": 132629811918118,
                    "parent": 4,
                    "parent_create_time": 132629811990478850,
                    "path": "Registry",
                    "pid": 84,
                    "sid": "S-1-5-18",
                    "username": "NT AUTHORITY\SYSTEM"
                },
                {
                    "command_line": "\SystemRoot\System32\smss.exe",
                    "create_time": 132629811991336,
                    "parent": 4,
                    "parent_create_time": 132629811990478850,
                    "path": "c:\windows\system32\smss.exe",
                    "pid": 308,
                    "sid": "S-1-5-18",
                    "username": "NT AUTHORITY\SYSTEM"
                }
            ],
            "device_id": "the actually device ID"
        }
    }
}

Human Readable Output

Carbon Black Defense Live Response Processes

Path Pid Command Line
SYSTEM 4  
Registry 84  
c:\windows\system32\smss.exe 308 \SystemRoot\System32\smss.exe
c:\windows\system32\wininit.exe 504 wininit.exe

cbd-lr-kill


Terminates a process on the remote machine

Base Command

cbd-lr-kill

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
pid Process ID to be terminated. Required

Context Output

There is no context output for this command.

Command Example

!cbd-lr-kill pid=4592 device_id="the actually device ID"

Human Readable Output

The process: 4592 was killed successfully.

cbd-lr-execute


Creates a new process on the remote machine with the specified command string

Base Command

cbd-lr-execute

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
command_string Command string used for the create process operation. Required
wait_for_output True to block on output from the new process (execute in foreground). This will also set the wait_for_completion command. Default is True. Optional
working_directory The working directory of the create process operation. Optional
remote_output_file_name The remote output file name used for the process output. Optional
wait_timeout Timeout used for this command. Default is 30. Optional
wait_for_completion True to wait until the process is completed before returning. Default is True. Optional

Context Output

Path Type Description
CarbonBlackDefenseLR.ExecuteProcess.return_value String The output of the process
CarbonBlackDefenseLR.ExecuteProcess.device_id String The device (endpoint) ID.
CarbonBlackDefenseLR.ExecuteProcess.command_string String The command string used for the create process operation

Command Example

!cbd-lr-execute device_id="the actually device ID" command_string="cmd.exe"

Human Readable Output

Microsoft Windows [Version 10.0.17763.1935]
© 2018 Microsoft Corporation. All rights reserved.
C:\Windows\system32>

cbd-lr-memdump


Performs a memory dump operation on the remote machine.

Base Command

cbd-lr-memdump

Input

Argument Name Description Required
device_id The device (endpoint) ID. Required
target_path Path of the file the memory dump will be stored in on the remote machine. Required

Context Output

There is no context output for this command.

Command Example

!cbd-lr-memdump device_id="the actually device ID" target_path=C:\test\memdump\dumped_file

Human Readable Output

Memory was successfully dumped to C:\test\memdump\dumped_file.

Configuration parameters

  • url — Server URL
  • custom_key — Custom Key
  • custom_id — Custom ID
  • credentials_custom_id — Custom ID
  • org_key — Organization Key
  • credentials_org_key
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (14)

  • cbd-lr-directory-listing

    Lists the contents of a directory on the remote machine.

  • cbd-lr-execute

    Creates a new process on the remote machine with the specified command string.

  • cbd-lr-file-delete

    Deletes the specified file name on the remote machine.

  • cbd-lr-file-get

    Retrieves the contents of the specified file on the remote machine.

  • cbd-lr-file-put

    Creates a new file on the remote machine with the specified data.

  • cbd-lr-kill

    Terminates a process on the remote machine.

  • cbd-lr-memdump

    Performs a memory dump operation on the remote machine.

  • cbd-lr-ps

    Lists the currently running processes on the remote machine.

  • cbd-lr-reg-get-values

    Enumerates all registry values from the specified registry key on the remote machine. Due to API limitations, binary values will not be shown.

  • cbd-lr-reg-key-create

    Creates a new registry key on the remote machine.

  • cbd-lr-reg-key-delete

    Deletes a registry key on the remote machine. The key must be without any subkeys.

  • cbd-lr-reg-sub-keys

    Enumerates the subkeys of the specified registry key on the remote machine.

  • cbd-lr-reg-value-delete

    Deletes a registry value on the remote machine.

  • cbd-lr-reg-value-set

    Sets a registry value on the specified registry key on the remote machine.

import functools

import demistomock as demisto
import pytest
from CarbonBlackLiveResponseCloud import *
from cbc_sdk.live_response_api import LiveResponseMemdump, LiveResponseSessionManager

CREDENTIALS = {"url": "https://test.test", "ssl_verify": False, "token": "test_key/test_id", "org_key": "test_org_key"}

api_client = CBCloudAPI(**CREDENTIALS)

commands_with_args = {
    command_test_module: {"api_client": api_client},
    put_file_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "destination_path": "test_destination_path",
        "file_id": "test_file_id",
    },
    get_file_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "source_path": "test_source_path",
        "timeout": "900",
        "delay": "900",
    },
    delete_file_command: {"api_client": api_client, "device_id": "test_device_id", "source_path": "test_source_path"},
    create_reg_key_command: {"api_client": api_client, "device_id": "test_device_id", "reg_path": "test_reg_path"},
    set_reg_value_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "reg_path": "test_reg_path",
        "value_data": "test_value_data",
        "value_type": "test_value_type",
        "overwrite": False,
    },
    delete_reg_key_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "reg_path": "test_reg_path",
    },
    delete_reg_value_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "reg_path": "test_reg_path",
    },
    list_directory_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "directory_path": "test_directory_path",
        "limit": 5,
    },
    list_reg_sub_keys_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "reg_path": "test_reg_path",
        "limit": "5",
    },
    get_reg_values_command: {"api_client": api_client, "device_id": "test_device_id", "reg_path": "test_reg_path", "limit": "5"},
    list_processes_command: {"api_client": api_client, "device_id": "test_device_id", "limit": 5},
    kill_process_command: {"api_client": api_client, "device_id": "test_device_id", "pid": "100"},
    create_process_command: {
        "api_client": api_client,
        "device_id": "test_device_id",
        "command_string": "test_cmd_line_path",
        "wait_for_output": "True",
        "wait_for_completion": True,
    },
    memdump_command: {"api_client": api_client, "device_id": "test_device_id", "target_path": "test_target_path"},
}

TEST_REG_VALUES = [
    {"registry_type": f"test_pbREG_SZ_{i}", "registry_name": f"test_val_{i}", "registry_data": f"value_data_{i}"}
    for i in range(10)
]

TEST_DIR_LIST = [
    {
        "size": 25600,
        "attributes": ["TEST_ARCHIVE"],
        "create_time": 123,
        "last_access_time": 123,
        "last_write_time": "1970-01-02T03:46:40.000Z",
        "filename": f"test_{i}.xls",
        "alternate_name": "test_$9EE1B~1.XLS",
    }
    for i in range(10)
]

TEST_PROCESSES = [
    {
        "process_path": f"test_path_{i}",
        "process_pid": i,
        "process_cmdline": f"test_command_line_{i}",
        "process_username": f"test_user_{i}",
    }
    for i in range(10)
]

SUB_KEY_LEN = 10
TEST_SUB_KEYS = {"sub_keys": [f"sub_{i}" for i in range(SUB_KEY_LEN)]}

HAPPY_PATH_ARGS = [
    (
        "put_file",
        put_file_command,
        "File: test_file_id is successfully put to the remote destination test_destination_path",
        {},
        None,
    ),
    (
        "delete_file",
        delete_file_command,
        "The file: test_source_path was deleted successfully.",
        {"filename": "test_source_path"},
        None,
    ),
    ("create_registry_key", create_reg_key_command, "Reg key: test_reg_path, was created successfully.", {}, None),
    ("set_registry_value", set_reg_value_command, "Value was set to the reg key: test_reg_path successfully.", {}, None),
    ("delete_registry_key", delete_reg_key_command, "Registry key: test_reg_path was deleted successfully.", {}, None),
    ("delete_registry_value", delete_reg_value_command, "Registry value: test_reg_path was deleted successfully.", {}, None),
    (
        "kill_process",
        kill_process_command,
        "The process: 100 was killed successfully.",
        {},
        "The process: 100 was killed successfully.",
    ),
]

WRONG_ARGS = [
    ("set_registry_value", set_reg_value_command, {"overwrite": "wrong_val"}),
    ("create_process", create_process_command, {"wait_for_completion": "wrong_val"}),
    ("create_process", create_process_command, {"wait_for_output": "wrong_val"}),
    ("create_process", create_process_command, {"wait_timeout": "wrong_val"}),
    ("get_file", get_file_command, {"timeout": "wrong_val"}),
    ("delete_registry_key", delete_reg_key_command, {"force": "wrong_val"}),
    ("list_directory", list_directory_command, {"limit": "wrong_val"}),
]

DIR_LIST_EXPECTED_OUTPUT = (
    "Name|Type|Date Modified|Size|\n|---|---|---|---|\n| test_0.xls | File | 1970-01-02T03:46:40.000Z | 25600"
)
#

HAPPY_PATH_ARGS_FOR_COMMAND_RESULTS = [
    ("list_registry_keys_and_values", list_reg_sub_keys_command, "sub_1", (), TEST_SUB_KEYS),
    ("list_registry_values", get_reg_values_command, "test_pbREG_SZ_1", (), TEST_REG_VALUES),
    ("list_processes", list_processes_command, "test_path_1 | 1 | test_command_line_1", (), TEST_PROCESSES),
    ("list_directory", list_directory_command, DIR_LIST_EXPECTED_OUTPUT, (), TEST_DIR_LIST),
    (
        "create_process",
        create_process_command,
        "פלט בעברית",
        {"command_string": "test_cmd_line_path", "wait_timeout": 30, "wait_for_output": True, "wait_for_completion": True},
        "פלט בעברית".encode(),
    ),
]


class MockedLRObject:
    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        pass

    def lr_session(self):
        return self


MOCKED_LR_SESSION = MockedLRObject()


def raise_exception(exception_to_raise, *args):
    raise exception_to_raise


def mock_method_in_lr_session(mocker, method_name, mocked_results=None):
    """
    mocked the required method in CBCloudAPI and CbLRSessionBase


    :type mocker: ``Mock``
    :param mocker: the pytest mock object

    :type method_name: ``str``
    :param method_name: The name of the method in CbLRSessionBase to be mocked e.g put_file

    :type mocked_results: ``Any``
    :param mocked_results: The result to return in call to the mocked method

    :rtype: ``Mock``
    :return: the mocked object
    """

    test_mocker = mocker.patch("cbc_sdk.CBCloudAPI.select", return_value=MOCKED_LR_SESSION)

    def mock_method():
        lambda *args, **kwargs: None  # noqa: B018

    setattr(MOCKED_LR_SESSION, method_name, mock_method)  # Just defined method in the object
    test_mocker = mocker.patch.object(MOCKED_LR_SESSION, method_name, return_value=mocked_results)

    mocker.patch.object(demisto, "getFilePath", return_value={"path": "test_data/test.txt", "name": "test"})
    return test_mocker


class TestCommands:
    @pytest.mark.parametrize(
        "api_method_to_be_mocked, tested_command, expected_result, expected_args, mocked_results", HAPPY_PATH_ARGS
    )
    def test_commands_happy_path(
        self, mocker, api_method_to_be_mocked, tested_command, expected_result, expected_args, mocked_results
    ):
        """

        Given:
            - Args for command to send via Live Response API (from commands_with_args)

        When:
            - Run the command

        Then:
            - Returns the command output

        """
        mocked_obj = mock_method_in_lr_session(mocker=mocker, method_name=api_method_to_be_mocked, mocked_results=mocked_results)

        kwargs = commands_with_args[tested_command]
        res = tested_command(**kwargs)

        # assert result
        assert res == expected_result

        if expected_args:
            assert mocked_obj.call_args[1] == expected_args

        limit = arg_to_number(kwargs.get("limit"))
        if limit:
            assert len(res) <= limit

    @pytest.mark.parametrize("api_method_to_be_mocked, tested_command, wrong_args", WRONG_ARGS)
    def test_commands_wrong_args(self, mocker, api_method_to_be_mocked, tested_command, wrong_args):
        """

        Given:
            - Args for command to send via Live Response API (from commands_with_args)

        When:
            - Run the command

        Then:
            - Returns the command output

        """

        mock_method_in_lr_session(
            mocker=mocker,
            method_name=api_method_to_be_mocked,
            mocked_results=[],
        )

        kwargs = commands_with_args[tested_command].copy()
        kwargs.update(wrong_args)
        with pytest.raises(ValueError):
            tested_command(**kwargs)

    @pytest.mark.parametrize(
        "api_method_to_be_mocked, tested_command, expected_result, expected_args, mocked_results",
        HAPPY_PATH_ARGS_FOR_COMMAND_RESULTS,
    )
    def test_readable_outputs(
        self, mocker, api_method_to_be_mocked, tested_command, expected_result, expected_args, mocked_results
    ):
        # prepare
        mock_method_in_lr_session(mocker=mocker, method_name=api_method_to_be_mocked, mocked_results=mocked_results)

        # run
        kwargs = commands_with_args[tested_command]
        res = tested_command(**kwargs)

        # assert
        assert expected_result in res.readable_output

        limit = arg_to_number(kwargs.get("limit"))
        if limit:
            assert len(res.raw_response) <= limit

    def test_memdump_command(self, mocker):
        """
        Given:
            - Args for memdump command to send via Live Response API (from commands_with_args)

        When:
            - Run the memdump command

        Then:
            - Returns the command output

        """
        # prepare
        mocker.patch("cbc_sdk.live_response_api.LiveResponseMemdump.wait")
        mock_method_in_lr_session(
            mocker=mocker,
            method_name="start_memdump",
            mocked_results=LiveResponseMemdump(None, None, None),
        )

        # run
        kwargs = commands_with_args[memdump_command]
        res = memdump_command(**kwargs)

        # assert
        assert res == "Memory was successfully dumped to test_target_path."

    @pytest.mark.parametrize("force, expected_call_count", [(False, 1), (True, 11)])
    def test_delete_reg_key_force(self, mocker, force, expected_call_count):
        """
        Given:
            - Reg key contain sub keys
        When:
            - run the delete reg key command with force arg true
        Then:
            - validate all sub keys was deleted
        """

        # prepare
        def mock_sub_keys(reg_key):
            return {"sub_keys": ["sub_key"] if reg_key.count("\\") < SUB_KEY_LEN else []}

        mock_method_in_lr_session(mocker=mocker, method_name="list_registry_keys_and_values")
        mocker.patch.object(MOCKED_LR_SESSION, "list_registry_keys_and_values", side_effect=mock_sub_keys)
        mocked_method = mock_method_in_lr_session(mocker=mocker, method_name="delete_registry_key")

        # run
        kwargs = commands_with_args[delete_reg_key_command]
        kwargs["force"] = force
        delete_reg_key_command(**kwargs)

        assert mocked_method.call_count == expected_call_count

    def test_command_test_happy_path(self, mocker):
        """
        Given:
            - Args for test_command

        When:
            - Run the test_command

        Then:
            - Validate the results

        """
        # prepare
        kwargs = commands_with_args[command_test_module]
        mocker.patch.object(LiveResponseSessionManager, "request_session")

        # run
        res = command_test_module(**kwargs)

        # assert
        assert res == "ok"

    RAISE_EXCEPTION_PARAMS = [
        (errors.UnauthorizedError(""), AUTHORIZATION_ERROR_MSG),
        (errors.ConnectionError(""), CONNECTION_ERROR_MSG),
        (errors.ObjectNotFoundError("wrong org_id"), ORG_ID_ERROR_MSG),
    ]

    @pytest.mark.parametrize("exception_to_raise, expected_res", RAISE_EXCEPTION_PARAMS)
    def test_command_test_raise_exception(self, mocker, exception_to_raise, expected_res):
        """
        Given:
            - Args for test_command

        When:
            - Run the test_command

        Then:
            - raise exceptions and validate them

        """

        # prepare
        mocker.patch.object(
            LiveResponseSessionManager, "request_session", side_effect=functools.partial(raise_exception, exception_to_raise)
        )

        # run
        kwargs = commands_with_args[command_test_module]
        with pytest.raises(DemistoException) as exc_info:
            command_test_module(**kwargs)

        # validate
        assert expected_res in exc_info.value.args[0]

    def test_not_implemented_command(self, mocker):
        """
        Given -
        When - Try to run not implemented command
        Then - Validate NotImplementedError was occurred
        """

        # prepare
        not_implemented_command = "not_implemented"
        mocker.patch.object(demisto, "command", return_value=not_implemented_command)
        mocker.patch.object(
            demisto, "params", return_value={"custom_key": "unit test", "custom_id": "unit test", "org_key": "unit test"}
        )
        # run
        with pytest.raises(NotImplementedError) as exc_info:
            main()

        assert exc_info.value.args[0] == f"Command: {not_implemented_command} not implemented"