Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/CyberBattleSim
Path: blob/main/notebooks/toyctf-blank.py
597 views
1
# ---
2
# jupyter:
3
# jupytext:
4
# formats: py:percent,ipynb
5
# text_representation:
6
# extension: .py
7
# format_name: percent
8
# format_version: '1.3'
9
# jupytext_version: 1.16.4
10
# kernelspec:
11
# display_name: Python 3 (ipykernel)
12
# language: python
13
# name: python3
14
# ---
15
16
# %% [markdown]
17
# pyright: reportUnusedExpression=false
18
19
# %% [markdown]
20
# Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.
21
#
22
# # Capture the Flag Toy Example - Interactive (Human player)
23
24
# %% [markdown]
25
# This is a blank instantiaion of the Capture The Flag network to be played interactively by a human player (not via the gym envrionment).
26
# The interface exposed to the attacker is given by the following commands:
27
# - c2.print_all_attacks()
28
# - c2.run_attack(node, attack_id)
29
# - c2.run_remote_attack(source_node, target_node, attack_id)
30
# - c2.connect_and_infect(source_node, target_node, port_name, credential_id)
31
32
# %%
33
import sys, logging
34
import cyberbattle.simulation.model as model
35
import cyberbattle.simulation.commandcontrol as commandcontrol
36
import cyberbattle.samples.toyctf.toy_ctf as ctf
37
import plotly.offline as plo
38
39
plo.init_notebook_mode(connected=True) # type: ignore
40
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(levelname)s: %(message)s")
41
# %matplotlib inline
42
43
# %%
44
network = model.create_network(ctf.nodes)
45
env = model.Environment(network=network, vulnerability_library=dict([]), identifiers=ctf.ENV_IDENTIFIERS)
46
env
47
48
# %%
49
env.plot_environment_graph()
50
51
# %%
52
c2 = commandcontrol.CommandControl(env)
53
dbg = commandcontrol.EnvironmentDebugging(c2)
54
55
56
def plot():
57
dbg.plot_discovered_network()
58
c2.print_all_attacks()
59
60
61
plot()
62
63