|
12 | 12 | import subprocess |
13 | 13 | import sys |
14 | 14 |
|
15 | | -# Setup config for this package |
16 | | -logger_config = config_parser.config['logger'] |
17 | | -logging.config.dictConfig(logger_config) |
18 | | - |
19 | | -_log = logging.getLogger(__name__) |
20 | | - |
21 | | -# Read arguments for DockerENT application |
22 | | -parser = argparse.ArgumentParser( |
23 | | - prog='Find the vulnerabilities hidden in your running container(s).' |
24 | | -) |
25 | | - |
26 | | -docker_args_group = parser.add_argument_group() |
27 | | -docker_args_group.add_argument( |
28 | | - '-d', |
29 | | - '--docker', |
30 | | - nargs='?', |
31 | | - dest='docker_container', |
32 | | - const='all', |
33 | | - help='Run scan against the running container.') |
34 | | -docker_args_group.add_argument( |
35 | | - '-p', |
36 | | - '--plugins', |
37 | | - nargs='?', |
38 | | - dest='docker_plugins', |
39 | | - const='all', |
40 | | - help='Run scan with only specified plugins.') |
41 | | - |
42 | | -docker_nw_args_group = parser.add_argument_group() |
43 | | -docker_nw_args_group.add_argument( |
44 | | - '-d-nw', |
45 | | - '--docker-network', |
46 | | - nargs='?', |
47 | | - dest='docker_network', |
48 | | - const='all', |
49 | | - help='Run scan against running docker-network.') |
50 | | -docker_args_group.add_argument( |
51 | | - '-p-nw', |
52 | | - '--nw-plugins', |
53 | | - nargs='?', |
54 | | - dest='docker_nw_plugins', |
55 | | - const='all', |
56 | | - help='Run scan with only specified plugins.') |
57 | | - |
58 | | -parser.add_argument( |
59 | | - '-w', |
60 | | - '--web-app', |
61 | | - dest='web_app', |
62 | | - action='store_true', |
63 | | - default=False, |
64 | | - help='Run DockerENT in WebApp mode. ' |
65 | | - 'If this parameter is enabled, other command line flags will be ignored.' |
66 | | -) |
67 | | - |
68 | | -parser.add_argument( |
69 | | - '-n', |
70 | | - '--process', |
71 | | - nargs='?', |
72 | | - dest='process_count', |
73 | | - default=2, |
74 | | - type=int, |
75 | | - help='Run scans in parallel (Process pool count).' |
76 | | -) |
77 | | - |
78 | | -parser.add_argument( |
79 | | - '-a', |
80 | | - '--audit', |
81 | | - dest='audit', |
82 | | - action='store_true', |
83 | | - default=False, |
84 | | - help='Flag to check weather to audit results or not.' |
85 | | -) |
86 | | - |
87 | | -output_plugin = parser.add_argument_group() |
88 | | -output_plugin.add_argument( |
89 | | - '-o', |
90 | | - '--output', |
91 | | - nargs='?', |
92 | | - dest='output', |
93 | | - default='file', |
94 | | - type=str, |
95 | | - help='Output plugin to write data to.' |
96 | | -) |
97 | | - |
98 | | -args = parser.parse_args() |
99 | | - |
100 | | -process_count = args.process_count |
101 | | -output = args.output |
102 | | -audit = args.audit |
103 | | -webapp = args.web_app |
104 | | - |
105 | | -docker_containers = args.docker_container |
106 | | -docker_plugins = args.docker_plugins |
107 | | - |
108 | | -docker_nws = args.docker_network |
109 | | -docker_nw_plugins = args.docker_nw_plugins |
110 | | - |
111 | | - |
112 | | -# Register Signal Handler for graceful exit in case of Web application |
113 | | -def sigterm_handler(_signo, _stack_frame): |
114 | | - """Signal handler.""" |
115 | | - _log.info("Thanks for using DockerENT") |
116 | | - sys.exit(0) |
117 | | - |
118 | | - |
119 | | -signal.signal(signal.SIGINT, sigterm_handler) |
120 | | - |
121 | | - |
122 | | -# Start DockerENT |
123 | | -# If webapp, start Streamlit else cli application. |
124 | | -if webapp: |
125 | | - _log.info('Starting web application ...') |
126 | | - |
127 | | - sys.path.append(os.path.abspath(os.path.join('..'))) |
128 | | - web_app_cmd = "streamlit run web_app.py" |
129 | | - |
130 | | - with subprocess.Popen(web_app_cmd.split(" ")) as web_process: |
131 | | - _log.info(web_process.stdout.read()) |
132 | | - |
133 | | -else: |
134 | | - controller.main(docker_containers=docker_containers, |
135 | | - docker_plugins=docker_plugins, |
136 | | - docker_nws=docker_nws, |
137 | | - docker_nw_plugins=docker_nw_plugins, |
138 | | - process_count=process_count, |
139 | | - audit=audit, |
140 | | - output=output) |
| 15 | + |
| 16 | +def start(): |
| 17 | + # Setup config for this package |
| 18 | + logger_config = config_parser.config['logger'] |
| 19 | + logging.config.dictConfig(logger_config) |
| 20 | + |
| 21 | + _log = logging.getLogger(__name__) |
| 22 | + |
| 23 | + # Read arguments for DockerENT application |
| 24 | + parser = argparse.ArgumentParser( |
| 25 | + prog='Find the vulnerabilities hidden in your running container(s).' |
| 26 | + ) |
| 27 | + |
| 28 | + docker_args_group = parser.add_argument_group() |
| 29 | + docker_args_group.add_argument( |
| 30 | + '-d', |
| 31 | + '--docker', |
| 32 | + nargs='?', |
| 33 | + dest='docker_container', |
| 34 | + const='all', |
| 35 | + help='Run scan against the running container.') |
| 36 | + docker_args_group.add_argument( |
| 37 | + '-p', |
| 38 | + '--plugins', |
| 39 | + nargs='?', |
| 40 | + dest='docker_plugins', |
| 41 | + const='all', |
| 42 | + help='Run scan with only specified plugins.') |
| 43 | + |
| 44 | + docker_nw_args_group = parser.add_argument_group() |
| 45 | + docker_nw_args_group.add_argument( |
| 46 | + '-d-nw', |
| 47 | + '--docker-network', |
| 48 | + nargs='?', |
| 49 | + dest='docker_network', |
| 50 | + const='all', |
| 51 | + help='Run scan against running docker-network.') |
| 52 | + docker_args_group.add_argument( |
| 53 | + '-p-nw', |
| 54 | + '--nw-plugins', |
| 55 | + nargs='?', |
| 56 | + dest='docker_nw_plugins', |
| 57 | + const='all', |
| 58 | + help='Run scan with only specified plugins.') |
| 59 | + |
| 60 | + parser.add_argument( |
| 61 | + '-w', |
| 62 | + '--web-app', |
| 63 | + dest='web_app', |
| 64 | + action='store_true', |
| 65 | + default=False, |
| 66 | + help='Run DockerENT in WebApp mode. ' |
| 67 | + 'If this parameter is enabled, other command line flags will be ignored.' |
| 68 | + ) |
| 69 | + |
| 70 | + parser.add_argument( |
| 71 | + '-n', |
| 72 | + '--process', |
| 73 | + nargs='?', |
| 74 | + dest='process_count', |
| 75 | + default=2, |
| 76 | + type=int, |
| 77 | + help='Run scans in parallel (Process pool count).' |
| 78 | + ) |
| 79 | + |
| 80 | + parser.add_argument( |
| 81 | + '-a', |
| 82 | + '--audit', |
| 83 | + dest='audit', |
| 84 | + action='store_true', |
| 85 | + default=False, |
| 86 | + help='Flag to check weather to audit results or not.' |
| 87 | + ) |
| 88 | + |
| 89 | + output_plugin = parser.add_argument_group() |
| 90 | + output_plugin.add_argument( |
| 91 | + '-o', |
| 92 | + '--output', |
| 93 | + nargs='?', |
| 94 | + dest='output', |
| 95 | + default='file', |
| 96 | + type=str, |
| 97 | + help='Output plugin to write data to.' |
| 98 | + ) |
| 99 | + |
| 100 | + args = parser.parse_args() |
| 101 | + |
| 102 | + process_count = args.process_count |
| 103 | + output = args.output |
| 104 | + audit = args.audit |
| 105 | + webapp = args.web_app |
| 106 | + |
| 107 | + docker_containers = args.docker_container |
| 108 | + docker_plugins = args.docker_plugins |
| 109 | + |
| 110 | + docker_nws = args.docker_network |
| 111 | + docker_nw_plugins = args.docker_nw_plugins |
| 112 | + |
| 113 | + # Register Signal Handler for graceful exit in case of Web application |
| 114 | + |
| 115 | + def sigterm_handler(_signo, _stack_frame): |
| 116 | + """Signal handler.""" |
| 117 | + _log.info("Thanks for using DockerENT") |
| 118 | + sys.exit(0) |
| 119 | + |
| 120 | + signal.signal(signal.SIGINT, sigterm_handler) |
| 121 | + |
| 122 | + # Start DockerENT |
| 123 | + # If webapp, start Streamlit else cli application. |
| 124 | + if webapp: |
| 125 | + _log.info('Starting web application ...') |
| 126 | + |
| 127 | + sys.path.append(os.path.abspath(os.path.join('..'))) |
| 128 | + web_app_cmd = "streamlit run web_app.py" |
| 129 | + |
| 130 | + with subprocess.Popen(web_app_cmd.split(" ")) as web_process: |
| 131 | + _log.info(web_process.stdout.read()) |
| 132 | + |
| 133 | + else: |
| 134 | + controller.main(docker_containers=docker_containers, |
| 135 | + docker_plugins=docker_plugins, |
| 136 | + docker_nws=docker_nws, |
| 137 | + docker_nw_plugins=docker_nw_plugins, |
| 138 | + process_count=process_count, |
| 139 | + audit=audit, |
| 140 | + output=output) |
| 141 | + |
| 142 | + |
| 143 | +start() |
0 commit comments