Zoo: Replace --os with --skip-powershell-reuse

With this logic the powershell cached will run
if we don't provide the cli param --skip-powershell-reuse.
This commit is contained in:
Ilija Lazoroski 2021-09-28 16:42:16 +02:00
parent 07c08ac0b6
commit a438f3afb0
3 changed files with 16 additions and 24 deletions

View File

@ -4,7 +4,7 @@ from envs.monkey_zoo.blackbox.config_templates.base_template import BaseTemplate
from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate from envs.monkey_zoo.blackbox.config_templates.config_template import ConfigTemplate
class PowerShellCachedCredentials(ConfigTemplate): class PowerShellCredentialsReuse(ConfigTemplate):
config_values = copy(BaseTemplate.config_values) config_values = copy(BaseTemplate.config_values)
config_values.update( config_values.update(

View File

@ -28,10 +28,10 @@ def pytest_addoption(parser):
help="If enabled performance tests will be run.", help="If enabled performance tests will be run.",
) )
parser.addoption( parser.addoption(
"--os", "--skip-powershell-reuse",
action="store", action="store_true",
default=None, default=False,
help="Use to run Windows or Linux specific tests.", help="Use to run PowerShell credentials reuse test.",
) )
@ -58,17 +58,10 @@ def pytest_runtest_setup(item):
"Skipping performance test because " "--run-performance-tests flag isn't specified." "Skipping performance test because " "--run-performance-tests flag isn't specified."
) )
if not item.config.getoption("--os"): if "skip_powershell_reuse" in item.keywords and item.config.getoption(
"--skip-powershell-reuse"
):
pytest.skip( pytest.skip(
"Skipping OS specific test because" "Skipping powershell credentials reuse test because "
"--os flag isn't specified." "--skip-powershell-cached flag isn't specified."
" Specify --os with windows or linux as options."
)
os = [mark.args[0] for mark in item.iter_markers(name="os")]
if os and item.config.getoption("--os") not in os:
pytest.skip(
f'Skipping OS specific test. Run with "--os={os[0]}" if '
f"you want this test to be executed."
) )

View File

@ -14,8 +14,8 @@ 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
from envs.monkey_zoo.blackbox.config_templates.powershell_cached_credentials import ( from envs.monkey_zoo.blackbox.config_templates.powershell_credentials_reuse import (
PowerShellCachedCredentials, PowerShellCredentialsReuse,
) )
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
@ -55,7 +55,6 @@ 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"
@pytest.fixture(autouse=True, scope="session") @pytest.fixture(autouse=True, scope="session")
@ -170,12 +169,12 @@ class TestMonkeyBlackbox:
island_client, PowerShell, "PowerShell_Remoting_exploiter" island_client, PowerShell, "PowerShell_Remoting_exploiter"
) )
@pytest.mark.os(WINDOWS) @pytest.mark.skip_powershell_reuse
def test_powershell_exploiter_cached_credentials(self, island_client): def test_powershell_exploiter_credentials_reuse(self, island_client):
TestMonkeyBlackbox.run_exploitation_test( TestMonkeyBlackbox.run_exploitation_test(
island_client, island_client,
PowerShellCachedCredentials, PowerShellCredentialsReuse,
"PowerShell_Remoting_exploiter_cached_credentials", "PowerShell_Remoting_exploiter_credentials_reuse",
) )
def test_smb_and_mimikatz_exploiters(self, island_client): def test_smb_and_mimikatz_exploiters(self, island_client):