|
|
@ -6,6 +6,7 @@ import unittest
|
|
|
|
# import os
|
|
|
|
# import os
|
|
|
|
from app.config import ExperimentConfig, MachineConfig
|
|
|
|
from app.config import ExperimentConfig, MachineConfig
|
|
|
|
from app.exceptions import ConfigurationError
|
|
|
|
from app.exceptions import ConfigurationError
|
|
|
|
|
|
|
|
from dotmap import DotMap
|
|
|
|
|
|
|
|
|
|
|
|
# https://docs.python.org/3/library/unittest.html
|
|
|
|
# https://docs.python.org/3/library/unittest.html
|
|
|
|
|
|
|
|
|
|
|
@ -21,481 +22,429 @@ class TestMachineConfig(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def test_basic_init(self):
|
|
|
|
def test_basic_init(self):
|
|
|
|
""" The init is basic and working """
|
|
|
|
""" The init is basic and working """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.raw_config["root"], "systems/attacker1")
|
|
|
|
self.assertEqual(mc.raw_config["root"], "systems/attacker1")
|
|
|
|
self.assertEqual(mc.raw_config["vm_controller"]["type"], "vagrant")
|
|
|
|
self.assertEqual(mc.raw_config.vm_controller.vm_type, "vagrant")
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_vm_name(self):
|
|
|
|
|
|
|
|
""" The vm name is missing """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
MachineConfig({"root": "systems/attacker1",
|
|
|
|
|
|
|
|
"os": "linux",
|
|
|
|
|
|
|
|
"vm_controller": {
|
|
|
|
|
|
|
|
"type": "vagrant",
|
|
|
|
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
|
|
|
|
}})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_use_existing_machine_is_true(self):
|
|
|
|
def test_use_existing_machine_is_true(self):
|
|
|
|
""" Testing use_existing:machine setting """
|
|
|
|
""" Testing use_existing:machine setting """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": True})
|
|
|
|
"use_existing_machine": True}))
|
|
|
|
self.assertEqual(mc.use_existing_machine(), True)
|
|
|
|
self.assertEqual(mc.use_existing_machine(), True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_use_existing_machine_is_false(self):
|
|
|
|
def test_use_existing_machine_is_false(self):
|
|
|
|
""" Testing use_existing:machine setting """
|
|
|
|
""" Testing use_existing:machine setting """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.use_existing_machine(), False)
|
|
|
|
self.assertEqual(mc.use_existing_machine(), False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_use_existing_machine_is_default(self):
|
|
|
|
def test_use_existing_machine_is_default(self):
|
|
|
|
""" Testing use_existing:machine setting """
|
|
|
|
""" Testing use_existing:machine setting """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.use_existing_machine(), False)
|
|
|
|
self.assertEqual(mc.use_existing_machine(), False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_windows_is_valid_os(self):
|
|
|
|
def test_windows_is_valid_os(self):
|
|
|
|
""" Testing if windows is valid os """
|
|
|
|
""" Testing if windows is valid os """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "windows",
|
|
|
|
"os": "windows",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.os(), "windows")
|
|
|
|
self.assertEqual(mc.os(), "windows")
|
|
|
|
|
|
|
|
|
|
|
|
def test_windows_is_valid_os_casefix(self):
|
|
|
|
def test_windows_is_valid_os_casefix(self):
|
|
|
|
""" Testing if windows is valid os - using lowercase fix"""
|
|
|
|
""" Testing if windows is valid os - using lowercase fix"""
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "WINDOWS",
|
|
|
|
"os": "WINDOWS",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.os(), "windows")
|
|
|
|
self.assertEqual(mc.os(), "windows")
|
|
|
|
|
|
|
|
|
|
|
|
def test_linux_is_valid_os(self):
|
|
|
|
def test_linux_is_valid_os(self):
|
|
|
|
""" Testing if windows is valid os """
|
|
|
|
""" Testing if windows is valid os """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.os(), "linux")
|
|
|
|
self.assertEqual(mc.os(), "linux")
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_os(self):
|
|
|
|
|
|
|
|
""" The os is missing """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
MachineConfig({"root": "systems/attacker1",
|
|
|
|
|
|
|
|
"vm_controller": {
|
|
|
|
|
|
|
|
"type": "vagrant",
|
|
|
|
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"vm_name": "target1"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_wrong_os(self):
|
|
|
|
|
|
|
|
""" The os is wrong """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
MachineConfig({"root": "systems/attacker1",
|
|
|
|
|
|
|
|
"os": "BROKEN",
|
|
|
|
|
|
|
|
"vm_controller": {
|
|
|
|
|
|
|
|
"type": "vagrant",
|
|
|
|
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"vm_name": "target1"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_vagrant_is_valid_vmcontroller(self):
|
|
|
|
def test_vagrant_is_valid_vmcontroller(self):
|
|
|
|
""" Testing if vagrant is valid vmcontroller """
|
|
|
|
""" Testing if vagrant is valid vmcontroller """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.vmcontroller(), "vagrant")
|
|
|
|
self.assertEqual(mc.vmcontroller(), "vagrant")
|
|
|
|
|
|
|
|
|
|
|
|
def test_vagrant_is_valid_vmcontroller_casefix(self):
|
|
|
|
def test_vagrant_is_valid_vmcontroller_casefix(self):
|
|
|
|
""" Testing if vagrant is valid vmcontroller case fixxed"""
|
|
|
|
""" Testing if vagrant is valid vmcontroller case fixxed"""
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "VAGRANT",
|
|
|
|
"vm_type": "VAGRANT",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.vmcontroller(), "vagrant")
|
|
|
|
self.assertEqual(mc.vmcontroller(), "vagrant")
|
|
|
|
|
|
|
|
|
|
|
|
def test_invalid_vmcontroller(self):
|
|
|
|
|
|
|
|
""" Testing if vagrant is valid vmcontroller case fixxed"""
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
MachineConfig({"root": "systems/attacker1",
|
|
|
|
|
|
|
|
"os": "linux",
|
|
|
|
|
|
|
|
"vm_controller": {
|
|
|
|
|
|
|
|
"type": "BROKEN",
|
|
|
|
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"vm_name": "target1"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_vmcontroller_2(self):
|
|
|
|
|
|
|
|
""" Testing if vagrant is valid vmcontroller case fixxed"""
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
MachineConfig({"root": "systems/attacker1",
|
|
|
|
|
|
|
|
"os": "linux",
|
|
|
|
|
|
|
|
"vm_name": "target1"})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_vagrant_is_valid_vmip(self):
|
|
|
|
def test_vagrant_is_valid_vmip(self):
|
|
|
|
""" Testing if vagrant is valid ip/url """
|
|
|
|
""" Testing if vagrant is valid ip/url """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"ip": "kali",
|
|
|
|
"ip": "kali",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1"})
|
|
|
|
"vm_name": "target1"}))
|
|
|
|
self.assertEqual(mc.vm_ip(), "kali")
|
|
|
|
self.assertEqual(mc.vm_ip(), "kali")
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_vmip(self):
|
|
|
|
def test_missing_vmip(self):
|
|
|
|
""" Testing if missing vm ip is handled"""
|
|
|
|
""" Testing if missing vm ip is handled"""
|
|
|
|
vm_name = "target1"
|
|
|
|
vm_name = "target1"
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": vm_name})
|
|
|
|
"vm_name": vm_name}))
|
|
|
|
self.assertEqual(mc.vm_ip(), vm_name)
|
|
|
|
self.assertEqual(mc.vm_ip(), vm_name)
|
|
|
|
|
|
|
|
|
|
|
|
def test_machinepath(self):
|
|
|
|
def test_machinepath(self):
|
|
|
|
""" Testing machinepath setting """
|
|
|
|
""" Testing machinepath setting """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"machinepath": "foo"})
|
|
|
|
"machinepath": "foo"}))
|
|
|
|
self.assertEqual(mc.machinepath(), "foo")
|
|
|
|
self.assertEqual(mc.machinepath(), "foo")
|
|
|
|
|
|
|
|
|
|
|
|
def test_machinepath_fallback(self):
|
|
|
|
def test_machinepath_fallback(self):
|
|
|
|
""" Testing machinepath setting fallback to vmname"""
|
|
|
|
""" Testing machinepath setting fallback to vmname"""
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.machinepath(), "target1")
|
|
|
|
self.assertEqual(mc.machinepath(), "target1")
|
|
|
|
|
|
|
|
|
|
|
|
def test_paw(self):
|
|
|
|
def test_paw(self):
|
|
|
|
""" Testing for caldera paw """
|
|
|
|
""" Testing for caldera paw """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"paw": "Bar",
|
|
|
|
"paw": "Bar",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.caldera_paw(), "Bar")
|
|
|
|
self.assertEqual(mc.caldera_paw(), "Bar")
|
|
|
|
|
|
|
|
|
|
|
|
def test_paw_fallback(self):
|
|
|
|
def test_paw_fallback(self):
|
|
|
|
""" Testing for caldera paw fallback """
|
|
|
|
""" Testing for caldera paw fallback """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.caldera_paw(), None)
|
|
|
|
self.assertEqual(mc.caldera_paw(), None)
|
|
|
|
|
|
|
|
|
|
|
|
def test_group(self):
|
|
|
|
def test_group(self):
|
|
|
|
""" Testing for caldera group """
|
|
|
|
""" Testing for caldera group """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"group": "Bar",
|
|
|
|
"group": "Bar",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.caldera_group(), "Bar")
|
|
|
|
self.assertEqual(mc.caldera_group(), "Bar")
|
|
|
|
|
|
|
|
|
|
|
|
def test_group_fallback(self):
|
|
|
|
def test_group_fallback(self):
|
|
|
|
""" Testing for caldera group fallback """
|
|
|
|
""" Testing for caldera group fallback """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.caldera_group(), None)
|
|
|
|
self.assertEqual(mc.caldera_group(), None)
|
|
|
|
|
|
|
|
|
|
|
|
def test_ssh_keyfile(self):
|
|
|
|
def test_ssh_keyfile(self):
|
|
|
|
""" Testing keyfile config """
|
|
|
|
""" Testing keyfile config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"ssh_keyfile": "Bar",
|
|
|
|
"ssh_keyfile": "Bar",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.ssh_keyfile(), "Bar")
|
|
|
|
self.assertEqual(mc.ssh_keyfile(), "Bar")
|
|
|
|
|
|
|
|
|
|
|
|
def test_ssh_keyfile_default(self):
|
|
|
|
def test_ssh_keyfile_default(self):
|
|
|
|
""" Testing keyfile config default """
|
|
|
|
""" Testing keyfile config default """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.ssh_keyfile(), None)
|
|
|
|
self.assertEqual(mc.ssh_keyfile(), None)
|
|
|
|
|
|
|
|
|
|
|
|
def test_ssh_user(self):
|
|
|
|
def test_ssh_user(self):
|
|
|
|
""" Testing ssh user config """
|
|
|
|
""" Testing ssh user config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"ssh_user": "Bob",
|
|
|
|
"ssh_user": "Bob",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.ssh_user(), "Bob")
|
|
|
|
self.assertEqual(mc.ssh_user(), "Bob")
|
|
|
|
|
|
|
|
|
|
|
|
def test_ssh_user_default(self):
|
|
|
|
def test_ssh_user_default(self):
|
|
|
|
""" Testing ssh user default config """
|
|
|
|
""" Testing ssh user default config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.ssh_user(), "vagrant")
|
|
|
|
self.assertEqual(mc.ssh_user(), "vagrant")
|
|
|
|
|
|
|
|
|
|
|
|
def test_ssh_password(self):
|
|
|
|
def test_ssh_password(self):
|
|
|
|
""" Testing ssh password config """
|
|
|
|
""" Testing ssh password config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"ssh_user": "Bob",
|
|
|
|
"ssh_user": "Bob",
|
|
|
|
"ssh_password": "Ross",
|
|
|
|
"ssh_password": "Ross",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.ssh_password(), "Ross")
|
|
|
|
self.assertEqual(mc.ssh_password(), "Ross")
|
|
|
|
|
|
|
|
|
|
|
|
def test_ssh_password_default(self):
|
|
|
|
def test_ssh_password_default(self):
|
|
|
|
""" Testing ssh password default config """
|
|
|
|
""" Testing ssh password default config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertIsNone(mc.ssh_password())
|
|
|
|
self.assertIsNone(mc.ssh_password())
|
|
|
|
|
|
|
|
|
|
|
|
def test_halt_needs_force_default(self):
|
|
|
|
def test_halt_needs_force_default(self):
|
|
|
|
""" Testing 'halt needs force' default config """
|
|
|
|
""" Testing 'halt needs force' default config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.halt_needs_force(), False)
|
|
|
|
self.assertEqual(mc.halt_needs_force(), False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_halt_needs_force(self):
|
|
|
|
def test_halt_needs_force(self):
|
|
|
|
""" Testing 'halt needs force' config """
|
|
|
|
""" Testing 'halt needs force' config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.halt_needs_force(), True)
|
|
|
|
self.assertEqual(mc.halt_needs_force(), True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_vagrantfilepath(self):
|
|
|
|
def test_vagrantfilepath(self):
|
|
|
|
""" Testing vagrantfilepath config """
|
|
|
|
""" Testing vagrantfilepath config """
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
"vagrantfilepath": "systems",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.vagrantfilepath(), "systems")
|
|
|
|
self.assertEqual(mc.vagrantfilepath(), "systems")
|
|
|
|
|
|
|
|
|
|
|
|
def test_vagrantfilepath_missing(self):
|
|
|
|
def test_vagrantfilepath_missing(self):
|
|
|
|
""" Testing missing vagrantfilepath config """
|
|
|
|
""" Testing missing vagrantfilepath config """
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False})))
|
|
|
|
mc.vagrantfilepath()
|
|
|
|
mc.vagrantfilepath()
|
|
|
|
|
|
|
|
|
|
|
|
def test_sensors_empty(self):
|
|
|
|
def test_sensors_empty(self):
|
|
|
|
""" Testing empty sensor config """
|
|
|
|
""" Testing empty sensor config """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.sensors(), [])
|
|
|
|
self.assertEqual(mc.sensors(), [])
|
|
|
|
|
|
|
|
|
|
|
|
def test_sensors_set(self):
|
|
|
|
def test_sensors_set(self):
|
|
|
|
""" Testing empty sensor config """
|
|
|
|
""" Testing empty sensor config """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]})
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]}))
|
|
|
|
self.assertEqual(mc.sensors(), ["linux_idp", "test_sensor"])
|
|
|
|
self.assertEqual(mc.sensors(), ["linux_idp", "test_sensor"])
|
|
|
|
|
|
|
|
|
|
|
|
def test_vulnerabilities_empty(self):
|
|
|
|
def test_vulnerabilities_empty(self):
|
|
|
|
""" Testing empty vulnerabilities config """
|
|
|
|
""" Testing empty vulnerabilities config """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False})
|
|
|
|
"use_existing_machine": False}))
|
|
|
|
self.assertEqual(mc.vulnerabilities(), [])
|
|
|
|
self.assertEqual(mc.vulnerabilities(), [])
|
|
|
|
|
|
|
|
|
|
|
|
def test_vulnerabilities_set(self):
|
|
|
|
def test_vulnerabilities_set(self):
|
|
|
|
""" Testing empty vulnerabilities config """
|
|
|
|
""" Testing empty vulnerabilities config """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"vulnerabilities": ["PEBKAC", "USER"]})
|
|
|
|
"vulnerabilities": ["PEBKAC", "USER"]}))
|
|
|
|
self.assertEqual(mc.vulnerabilities(), ["PEBKAC", "USER"])
|
|
|
|
self.assertEqual(mc.vulnerabilities(), ["PEBKAC", "USER"])
|
|
|
|
|
|
|
|
|
|
|
|
def test_active_not_set(self):
|
|
|
|
def test_active_not_set(self):
|
|
|
|
""" machine active not set """
|
|
|
|
""" machine active not set """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]})
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]}))
|
|
|
|
self.assertEqual(mc.is_active(), True)
|
|
|
|
self.assertEqual(mc.is_active(), True)
|
|
|
|
|
|
|
|
|
|
|
|
def test_active_is_false(self):
|
|
|
|
def test_active_is_false(self):
|
|
|
|
""" machine active is set to false """
|
|
|
|
""" machine active is set to false """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"active": False,
|
|
|
|
"active": False,
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]})
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]}))
|
|
|
|
self.assertEqual(mc.is_active(), False)
|
|
|
|
self.assertEqual(mc.is_active(), False)
|
|
|
|
|
|
|
|
|
|
|
|
def test_active_is_true(self):
|
|
|
|
def test_active_is_true(self):
|
|
|
|
""" machine active is set to true """
|
|
|
|
""" machine active is set to true """
|
|
|
|
|
|
|
|
|
|
|
|
mc = MachineConfig({"root": "systems/attacker1",
|
|
|
|
mc = MachineConfig(DotMap({"root": "systems/attacker1",
|
|
|
|
"os": "linux",
|
|
|
|
"os": "linux",
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"halt_needs_force": True,
|
|
|
|
"vm_controller": {
|
|
|
|
"vm_controller": {
|
|
|
|
"type": "vagrant",
|
|
|
|
"vm_type": "vagrant",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"vm_name": "target1",
|
|
|
|
"vm_name": "target1",
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"use_existing_machine": False,
|
|
|
|
"active": True,
|
|
|
|
"active": True,
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]})
|
|
|
|
"sensors": ["linux_idp", "test_sensor"]}))
|
|
|
|
self.assertEqual(mc.is_active(), True)
|
|
|
|
self.assertEqual(mc.is_active(), True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -509,7 +458,7 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
""" Existing, basic config file, testing the values are loaded properly """
|
|
|
|
""" Existing, basic config file, testing the values are loaded properly """
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
self.assertEqual(ex.raw_config["caldera"]["apikey"], "ADMIN123")
|
|
|
|
self.assertEqual(ex.raw_config.caldera.apikey, "ADMIN123")
|
|
|
|
self.assertEqual(ex.caldera_apikey(), "ADMIN123")
|
|
|
|
self.assertEqual(ex.caldera_apikey(), "ADMIN123")
|
|
|
|
|
|
|
|
|
|
|
|
def test_broken_apikey(self):
|
|
|
|
def test_broken_apikey(self):
|
|
|
@ -528,22 +477,6 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
e.loot_dir()
|
|
|
|
e.loot_dir()
|
|
|
|
|
|
|
|
|
|
|
|
def test_broken_attack_conf(self):
|
|
|
|
|
|
|
|
""" Test with partially empty config file """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
|
|
|
|
e.raw_config = None
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
e.attack_conf("hydra")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_broken_attack_conf_2(self):
|
|
|
|
|
|
|
|
""" Test with partially empty config file """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
|
|
|
|
e.raw_config["attack_conf"] = None
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
e.attack_conf("hydra")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_broken_caldera_obfuscator_conf(self):
|
|
|
|
def test_broken_caldera_obfuscator_conf(self):
|
|
|
|
""" Test with partially empty config file """
|
|
|
|
""" Test with partially empty config file """
|
|
|
|
|
|
|
|
|
|
|
@ -598,53 +531,12 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
self.assertEqual(ex.loot_dir(), "loot")
|
|
|
|
self.assertEqual(ex.loot_dir(), "loot")
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_loot_dir(self):
|
|
|
|
|
|
|
|
""" Test with missing loot dir """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
ExperimentConfig("tests/data/basic_loot_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty_config(self):
|
|
|
|
def test_empty_config(self):
|
|
|
|
""" Test with empty config file """
|
|
|
|
""" Test with empty config file """
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
ExperimentConfig("tests/data/empty.yaml")
|
|
|
|
ExperimentConfig("tests/data/empty.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty_targets(self):
|
|
|
|
|
|
|
|
""" Test with empty targets in file """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
ExperimentConfig("tests/data/empty_targets.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_empty_attackers(self):
|
|
|
|
|
|
|
|
""" Test with empty attackers in file """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
ExperimentConfig("tests/data/empty_attackers.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_results(self):
|
|
|
|
|
|
|
|
""" Test with missing results """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with self.assertRaises(ConfigurationError):
|
|
|
|
|
|
|
|
ExperimentConfig("tests/data/basic_results_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_basic_loading_targets_read(self):
|
|
|
|
|
|
|
|
""" Targets in config: can be found """
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
|
|
|
|
self.assertEqual(len(ex._targets), 2)
|
|
|
|
|
|
|
|
self.assertEqual(ex._targets[0].raw_config["vm_name"], "target1")
|
|
|
|
|
|
|
|
self.assertEqual(ex._targets[0].vmname(), "target1")
|
|
|
|
|
|
|
|
self.assertEqual(ex.targets()[0].vmname(), "target1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_basic_loading_attacker_read(self):
|
|
|
|
|
|
|
|
""" Attackers in config: can be found """
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
|
|
|
|
self.assertEqual(len(ex._targets), 2)
|
|
|
|
|
|
|
|
self.assertEqual(ex._attackers[0].raw_config["vm_name"], "attacker")
|
|
|
|
|
|
|
|
self.assertEqual(ex._attackers[0].vmname(), "attacker")
|
|
|
|
|
|
|
|
self.assertEqual(ex.attackers()[0].vmname(), "attacker")
|
|
|
|
|
|
|
|
self.assertEqual(ex.attacker(0).vmname(), "attacker")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_nicknames_missing(self):
|
|
|
|
def test_nicknames_missing(self):
|
|
|
|
""" Test when the machine nicknames are non existing """
|
|
|
|
""" Test when the machine nicknames are non existing """
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
@ -658,7 +550,7 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
def test_nicknames_present(self):
|
|
|
|
def test_nicknames_present(self):
|
|
|
|
""" Test when the machine nicknames are there """
|
|
|
|
""" Test when the machine nicknames are there """
|
|
|
|
ex = ExperimentConfig("tests/data/attacker_has_empty_nicknames.yaml")
|
|
|
|
ex = ExperimentConfig("tests/data/attacker_has_empty_nicknames.yaml")
|
|
|
|
self.assertEqual(ex._targets[0].get_nicknames(), [1, 2, 3])
|
|
|
|
self.assertEqual(ex._targets[0].get_nicknames(), ["1", "2", "3"])
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_attack_config(self):
|
|
|
|
def test_missing_attack_config(self):
|
|
|
|
""" Getting attack config for a specific attack. Attack missing """
|
|
|
|
""" Getting attack config for a specific attack. Attack missing """
|
|
|
@ -674,14 +566,6 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
data = ex.attack_conf("hydra")
|
|
|
|
data = ex.attack_conf("hydra")
|
|
|
|
self.assertEqual(data["userfile"], "users.txt")
|
|
|
|
self.assertEqual(data["userfile"], "users.txt")
|
|
|
|
|
|
|
|
|
|
|
|
def test_attack_config_missing_attack_data(self):
|
|
|
|
|
|
|
|
""" Getting attack config for a specific attack: Missing """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/attacks_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = ex.attack_conf("missing")
|
|
|
|
|
|
|
|
self.assertEqual(data, {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_missing_caldera_config_obfuscator(self):
|
|
|
|
def test_missing_caldera_config_obfuscator(self):
|
|
|
|
""" A config file with no caldera config at all """
|
|
|
|
""" A config file with no caldera config at all """
|
|
|
|
|
|
|
|
|
|
|
@ -718,27 +602,6 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
ex = ExperimentConfig("tests/data/attacks_perfect.yaml")
|
|
|
|
ex = ExperimentConfig("tests/data/attacks_perfect.yaml")
|
|
|
|
self.assertEqual(ex.get_caldera_jitter(), "08/15")
|
|
|
|
self.assertEqual(ex.get_caldera_jitter(), "08/15")
|
|
|
|
|
|
|
|
|
|
|
|
def test_nap_time(self):
|
|
|
|
|
|
|
|
""" nap time is set """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/basic.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_nap_time(), 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_nap_time_not_set(self):
|
|
|
|
|
|
|
|
""" nap time is not set """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/nap_time_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_nap_time(), 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_kali_attacks_missing(self):
|
|
|
|
|
|
|
|
""" kali attacks entry fully missing from config """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/attacks_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_plugin_based_attacks("linux"), [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_kali_attacks_empty(self):
|
|
|
|
def test_kali_attacks_empty(self):
|
|
|
|
""" zero entries in kali attacks list """
|
|
|
|
""" zero entries in kali attacks list """
|
|
|
|
|
|
|
|
|
|
|
@ -760,13 +623,6 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_plugin_based_attacks("windows"), ["hydra", "medusa", "skylla"])
|
|
|
|
self.assertEqual(ex.get_plugin_based_attacks("windows"), ["hydra", "medusa", "skylla"])
|
|
|
|
|
|
|
|
|
|
|
|
def test_caldera_attacks_missing(self):
|
|
|
|
|
|
|
|
""" caldera attacks entry fully missing from config """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/attacks_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_caldera_attacks("linux"), [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_kali_attacks_half(self):
|
|
|
|
def test_kali_attacks_half(self):
|
|
|
|
""" kali attacks entry partially missing from config """
|
|
|
|
""" kali attacks entry partially missing from config """
|
|
|
|
|
|
|
|
|
|
|
@ -818,13 +674,6 @@ class TestExperimentConfig(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_sensor_config("missing_windows_sensor"), {})
|
|
|
|
self.assertEqual(ex.get_sensor_config("missing_windows_sensor"), {})
|
|
|
|
|
|
|
|
|
|
|
|
def test_basic_sensor_entry_missing(self):
|
|
|
|
|
|
|
|
""" Test global configuration for a specific and missing sensor entry"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ex = ExperimentConfig("tests/data/attacks_missing.yaml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.assertEqual(ex.get_sensor_config("windows_sensor"), {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_basic_sensor_entry_empty(self):
|
|
|
|
def test_basic_sensor_entry_empty(self):
|
|
|
|
""" Test global configuration for a specific and empty sensor entry"""
|
|
|
|
""" Test global configuration for a specific and empty sensor entry"""
|
|
|
|
|
|
|
|
|
|
|
|