/
cli_parser.py
245 lines (209 loc) · 11.4 KB
/
cli_parser.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
from ScoutSuite import DEFAULT_REPORT_DIR
class ScoutSuiteArgumentParser:
def __init__(self):
self.parser = argparse.ArgumentParser()
# People will still be able to use the old --provider syntax
self.parser.add_argument("--provider", action='store_true', dest='sinkhole', help=argparse.SUPPRESS)
self.common_providers_args_parser = argparse.ArgumentParser(add_help=False)
self.subparsers = self.parser.add_subparsers(title="The provider you want to run scout against",
dest="provider")
self._init_common_args_parser()
self._init_aws_parser()
self._init_gcp_parser()
self._init_azure_parser()
def _init_aws_parser(self):
aws_parser = self.subparsers.add_parser("aws",
parents=[self.common_providers_args_parser],
help="Run Scout against an Amazon web Services account")
parser = aws_parser.add_argument_group('Authentication parameters')
parser.add_argument('-p',
'--profile',
dest='profile',
default=None,
help='Name of the profile')
parser = aws_parser.add_argument_group('Additional arguments')
parser.add_argument('-r',
'--regions',
dest='regions',
default=[],
nargs='+',
help='Name of regions to run the tool in, defaults to all')
parser.add_argument('--vpc',
dest='vpc',
default=[],
nargs='+',
help='Name of VPC to run the tool in, defaults to all')
parser.add_argument('--ip-ranges',
dest='ip_ranges',
default=[],
nargs='+',
help='Config file(s) that contain your known IP ranges')
parser.add_argument('--ip-ranges-name-key',
dest='ip_ranges_name_key',
default='name',
help='Name of the key containing the display name of a known CIDR')
def _init_gcp_parser(self):
gcp_parser = self.subparsers.add_parser("gcp",
parents=[self.common_providers_args_parser],
help="Run Scout against a Google Cloud Platform account")
parser = gcp_parser.add_argument_group('Authentication modes')
gcp_auth_modes = parser.add_mutually_exclusive_group(required=True)
gcp_auth_modes.add_argument('-u',
'--user-account',
action='store_true',
help='Run Scout with a Google Account')
gcp_auth_modes.add_argument('-s',
'--service-account',
action='store',
metavar="KEY_FILE",
help='Run Scout with a Google Service Account with the specified '
'Google Service Account Application Credentials file')
gcp_scope = gcp_parser.add_argument_group('Additional arguments')
gcp_scope.add_argument('--project-id',
action='store',
help='ID of the GCP Project to scan')
gcp_scope.add_argument('--folder-id',
action='store',
help='ID of the GCP Folder to scan')
gcp_scope.add_argument('--organization-id',
action='store',
help='ID of the GCP Organization to scan')
gcp_scope.add_argument('--all-projects',
action='store_true',
help='Scan all of the accessible projects')
def _init_azure_parser(self):
parser = self.subparsers.add_parser("azure",
parents=[self.common_providers_args_parser],
help="Run Scout against a Microsoft Azure account")
azure_parser = parser.add_argument_group('Authentication modes')
azure_auth_params = parser.add_argument_group('Authentication parameters')
azure_auth_modes = azure_parser.add_mutually_exclusive_group(required=True)
azure_auth_modes.add_argument('-c',
'--cli',
action='store_true',
help='Run Scout using configured azure-cli credentials')
azure_auth_modes.add_argument('-m',
'--msi',
action='store_true',
help='Run Scout with Managed Service Identity')
azure_auth_modes.add_argument('-s',
'--service-principal',
action='store_true',
help='Run Scout with an Azure Service Principal')
azure_auth_params.add_argument('--tenant',
action='store',
dest='tenant_id',
help='Tenant ID of the service principal')
azure_auth_params.add_argument('--subscription',
action='store',
dest='subscription_id',
help='Subscription ID of the service principal')
azure_auth_params.add_argument('--client-id',
action='store',
dest='client_id',
help='Client ID of the service principal')
azure_auth_params.add_argument('--client-secret',
action='store',
dest='client_secret',
help='Client of the service principal')
azure_auth_modes.add_argument('--file-auth',
action='store',
type=argparse.FileType('r'),
dest='file_auth',
metavar="FILE",
help='Run Scout with the specified credential file')
azure_auth_modes.add_argument('--user-account',
action='store_true',
help='Run Scout with user credentials')
azure_auth_params.add_argument('-u',
'--username',
action='store',
default=None,
dest='username',
help='Username of the Azure account')
azure_auth_params.add_argument('-p',
'--password',
action='store',
default=None,
dest='password',
help='Password of the Azure account')
def _init_common_args_parser(self):
parser = self.common_providers_args_parser.add_argument_group('Scout Arguments')
parser.add_argument('-f',
'--force',
dest='force_write',
default=False,
action='store_true',
help='Overwrite existing files')
parser.add_argument('-l', '--local',
dest='fetch_local',
default=False,
action='store_true',
help='Use local data previously fetched and re-run the analysis.')
parser.add_argument('--debug',
dest='debug',
default=False,
action='store_true',
help='Print the stack trace when exception occurs')
parser.add_argument('--resume',
dest='resume',
default=False,
action='store_true',
help='Complete a partial (throttled) run')
parser.add_argument('--update',
dest='update',
default=False,
action='store_true',
help='Reload all the existing data and only overwrite data in scope for this run')
parser.add_argument('--ruleset',
dest='ruleset',
default='default.json',
nargs='?',
help='Set of rules to be used during the analysis.')
parser.add_argument('--no-browser',
dest='no_browser',
default=False,
action='store_true',
help='Do not automatically open the report in the browser.')
parser.add_argument('--thread-config',
dest='thread_config',
type=int,
default=4,
help='Level of multi-threading wanted [1-5]; defaults to 4.')
parser.add_argument('--report-dir',
dest='report_dir',
default=DEFAULT_REPORT_DIR,
help='Path of the Scout report.')
parser.add_argument('--timestamp',
dest='timestamp',
default=False,
nargs='?',
help='Timestamp added to the name of the report (default is current time in UTC).')
parser.add_argument('--services',
dest='services',
default=[],
nargs='+',
help='Name of in-scope services.')
parser.add_argument('--skip',
dest='skipped_services',
default=[],
nargs='+',
help='Name of out-of-scope services.')
parser.add_argument('--exceptions',
dest='exceptions',
default=[None],
nargs='+',
help='Exception file to use during analysis.')
def parse_args(self, args=None):
args = self.parser.parse_args(args)
# Cannot simply use required for backward compatibility
if not args.provider:
self.parser.error('You need to input a provider')
# If local analysis, overwrite results
if args.__dict__.get('fetch_local'):
args.force_write = True
return args