Skip to content

Commit

Permalink
Updated README and moved example code
Browse files Browse the repository at this point in the history
  • Loading branch information
hyakuhei committed Apr 28, 2021
1 parent dc396d1 commit db5c64f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 76 deletions.
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,34 @@ The `renderer.render()` function can toggle whether to include unimplemented thi

![PNG image showing graph created by exampleTree_simpleS3.py](images/example_simpleS3.png?raw=true "Simple S3")


## Prerequisites
# Prerequisites for Installation or Development
Your system needs an installed version of graphviz for rendering to work.
On MacOS this can be installed using `brew install graphviz`

See https://graphviz.org/download/ for other options.

## Instructions for setup
# Installation
attacktree is available in PyPI, we recommend installing in a virtualenv
```
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
deactivate
pip install attacktree
```

## Instructions for running
`exampleTree_simpleS3.py` is a simple model, containing only the current path. It can be run simply:
`S3Simple.py` is a simple model, containing only a single path in some hypothetical S3 threat model. It can be run simply:
```
source .venv/bin/activate
python3 exampleTree_simpleS3.py
deactivate
python3 examples/S3Simple.py
```

`exampleTree_complexS3.py` contains some potential blocking mitigations, things the security team might be considering but hasn't implemented.
`S3Complex.py` contains some potential blocking mitigations, things the security team might be considering but hasn't implemented yet.
```
source .venv/bin/activate
python3 exampleTree_complexS3.py
deactivate
python3 examples/S3Complex.py
```


## Methodology
In messing with this idea, I've found the easiest approach is to map the existing paths out first, without consideration for things you might implement. To see what that looks like checkout [exampleTree_simpleS3.py](exampleTree_simpleS3.py). After this one can either create a new tree with potential mitigations _or_ add them to the existing tree, for examples purposes I chose the former; [exampleTree_complexS3.py](exampleTree_complexS3.py).
In messing with this idea, I've found the easiest approach is to map the existing paths out first, without consideration for things you might implement. To see what that looks like checkout [examples/S3Simple.py](eexamples/S3Simple.py). After this one can either create a new tree with potential mitigations _or_ add them to the existing tree, for examples purposes I chose the former; [examples/S3Complex.py](examples/S3Complex.py).

See [Methodology.md](Methodology.md) for more thoughts on how this might work in practice.

Expand Down Expand Up @@ -72,7 +68,17 @@ The last line in each of those files is a call to render the tree:

I imagine that in general usage, we'd just want one model for a specific attacker; not a _simple and a _complex_ one. However, it's very useful to be able to see what those different graphs look like, as the latter models things we _could_ do but are currently *unimplemented* - for that reason the `render()` function has a parameter to enable or disable rendering of unimplemented paths. This way you can record everything in one tree (and maybe add that into version control, as a system of record) and render different outputs, one that shows your current reality, and one that shows your potential reality (hopefully improved).

Below is the output of running the _complex example with `renderUnimplemented=True`, note that if you set this to `False` the generated graph looks the same as `exampleTree_simpleS3.py`
Below is the output of running the _complex example with `renderUnimplemented=True`, note that if you set this to `False` the generated graph looks the same as `examples/S3Simple.py.py`

![PNG image showing graph created by exampleTree_complexS3.py](images/example_complexS3.png?raw=true "Complex S3")
![PNG image showing graph created by examples/S3Complex.py](images/example_complexS3.png?raw=true "Complex S3")


# Development

## Instructions for setup
```
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
deactivate
```
4 changes: 2 additions & 2 deletions examples/exampleTree_complexS3.py → examples/S3Complex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from models import Action, Block, Detect, Discovery, Edge, Node
from renderer import Renderer
from attacktree.models import Action, Block, Detect, Discovery, Edge, Node
from attacktree.renderer import Renderer

with Renderer(root = "Reality", goal= "Attacker gets data from bucket") as graph:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from models import Action, Block, Detect, Discovery, Edge, Node
from renderer import Renderer
from attacktree.models import Action, Block, Detect, Discovery, Edge, Node
from attacktree.renderer import Renderer

with Renderer(root = "Reality", goal= "Attacker gets data from bucket") as graph:

Expand Down
12 changes: 5 additions & 7 deletions examples/exampleTree_simpleS3.py → examples/S3Simple.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from models import Action, Block, Detect, Discovery, Edge, Node
import renderer

if __name__ == "__main__":
root = Node(label="Reality")
goal = Node(label="Attacker gets data from bucket")
from attacktree.models import Action, Block, Detect, Discovery, Edge, Node
from attacktree.renderer import Renderer

with Renderer(root = "Reality", goal= "Attacker gets data from bucket") as graph:

apiCache = Action(
label="Search API Caches",
chain="recon",
Expand All @@ -13,7 +11,7 @@
objective="Discover bucket paths",
pSuccess=1.0
)
root.createEdge(apiCache,label="#Yolosec")
graph.root.connectTo(apiCache, label="#Yolosec")

s3urls = Discovery(
label="S3 Urls",
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = attacktree
version = 0.0.162
version = 0.0.163
author = hyakuhei
author_email = hyakuhei@gmail.com
summary = Build, analyize and render attack trees
Expand Down
48 changes: 0 additions & 48 deletions style.json

This file was deleted.

0 comments on commit db5c64f

Please sign in to comment.