-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.py
More file actions
322 lines (307 loc) · 10.3 KB
/
main.py
File metadata and controls
322 lines (307 loc) · 10.3 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#!/usr/bin/env python3
from __future__ import annotations
from argparse import (
ArgumentParser as Parser,
Namespace
)
from lib.services import (
UserController,
ComputerController,
PolicyController,
JAMFService
)
from lib.preprocess import Preprocessor, checkAzureUsers
from lib.presentation import log_error, log_info
import json
import os
from datetime import datetime
def main():
parser: Parser = Parser(
description="JAMFhound: A BloodHound generic data collector for JAMF tenants.",
add_help=True
)
parser.add_argument(
"--username", "--username", "-u",
dest="username",
type=str,
default="",
action="store",
help="Username for authentication"
)
parser.add_argument(
"--password", "-p",
dest="password",
type=str,
default="",
action="store",
help="Password for authentication"
)
parser.add_argument(
"--token", "-t",
dest="token",
type=str,
default="",
action="store",
help="Token file to use in place of credentials"
)
parser.add_argument(
"--target", "--api", "--url", "-a",
dest="baseUrl",
type=str,
default="https://tenant.jamfcloud.com",
action="store",
help="Base url of target API"
)
parser.add_argument(
"--permission", "-permission", "-me ",
dest="getMyPermissions",
default=False,
action="store_true",
help="Display current users permissions"
)
parser.add_argument(
"--accounts", "-accounts",
dest="getAccountsPermissions",
default=False,
action="store_true",
help="Display all account permissions"
)
parser.add_argument(
"--account", "-account",
dest="getAccountPermissions",
default="",
action="store",
help="Display account permissions by name"
)
parser.add_argument(
"--users", "-users",
dest="getUsersPermissions",
default=False,
action="store_true",
help="Display all user permissions"
)
parser.add_argument(
"--user", "-user",
dest="getUserPermissions",
default="",
action="store",
help="Display user permissions by name"
)
parser.add_argument(
"--site", "--site", "-s",
dest="siteFilter",
type=str,
default="all",
action="store",
help="Filter site permissions"
)
parser.add_argument(
"--sites", "--sites",
dest="getMySiteNames",
default=False,
action="store_true",
help="Retrieve site names"
)
parser.add_argument(
"--computers", "-computers",
dest="getJamfComputers",
default=False,
action="store_true",
help="Display all computers"
)
parser.add_argument(
"--computer", "-computer",
dest="getJamfComputer",
default="",
action="store",
help="Display computer by ID"
)
parser.add_argument(
"--policies", "-policies",
dest="getJamfPolicies",
default=False,
action="store_true",
help="Display all policies"
)
parser.add_argument(
"--policy", "-policy",
dest="getJamfPolicy",
default="",
action="store",
help="Display policy by ID"
)
parser.add_argument(
"--verbose", "-v",
dest="verbose",
default=False,
action="store_true",
help="Display verbose output"
)
parser.add_argument(
"--throw", "-throw",
dest="throw",
default=False,
action="store_true",
help="Throw all exceptions"
)
parser.add_argument(
"--save", "-save",
dest="saveResults",
default=False,
action="store_true",
help="Save results in JSON format"
)
parser.add_argument(
"--collect", "-collect",
dest="collect",
default=False,
action="store_true",
help="Runs a collection of JAMF resources and saves the output as JSON for generic ingest into BloodHound."
)
parser.add_argument(
"--checkAzureUsers", "-checkAzureUsers",
dest="checkAzureUsers",
type=str,
default="",
action="store",
help="Compares an AzureHound collection against a JamfHound collection to determine if any Azure accounts match JAMF principals. Requires the additional JAMFcollection argument with path to the JSON to compare."
)
parser.add_argument(
"--JAMFcollection", "-JAMFcollection",
dest="JAMFcollection",
type=str,
default="",
action="store",
help="Path to the additional JAMFcollection JSON file to use for processing."
)
parser.add_argument(
"--okta", "-okta",
dest="okta",
action="store_true",
help="Enable Okta hybrid edge creation if OktaHound will be used with JamfHound"
)
args = parser.parse_args()
if not ((args.username and args.password) or args.token or (args.checkAzureUsers and args.JAMFcollection)):
if args.checkAzureUsers or args.JAMFcollection:
parser.error("checkAzureUsers and JAMFcollection arguments require both arguments to be provided if either one is used")
else:
parser.error("Missing credentials or token file")
# collection
if args.collect:
# Get current time and format it
timestamp = datetime.now().strftime("Collection_%Y_%m_%d_%H_%M_%S")
# Create collection directory
os.makedirs(timestamp, exist_ok=True)
# Change the current working directory
os.chdir(timestamp)
# Set save results to true
args.saveResults = True
# Set up initial controller
ctl = UserController(**args.__dict__)
# Print directory message
ctl.view.success(f"Created collection directory: {timestamp}")
# Collect accounts and users first
try:
ctl.getAccounts()
except Exception as e:
log_error(f"Failed to collect accounts: {e}")
# Collect Computers
try:
cptrs = ComputerController(**args.__dict__)
cptrs.getComputers()
except Exception as e:
log_error(f"Failed to collect computers: {e}")
# Sites
try:
jservice = JAMFService(**args.__dict__)
jservice.authenticate()
cptrs.view.success("Saving sites to sites.json") #TODO either write a sites controller or stop using controllers and pass directly for processing
sites = jservice.getSites()
jservice.writeJsonFile("sites.json", sites)
except Exception as e:
log_error(f"Failed to collect sites: {e}")
# Collect account groups TODO: Move these actions to controller or services.py internal method calls
try:
agroups = jservice.getAccountGroups()
groups = []
for group in agroups.get("accounts").get("groups"):
groups.append(jservice.getGroup(group.get("id")))
group_out = {}
group_out["Groups"] = groups
jservice.writeJsonFile("groups.json", group_out)
cptrs.view.success("Saving groups to groups.json")
except Exception as e:
log_error(f"Failed to collect groups: {e}")
#TODO: Collect Policies to determine if any scripts are recurring/can be updated alone
try:
pols = PolicyController(**args.__dict__)
pols.getPolicies()
except Exception as e:
log_error(f"Failed to collect policies: {e}")
# Collect Scripts
try:
scripts = jservice.getScripts()
cptrs.view.success("Saving scripts to scripts.json") #TODO either write a sites controller or stop using controllers and pass directly for processing
jservice.writeJsonFile("scripts.json", scripts)
except Exception as e:
log_error(f"Failed to collect scripts: {e}")
# SSO Settings Collection
try:
sso = jservice.getSSO()
cptrs.view.success("Saving SSO settings to sso.json") #TODO either write a sites controller or stop using controllers and pass directly for processing
jservice.writeJsonFile("sso.json", sso)
except Exception as e:
log_info(f"SSO not configured, or endpoint is inaccessible: {e}")
# Api Clients and Roles Collection
try:
apiRoles = jservice.getApiRoles()
jservice.writeJsonFile("apiroles.json", apiRoles)
except Exception as e:
log_error(f"Failed to collect API roles: {e}")
try:
apiClients = jservice.getApiClients()
jservice.writeJsonFile("apiclients.json", apiClients)
cptrs.view.success("Saving api roles and clients to apiroles.json and apiclients.json")
except Exception as e:
log_error(f"Failed to collect API clients: {e}")
# Preprocessing to create JSON to import into BloodHound
jamfPreprocessor = Preprocessor(args)
jamfPreprocessor.process_nodes()
cptrs.view.success(jamfPreprocessor.write_out_collection(jservice, okta=args.okta))
return
if args.checkAzureUsers:
checkAzureUsers(args.checkAzureUsers, args.JAMFcollection)
return
# policies
if args.getJamfPolicy or args.getJamfPolicies:
ctl = PolicyController(**args.__dict__)
if ctl.getJamfPolicies:
ctl.jamfPolicies()
elif ctl.getJamfPolicy:
ctl.jamfPolicy(ctl.getJamfPolicy)
return
# computers
if args.getJamfComputer or args.getJamfComputers:
ctl = ComputerController(**args.__dict__)
if ctl.getJamfComputers:
ctl.jamfComputers()
elif ctl.getJamfComputer:
ctl.jamfComputer(ctl.getJamfComputer)
return
# users
ctl = UserController(**args.__dict__)
if ctl.getMyPermissions:
ctl.myPermissions()
elif ctl.getAccountsPermissions:
ctl.accountsPermissions()
elif ctl.getMySiteNames:
ctl.mySites()
elif ctl.getUsersPermissions:
ctl.usersPermissions()
elif ctl.getAccountPermissions:
ctl.accountPermissions(ctl.getAccountPermissions)
elif ctl.getUserPermissions:
ctl.userPermissions(ctl.getUserPermissions)
return
if __name__ == "__main__":
main()