-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove heavy ipynb notebooks from main branch (#147)
* chore: Update publish_benchmarks.sh script to create benchmark directory before copying files Remove heavy notebooks chore: Remove trailing-whitespace hook and update check-yaml hook configuration * chore: Update notebook_benchmark parameters for different environments Adjust the parameters for the notebook_benchmark script to run benchmarks on different environments. This includes changing the gymid, training_episode_count, eval_episode_count, maximum_total_credentials, and plots_dir values for each environment. Co-authored-by: William Blum <[email protected]> --------- Co-authored-by: William Blum <[email protected]>
- Loading branch information
Showing
44 changed files
with
1,863 additions
and
1,402,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# --- | ||
# jupyter: | ||
# jupytext: | ||
# formats: ipynb,py:percent | ||
# text_representation: | ||
# extension: .py | ||
# format_name: percent | ||
# format_version: '1.3' | ||
# jupytext_version: 1.16.4 | ||
# kernelspec: | ||
# display_name: cybersim | ||
# language: python | ||
# name: cybersim | ||
# --- | ||
|
||
# %% [markdown] | ||
# pyright: reportUnusedExpression=false | ||
|
||
# %% [markdown] | ||
# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. | ||
# | ||
# # Command and Control interface | ||
# This notebooks shows how to interact with the command&control server to observe the environment and initiate actions on the nodes where the attacker client is installed. | ||
|
||
# %% | ||
import networkx as nx | ||
from tabulate import tabulate | ||
import cyberbattle.simulation.model as model | ||
import cyberbattle.simulation.actions as actions | ||
import cyberbattle.simulation.commandcontrol as commandcontrol | ||
import importlib | ||
|
||
importlib.reload(model) | ||
importlib.reload(actions) | ||
importlib.reload(commandcontrol) | ||
import plotly.offline as plo | ||
|
||
plo.init_notebook_mode(connected=True) # type: ignore | ||
# %matplotlib inline | ||
|
||
# %% [markdown] | ||
# We first create a simulation environment from a randomly generated network graph. | ||
|
||
# %% | ||
g = nx.erdos_renyi_graph(35, 0.05, directed=True) | ||
g = model.assign_random_labels(g) | ||
env = model.Environment(network=g, vulnerability_library=dict([]), identifiers=model.SAMPLE_IDENTIFIERS) | ||
|
||
# %% [markdown] | ||
# We create the `CommandControl` object used to the environment and execute actions, and plot the graph explored so far. | ||
# | ||
|
||
# %% | ||
c = commandcontrol.CommandControl(env) | ||
|
||
# %% | ||
c.plot_nodes() | ||
print("Nodes disovered so far: " + str(c.list_nodes())) | ||
starting_node = c.list_nodes()[0]["id"] | ||
|
||
# %% [markdown] | ||
# For debugging purpose it's also convient to view the internals of the environment via the `EnvironmentDebugging` object. For instance we can use it to plot the entire graph, including nodes that were not discovered yet by the attacker. | ||
|
||
# %% | ||
dbg = commandcontrol.EnvironmentDebugging(c) | ||
|
||
# %% | ||
env.plot_environment_graph() | ||
print(nx.info(env.network)) # type: ignore | ||
|
||
# %% | ||
print(tabulate(c.list_all_attacks(), {})) | ||
|
||
# %% | ||
outcome = c.run_attack(starting_node, "RecentlyAccessedMachines") | ||
outcome | ||
|
||
# %% | ||
c.plot_nodes() | ||
|
||
# %% | ||
print(tabulate(c.list_nodes(), {})) | ||
|
||
# %% | ||
print(tabulate(c.list_all_attacks(), {})) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# --- | ||
# jupyter: | ||
# jupytext: | ||
# formats: py:percent,ipynb | ||
# text_representation: | ||
# extension: .py | ||
# format_name: percent | ||
# format_version: '1.3' | ||
# jupytext_version: 1.16.4 | ||
# kernelspec: | ||
# display_name: cybersim | ||
# language: python | ||
# name: cybersim | ||
# --- | ||
|
||
# %% [markdown] magic_args="[markdown]" | ||
# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. | ||
|
||
# %% | ||
# %% | ||
import plotly.io.orca | ||
import gymnasium as gym | ||
import numpy | ||
from typing import cast | ||
from cyberbattle._env.cyberbattle_env import CyberBattleEnv | ||
|
||
# %% | ||
# %matplotlib inline | ||
plotly.io.orca.config.executable = "~/.npm-packages/bin/orca" # type: ignore | ||
|
||
# %% | ||
from cyberbattle._env.cyberbattle_env import AttackerGoal | ||
from cyberbattle._env.option_wrapper import ContextWrapper, random_options | ||
|
||
# %% | ||
rnd = numpy.random.RandomState(13) | ||
|
||
# %% | ||
env = cast(CyberBattleEnv, gym.make("CyberBattleChain-v0", size=10, attacker_goal=AttackerGoal(reward=4000))) | ||
env = ContextWrapper(env, options=random_options) | ||
|
||
# %% | ||
s, _ = env.reset() | ||
env.render() | ||
|
||
# %% | ||
n = 10 | ||
|
||
# %% | ||
for t in range(100): | ||
s, r, done, _, info = env.step() | ||
if r > 0: | ||
print(r, done, info["action"]) | ||
# env.render() | ||
if done: | ||
if n == 0: | ||
break | ||
n -= r > 0 | ||
env.reset() |
Oops, something went wrong.