-
Notifications
You must be signed in to change notification settings - Fork 0
/
daca.py
136 lines (108 loc) · 5.02 KB
/
daca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3
### System modules ###
import logging
import click
from pathlib import Path
### Local modules ###
from daca import *
from daca.scenariorunner import ScenarioRunner
### Global Variables ###
BANNER='''
___ ___ ___ ___
/\ \ /\ \ /\ \ /\ \
/::\ \ /::\ \ /::\ \ /::\ \
/:/\:\ \ /:/\:\ \ /:/\:\ \ /:/\:\ \
/:/ \:\__\ /::\~\:\ \ /:/ \:\ \ /::\~\:\ \
/:/__/ \:|__| /:/\:\ \:\__\ /:/__/ \:\__\ /:/\:\ \:\__\
\:\ \ /:/ / \/__\:\/:/ / \:\ \ \/__/ \/__\:\/:/ /
\:\ /:/ / \::/ / \:\ \ \::/ /
\:\/:/ / /:/ / \:\ \ /:/ /
\::/__/ /:/ / \:\__\ /:/ /
~~ \/__/ \/__/ \/__/
v0.1 (https://github.com/Korving-F/DACA)
'''
### Setup logging ###
logger = logging.getLogger('daca')
def set_logging(debug):
'''
Set logging parameters.
Keyword arguments:
debug -- enable debug level logging (default False)
'''
logger.setLevel(logging.DEBUG if debug else logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter('%(asctime)s [ %(filename)s:%(lineno)s %(funcName)s %(levelname)s ] %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
### CLI Application ###
@click.group()
@click.option('--debug', is_flag=True, help='Set debug logging level.')
def main(debug):
set_logging(debug)
@main.command()
@click.option('--path', '-p', required=True, help='''Path to scenario definition file.
Give "*" to delete all objects DACA can find.
Prompts for confirmation.''', type=str)
def destroy(path):
"""
Cleans-up all scenario related objects like VMs/Docker images.
"""
logger.debug(f"Destroying scenario with path: {path}")
click.echo("Destroying")
#TODO Implement cleanup
@main.command()
@click.option('--path', '-p', default='scenarios', help='Path to scenario definition file.', type=str)
@click.option('--id', '-i', help='ID of the scenario that needs to be displayed.', type=int)
@click.option('--workingdir', '-w', default='data', help='Working directory where all files are stored (e.g. VMs).', type=str)
@click.option('--datapath', '-d', help='Path where extracted data samples should be stored.', type=str)
@click.option('--interactive', is_flag=True, help='Run the scenario interactively')
#@click.option('--parralelize', '-p', help='Run the scenarios in parrlalel', type=int) # TODO
def run(path, id, workingdir, datapath, interactive):
"""
Run the selected scenario.
Download and build the infrastructure for the selected scenario.
E.g. VMs, Docker containers or cloud-based infrastructure used as attack, server or
client machines as well as supportive components to collect data.
"""
logger.debug(f"Running scenario with path: {path}")
logger.debug(f"Storing data at path: {datapath}")
click.echo("[+] Starting execution.")
runner = ScenarioRunner(scenario_path=Path(path).absolute(),
working_directory=Path(workingdir).absolute(),
interactive=interactive)
if id != None:
runner.set_scenario_by_id(id)
if runner.scenario is None:
click.echo("[!] No scenario is set to build. Please point to a file or use the '--id' flag.")
exit(1)
runner.run()
@main.command()
@click.option('--path', '-p', default='scenarios', help='Path to scenario definition file or directory.', type=str)
@click.option('--id', '-i', help='ID of the scenario that needs to be displayed.', type=int)
@click.option('--summarize', '-s', is_flag=True, help='Summarize scenario runthrough (e.g. # of cycles / approximate running time)')
@click.option('--list', '-l', is_flag=True, help='List all available scenarios')
def info(path, id, summarize, list):
"""
Display information and metadata on available scenario(s).
"""
logger.debug(f"Displaying information on scenario with given path: {path}")
if list == True:
logger.debug(f"Listing avaiable scenarions {Path(path).absolute()}")
runner = ScenarioRunner(Path(path).absolute())
runner.list_scenarios()
if summarize == True:
logger.debug(f"Summarizing scenario: {Path(path).absolute()}")
runner = ScenarioRunner(Path(path).absolute())
if id != None:
runner.set_scenario_by_id(id)
if runner.scenario is None:
click.echo("[!] No scenario is set to summarize. Please point to a file or use the '--id' flag.")
exit(1)
runner.summarize()
# Function to force print help section
#def print_help():
# ctx = click.get_current_context()
# click.echo(ctx.get_help())
if __name__ == '__main__':
print(BANNER)
main()