def __init__(self,
                 ep: EnvironmentBounds,
                 qm: Optional[np.ndarray] = None) -> None:

        self.state_space = w.HashEncoding(
            ep,
            [
                w.Feature_active_node_properties(ep),
                w.Feature_active_node_age(ep)
                # w.Feature_actions_tried_at_node(ep)
            ],
            7000)

        # NOTE: For debugging purpose it's convenient instead to use
        # Ravel encoding for node properties
        self.state_space_debugging = w.RavelEncoding(
            ep,
            [
                w.HashEncoding(
                    ep,
                    [
                        # Feature_discovered_node_count(),
                        # Feature_discovered_credential_count(),
                        w.Feature_discovered_ports_sliding(ep),
                        w.Feature_discovered_nodeproperties_sliding(ep),
                        w.Feature_discovered_notowned_node_count(ep, 3),
                    ],
                    100),
                w.Feature_active_node_properties(ep)
            ])

        self.action_space = w.AbstractAction(ep)

        super().__init__("attack_at_source", self.state_space,
                         self.action_space, qm)
示例#2
0
    def __init__(self, ep: EnvironmentBounds):
        self.ep = ep

        self.global_features = w.ConcatFeatures(
            ep,
            [
                # w.Feature_discovered_node_count(ep),
                # w.Feature_owned_node_count(ep),
                w.Feature_discovered_notowned_node_count(ep, None)

                # w.Feature_discovered_ports(ep),
                # w.Feature_discovered_ports_counts(ep),
                # w.Feature_discovered_ports_sliding(ep),
                # w.Feature_discovered_credential_count(ep),
                # w.Feature_discovered_nodeproperties_sliding(ep),
            ])

        self.node_specific_features = w.ConcatFeatures(
            ep,
            [
                # w.Feature_actions_tried_at_node(ep),
                w.Feature_success_actions_at_node(ep),
                w.Feature_failed_actions_at_node(ep),
                w.Feature_active_node_properties(ep),
                w.Feature_active_node_age(ep)
                # w.Feature_active_node_id(ep)
            ])

        self.state_space = w.ConcatFeatures(
            ep, self.global_features.feature_selection +
            self.node_specific_features.feature_selection)

        self.action_space = w.AbstractAction(ep)
    def __init__(self, ep: EnvironmentBounds, qm: Optional[np.ndarray] = None):
        self.ep = ep

        self.state_space = w.HashEncoding(
            ep,
            [
                # Feature_discovered_node_count(),
                # Feature_discovered_credential_count(),
                w.Feature_discovered_ports_sliding(ep),
                w.Feature_discovered_nodeproperties_sliding(ep),
                w.Feature_discovered_notowned_node_count(ep, 3)
            ],
            5000
        )  # should not be too small, pick something big to avoid collision

        self.action_space = w.RavelEncoding(
            ep, [w.Feature_active_node_properties(ep)])

        super().__init__("attack_source", self.state_space, self.action_space,
                         qm)
示例#4
0
if debugging:
    print(f"port_count = {ep.port_count}, property_count = {ep.property_count}")

    gym_env.environment
    # training_env.environment.plot_environment_graph()
    gym_env.environment.network.nodes
    gym_env.action_space
    gym_env.action_space.sample()
    gym_env.observation_space.sample()
    o0 = gym_env.reset()
    o_test, r, d, i = gym_env.step(gym_env.sample_valid_action())
    o0 = gym_env.reset()

    o0.keys()

    fe_example = w.RavelEncoding(ep, [w.Feature_active_node_properties(ep), w.Feature_discovered_node_count(ep)])
    a = w.StateAugmentation(o0)
    w.Feature_discovered_ports(ep).get(a, None)
    fe_example.encode_at(a, 0)

# %%
# Evaluate a random agent that opportunistically exploits
# credentials gathere in its local cache
credlookup_run = learner.epsilon_greedy_search(
    gym_env,
    ep,
    learner=rca.CredentialCacheExploiter(),
    episode_count=10,
    iteration_count=iteration_count,
    epsilon=0.90,
    render=False,
o_test, r, d, i = cyberbattlechain_10.step(
    cyberbattlechain_10.sample_valid_action())
o0 = cyberbattlechain_10.reset()

o0.keys()

# %%
ep = w.EnvironmentBounds.of_identifiers(
    maximum_node_count=22,
    maximum_total_credentials=22,
    identifiers=cyberbattlechain_10.identifiers)

print(f"port_count = {ep.port_count}, property_count = {ep.property_count}")

fe_example = w.RavelEncoding(ep, [
    w.Feature_active_node_properties(ep),
    w.Feature_discovered_node_count(ep)
])
a = w.StateAugmentation(o0)
w.Feature_discovered_ports(ep).get(a, None)
fe_example.encode_at(a, 0)

iteration_count = 9000
training_episode_count = 50
eval_episode_count = 5

# %%
random_run = learner.epsilon_greedy_search(
    cyberbattlechain_10,
    ep,
    learner=learner.RandomPolicy(),