port refactor - eod commit, airspace still broken
This commit is contained in:
@@ -26,9 +26,9 @@ def game_and_agent_fixture(game_and_agent):
|
||||
game, agent = game_and_agent
|
||||
|
||||
router = game.simulation.network.get_node_by_hostname("router")
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.HTTP, dst_port=Port.HTTP, position=4)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.DNS, dst_port=Port.DNS, position=5)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.FTP, dst_port=Port.FTP, position=6)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port["HTTP"], dst_port=Port["HTTP"], position=4)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port["DNS"], dst_port=Port["DNS"], position=5)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port["FTP"], dst_port=Port["FTP"], position=6)
|
||||
|
||||
c2_server_host = game.simulation.network.get_node_by_hostname("client_1")
|
||||
c2_server_host.software_manager.install(software_class=C2Server)
|
||||
|
||||
@@ -200,7 +200,7 @@ class TestConfigureDoSBot:
|
||||
game.step()
|
||||
|
||||
assert dos_bot.target_ip_address == IPv4Address("192.168.1.99")
|
||||
assert dos_bot.target_port == Port.POSTGRES_SERVER
|
||||
assert dos_bot.target_port == Port["POSTGRES_SERVER"]
|
||||
assert dos_bot.payload == "HACC"
|
||||
assert not dos_bot.repeat
|
||||
assert dos_bot.port_scan_p_of_success == 0.875
|
||||
|
||||
@@ -20,7 +20,7 @@ def game_and_agent_fixture(game_and_agent):
|
||||
game, agent = game_and_agent
|
||||
|
||||
router = game.simulation.network.get_node_by_hostname("router")
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port.SSH, dst_port=Port.SSH, position=4)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, src_port=Port["SSH"], dst_port=Port["SSH"], position=4)
|
||||
|
||||
return (game, agent)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ def test_acl_observations(simulation):
|
||||
server.software_manager.install(NTPServer)
|
||||
|
||||
# add router acl rule
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, dst_port=Port.NTP, src_port=Port.NTP, position=1)
|
||||
router.acl.add_rule(action=ACLAction.PERMIT, dst_port=Port["NTP"], src_port=Port["NTP"], position=1)
|
||||
|
||||
acl_obs = ACLObservation(
|
||||
where=["network", "nodes", router.hostname, "acl", "acl"],
|
||||
|
||||
@@ -62,13 +62,13 @@ def test_firewall_observation():
|
||||
# add a rule to the internal inbound and check that the observation is correct
|
||||
firewall.internal_inbound_acl.add_rule(
|
||||
action=ACLAction.DENY,
|
||||
protocol=IPProtocol.TCP,
|
||||
protocol=IPProtocol["TCP"],
|
||||
src_ip_address="10.0.0.1",
|
||||
src_wildcard_mask="0.0.0.1",
|
||||
dst_ip_address="10.0.0.2",
|
||||
dst_wildcard_mask="0.0.0.1",
|
||||
src_port=Port.HTTP,
|
||||
dst_port=Port.HTTP,
|
||||
src_port=Port["HTTP"],
|
||||
dst_port=Port["HTTP"],
|
||||
position=5,
|
||||
)
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ def test_config_nic_categories(simulation):
|
||||
|
||||
|
||||
def test_nic_monitored_traffic(simulation):
|
||||
monitored_traffic = {"icmp": ["NONE"], "tcp": ["DNS"]}
|
||||
monitored_traffic = {"icmp": ["NONE"], "tcp": [53,]}
|
||||
|
||||
pc: Computer = simulation.network.get_node_by_hostname("client_1")
|
||||
pc2: Computer = simulation.network.get_node_by_hostname("client_2")
|
||||
|
||||
@@ -39,13 +39,13 @@ def test_router_observation():
|
||||
# Add an ACL rule to the router
|
||||
router.acl.add_rule(
|
||||
action=ACLAction.DENY,
|
||||
protocol=IPProtocol.TCP,
|
||||
protocol=IPProtocol["TCP"],
|
||||
src_ip_address="10.0.0.1",
|
||||
src_wildcard_mask="0.0.0.1",
|
||||
dst_ip_address="10.0.0.2",
|
||||
dst_wildcard_mask="0.0.0.1",
|
||||
src_port=Port.HTTP,
|
||||
dst_port=Port.HTTP,
|
||||
src_port=Port["HTTP"],
|
||||
dst_port=Port["HTTP"],
|
||||
position=5,
|
||||
)
|
||||
# Observe the state using the RouterObservation instance
|
||||
|
||||
@@ -15,7 +15,7 @@ def env_with_ssh() -> PrimaiteGymEnv:
|
||||
env = PrimaiteGymEnv(DATA_MANIPULATION_CONFIG)
|
||||
env.agent.flatten_obs = False
|
||||
router: Router = env.game.simulation.network.get_node_by_hostname("router_1")
|
||||
router.acl.add_rule(ACLAction.PERMIT, src_port=Port.SSH, dst_port=Port.SSH, position=3)
|
||||
router.acl.add_rule(ACLAction.PERMIT, src_port=Port["SSH"], dst_port=Port["SSH"], position=3)
|
||||
return env
|
||||
|
||||
|
||||
|
||||
@@ -608,9 +608,9 @@ def test_firewall_acl_add_remove_rule_integration():
|
||||
assert firewall.internal_outbound_acl.acl[1].action.name == "DENY"
|
||||
assert firewall.internal_outbound_acl.acl[1].src_ip_address == IPv4Address("192.168.0.10")
|
||||
assert firewall.internal_outbound_acl.acl[1].dst_ip_address is None
|
||||
assert firewall.internal_outbound_acl.acl[1].dst_port == Port.DNS
|
||||
assert firewall.internal_outbound_acl.acl[1].src_port == Port.ARP
|
||||
assert firewall.internal_outbound_acl.acl[1].protocol == IPProtocol.ICMP
|
||||
assert firewall.internal_outbound_acl.acl[1].dst_port == Port["DNS"]
|
||||
assert firewall.internal_outbound_acl.acl[1].src_port == Port["ARP"]
|
||||
assert firewall.internal_outbound_acl.acl[1].protocol == IPProtocol["ICMP"]
|
||||
|
||||
env.step(4) # Remove ACL rule from Internal Outbound
|
||||
assert firewall.internal_outbound_acl.num_rules == 2
|
||||
@@ -620,9 +620,9 @@ def test_firewall_acl_add_remove_rule_integration():
|
||||
assert firewall.dmz_inbound_acl.acl[1].action.name == "DENY"
|
||||
assert firewall.dmz_inbound_acl.acl[1].src_ip_address == IPv4Address("192.168.10.10")
|
||||
assert firewall.dmz_inbound_acl.acl[1].dst_ip_address == IPv4Address("192.168.0.10")
|
||||
assert firewall.dmz_inbound_acl.acl[1].dst_port == Port.HTTP
|
||||
assert firewall.dmz_inbound_acl.acl[1].src_port == Port.HTTP
|
||||
assert firewall.dmz_inbound_acl.acl[1].protocol == IPProtocol.UDP
|
||||
assert firewall.dmz_inbound_acl.acl[1].dst_port == Port["HTTP"]
|
||||
assert firewall.dmz_inbound_acl.acl[1].src_port == Port["HTTP"]
|
||||
assert firewall.dmz_inbound_acl.acl[1].protocol == IPProtocol["UDP"]
|
||||
|
||||
env.step(6) # Remove ACL rule from DMZ Inbound
|
||||
assert firewall.dmz_inbound_acl.num_rules == 2
|
||||
@@ -632,9 +632,9 @@ def test_firewall_acl_add_remove_rule_integration():
|
||||
assert firewall.dmz_outbound_acl.acl[2].action.name == "DENY"
|
||||
assert firewall.dmz_outbound_acl.acl[2].src_ip_address == IPv4Address("192.168.10.10")
|
||||
assert firewall.dmz_outbound_acl.acl[2].dst_ip_address == IPv4Address("192.168.0.10")
|
||||
assert firewall.dmz_outbound_acl.acl[2].dst_port == Port.HTTP
|
||||
assert firewall.dmz_outbound_acl.acl[2].src_port == Port.HTTP
|
||||
assert firewall.dmz_outbound_acl.acl[2].protocol == IPProtocol.TCP
|
||||
assert firewall.dmz_outbound_acl.acl[2].dst_port == Port["HTTP"]
|
||||
assert firewall.dmz_outbound_acl.acl[2].src_port == Port["HTTP"]
|
||||
assert firewall.dmz_outbound_acl.acl[2].protocol == IPProtocol["TCP"]
|
||||
|
||||
env.step(8) # Remove ACL rule from DMZ Outbound
|
||||
assert firewall.dmz_outbound_acl.num_rules == 2
|
||||
@@ -644,9 +644,9 @@ def test_firewall_acl_add_remove_rule_integration():
|
||||
assert firewall.external_inbound_acl.acl[10].action.name == "DENY"
|
||||
assert firewall.external_inbound_acl.acl[10].src_ip_address == IPv4Address("192.168.20.10")
|
||||
assert firewall.external_inbound_acl.acl[10].dst_ip_address == IPv4Address("192.168.10.10")
|
||||
assert firewall.external_inbound_acl.acl[10].dst_port == Port.POSTGRES_SERVER
|
||||
assert firewall.external_inbound_acl.acl[10].src_port == Port.POSTGRES_SERVER
|
||||
assert firewall.external_inbound_acl.acl[10].protocol == IPProtocol.ICMP
|
||||
assert firewall.external_inbound_acl.acl[10].dst_port == Port["POSTGRES_SERVER"]
|
||||
assert firewall.external_inbound_acl.acl[10].src_port == Port["POSTGRES_SERVER"]
|
||||
assert firewall.external_inbound_acl.acl[10].protocol == IPProtocol["ICMP"]
|
||||
|
||||
env.step(10) # Remove ACL rule from External Inbound
|
||||
assert firewall.external_inbound_acl.num_rules == 1
|
||||
|
||||
@@ -42,7 +42,7 @@ def test_WebpageUnavailablePenalty(game_and_agent):
|
||||
|
||||
# Block the web traffic, check that failing to fetch the webpage yields a reward of -0.7
|
||||
router: Router = game.simulation.network.get_node_by_hostname("router")
|
||||
router.acl.add_rule(action=ACLAction.DENY, protocol=IPProtocol.TCP, src_port=Port.HTTP, dst_port=Port.HTTP)
|
||||
router.acl.add_rule(action=ACLAction.DENY, protocol=IPProtocol["TCP"], src_port=Port["HTTP"], dst_port=Port["HTTP"])
|
||||
agent.store_action(("NODE_APPLICATION_EXECUTE", {"node_id": 0, "application_id": 0}))
|
||||
game.step()
|
||||
assert agent.reward_function.current_reward == -0.7
|
||||
@@ -65,7 +65,7 @@ def test_uc2_rewards(game_and_agent):
|
||||
db_client.run()
|
||||
|
||||
router: Router = game.simulation.network.get_node_by_hostname("router")
|
||||
router.acl.add_rule(ACLAction.PERMIT, src_port=Port.POSTGRES_SERVER, dst_port=Port.POSTGRES_SERVER, position=2)
|
||||
router.acl.add_rule(ACLAction.PERMIT, src_port=Port["POSTGRES_SERVER"], dst_port=Port["POSTGRES_SERVER"], position=2)
|
||||
|
||||
comp = GreenAdminDatabaseUnreachablePenalty("client_1")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user