Zoo: Add os specific black box test.

Add new --os flag to the blackbox tests.
If not specified it will skip all os marked tests.
This commit is contained in:
Ilija Lazoroski 2021-09-27 13:08:52 +02:00
parent b90e9ccf21
commit 689e6ac532
4 changed files with 49 additions and 1 deletions

View File

@ -27,3 +27,20 @@ class PowerShell(ConfigTemplate):
], ],
} }
) )
class PowerShell_Cached(ConfigTemplate):
config_values = copy(BaseTemplate.config_values)
config_values.update(
{
"basic.exploiters.exploiter_classes": ["PowerShellExploiter"],
"basic_network.scope.subnet_scan_list": [
"10.2.3.46",
],
"basic_network.scope.depth": 2,
"internal.classes.finger_classes": ["PingScanner"],
"internal.network.tcp_scanner.HTTP_PORTS": [],
"internal.network.tcp_scanner.tcp_target_ports": [],
}
)

View File

@ -27,6 +27,12 @@ def pytest_addoption(parser):
default=False, default=False,
help="If enabled performance tests will be run.", help="If enabled performance tests will be run.",
) )
parser.addoption(
"--os",
action="store",
default=None,
help="Use to run Windows or Linux specific tests.",
)
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
@ -51,3 +57,18 @@ def pytest_runtest_setup(item):
pytest.skip( pytest.skip(
"Skipping performance test because " "--run-performance-tests flag isn't specified." "Skipping performance test because " "--run-performance-tests flag isn't specified."
) )
if item.config.getoption("--os"):
os = [mark.args[0] for mark in item.iter_markers(name="os")]
if os:
if item.config.getoption("--os") not in os:
pytest.skip(
f"Skipping OS specific test. Run in {os[0]} if "
f"you want this test to be executed."
)
else:
pytest.skip(
"Skipping OS specific test because"
"--os flag isn't specified."
" Specify --os with windows or linux as options."
)

View File

@ -13,7 +13,7 @@ from envs.monkey_zoo.blackbox.config_templates.elastic import Elastic
from envs.monkey_zoo.blackbox.config_templates.hadoop import Hadoop from envs.monkey_zoo.blackbox.config_templates.hadoop import Hadoop
from envs.monkey_zoo.blackbox.config_templates.mssql import Mssql from envs.monkey_zoo.blackbox.config_templates.mssql import Mssql
from envs.monkey_zoo.blackbox.config_templates.performance import Performance from envs.monkey_zoo.blackbox.config_templates.performance import Performance
from envs.monkey_zoo.blackbox.config_templates.powershell import PowerShell from envs.monkey_zoo.blackbox.config_templates.powershell import PowerShell, PowerShell_Cached
from envs.monkey_zoo.blackbox.config_templates.shellshock import ShellShock from envs.monkey_zoo.blackbox.config_templates.shellshock import ShellShock
from envs.monkey_zoo.blackbox.config_templates.smb_mimikatz import SmbMimikatz from envs.monkey_zoo.blackbox.config_templates.smb_mimikatz import SmbMimikatz
from envs.monkey_zoo.blackbox.config_templates.smb_pth import SmbPth from envs.monkey_zoo.blackbox.config_templates.smb_pth import SmbPth
@ -52,6 +52,8 @@ MACHINE_BOOTUP_WAIT_SECONDS = 30
LOG_DIR_PATH = "./logs" LOG_DIR_PATH = "./logs"
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
WINDOWS = "windows"
LINUX = "linux"
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")
@ -166,6 +168,12 @@ class TestMonkeyBlackbox:
island_client, PowerShell, "PowerShell_Remoting_exploiter" island_client, PowerShell, "PowerShell_Remoting_exploiter"
) )
@pytest.mark.os(WINDOWS)
def test_powershell_exploiter_cached_credentials(self, island_client):
TestMonkeyBlackbox.run_exploitation_test(
island_client, PowerShell_Cached, "PowerShell_Remoting_exploiter_cached_credentials"
)
def test_smb_and_mimikatz_exploiters(self, island_client): def test_smb_and_mimikatz_exploiters(self, island_client):
TestMonkeyBlackbox.run_exploitation_test( TestMonkeyBlackbox.run_exploitation_test(
island_client, SmbMimikatz, "SMB_exploiter_mimikatz" island_client, SmbMimikatz, "SMB_exploiter_mimikatz"

View File

@ -205,4 +205,6 @@ environment # unused variable (monkey/monkey_island/cc/models/monkey.py:59)
_.environment # unused attribute (monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/environment.py:10) _.environment # unused attribute (monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/environment.py:10)
_.instance_name # unused attribute (monkey/common/cloud/azure/azure_instance.py:35) _.instance_name # unused attribute (monkey/common/cloud/azure/azure_instance.py:35)
_.instance_name # unused attribute (monkey/common/cloud/azure/azure_instance.py:64) _.instance_name # unused attribute (monkey/common/cloud/azure/azure_instance.py:64)
# TODO: Remove this when adding LINUX specific bb test
LINUX # unused variable (envs/monkey_zoo/blackbox/test_blackbox.py:56)
GCPHandler # unused function (envs/monkey_zoo/blackbox/test_blackbox.py:57) GCPHandler # unused function (envs/monkey_zoo/blackbox/test_blackbox.py:57)