-
Notifications
You must be signed in to change notification settings - Fork 107
/
discover.py
543 lines (456 loc) · 25.4 KB
/
discover.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
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
"""CrowdStrike Falcon Discover API Interface Class.
_______ __ _______ __ __ __
| _ .----.-----.--.--.--.--| | _ | |_.----|__| |--.-----.
|. 1___| _| _ | | | | _ | 1___| _| _| | <| -__|
|. |___|__| |_____|________|_____|____ |____|__| |__|__|__|_____|
|: 1 | |: 1 |
|::.. . | CROWDSTRIKE FALCON |::.. . | FalconPy
`-------' `-------'
OAuth2 API - Customer SDK
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
"""
from typing import Dict, Union
from ._util import process_service_request, force_default, handle_single_argument
from ._service_class import ServiceClass
from ._endpoint._discover import _discover_endpoints as Endpoints
class Discover(ServiceClass):
"""The only requirement to instantiate an instance of this class is one of the following.
- a valid client_id and client_secret provided as keywords.
- a credential dictionary with client_id and client_secret containing valid API credentials
{
"client_id": "CLIENT_ID_HERE",
"client_secret": "CLIENT_SECRET_HERE"
}
- a previously-authenticated instance of the authentication service class (oauth2.py)
- a valid token provided by the authentication service class (oauth2.py)
"""
@force_default(defaults=["parameters"], default_types=["dict"])
def get_accounts(self: object, *args, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Get details on accounts by providing one or more IDs.
Find account IDs with `query_accounts`.
Keyword arguments:
ids -- One or more account IDs (max: 100). String or list of strings.
parameters - full parameters payload, not required if ids is provided as a keyword.
Arguments: When not specified, the first argument to this method is assumed to be 'ids'.
All others are ignored.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/get-accounts
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="get_accounts",
keywords=kwargs,
params=handle_single_argument(args, parameters, "ids")
)
@force_default(defaults=["parameters"], default_types=["dict"])
def get_applications(self: object, *args, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Get details on applications by providing one or more IDs.
Find application IDs with `query_applications`.
Keyword arguments:
ids -- One or more application IDs (max: 100). String or list of strings.
parameters - full parameters payload, not required if ids is provided as a keyword.
Arguments: When not specified, the first argument to this method is assumed to be 'ids'.
All others are ignored.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/get-applications
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="get_applications",
keywords=kwargs,
params=handle_single_argument(args, parameters, "ids")
)
@force_default(defaults=["parameters"], default_types=["dict"])
def get_hosts(self: object, *args, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Get details on assets by providing one or more IDs.
Find asset IDs with `query_hosts`.
Keyword arguments:
ids -- One or more asset IDs (max: 100). String or list of strings.
parameters - full parameters payload, not required if ids is provided as a keyword.
Arguments: When not specified, the first argument to this method is assumed to be 'ids'.
All others are ignored.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/get-hosts
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="get_hosts",
keywords=kwargs,
params=handle_single_argument(args, parameters, "ids")
)
@force_default(defaults=["parameters"], default_types=["dict"])
def get_logins(self: object, *args, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Get details on logins by providing one or more IDs.
Find login IDs with `query_logins`.
Keyword arguments:
ids -- One or more login IDs (max: 100). String or list of strings.
parameters - full parameters payload, not required if ids is provided as a keyword.
Arguments: When not specified, the first argument to this method is assumed to be 'ids'.
All others are ignored.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/get-logins
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="get_logins",
keywords=kwargs,
params=handle_single_argument(args, parameters, "ids")
)
@force_default(defaults=["parameters"], default_types=["dict"])
def query_accounts(self: object, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Search for accounts in your environment.
Supports providing a FQL (Falcon Query Language) filter and paging details.
Returns a set of account IDs which match the filter criteria.
Keyword arguments:
filter -- The filter expression that should be used to limit the results. FQL syntax.
Common filter options include:
account_type:'Local'
admin_privileges:'Yes'
first_seen_timestamp:<'now-7d'
last_successful_login_type:'Terminal server'
Available Filters:
id last_successful_login_timestamp
cid last_successful_login_hostname
user_sid last_successful_login_remote_ip
login_domain last_successful_login_host_country
account_name last_successful_login_host_city
username last_failed_login_type
account_type last_failed_login_timestamp
admin_privileges last_failed_login_hostname
first_seen_timestamp password_last_set_timestamp
last_successful_login_type
limit -- The number of account IDs to return in this response. (Max: 100, default: 100)
Use with the offset parameter to manage pagination of results.
offset -- An offset used with the limit parameter to manage pagination of results.
On your first request, don’t provide an offset. On subsequent requests,
provide the offset from the previous response to continue from that place
in the results.
parameters - full parameters payload, not required if using other keywords.
sort -- Sort assets by their properties. A single sort field is allowed.
Common sort options include:
username|asc
last_failed_login_timestamp|desc
This method only supports keywords for providing arguments.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/query-accounts
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="query_accounts",
keywords=kwargs,
params=parameters
)
@force_default(defaults=["parameters"], default_types=["dict"])
def query_applications(self: object, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Search for applications in your environment.
Supports providing a FQL (Falcon Query Language) filter and paging details.
Returns a set of account IDs which match the filter criteria.
Keyword arguments:
filter -- The filter expression that should be used to limit the results. FQL syntax.
limit -- The number of account IDs to return in this response. (Max: 100, default: 100)
Use with the offset parameter to manage pagination of results.
offset -- An offset used with the limit parameter to manage pagination of results.
On your first request, don’t provide an offset. On subsequent requests,
provide the offset from the previous response to continue from that place
in the results.
parameters - full parameters payload, not required if using other keywords.
sort -- Sort assets by their properties. A single sort field is allowed.
This method only supports keywords for providing arguments.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/query-applications
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="query_applications",
keywords=kwargs,
params=parameters
)
@force_default(defaults=["parameters"], default_types=["dict"])
def query_hosts(self: object, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Search for assets in your environment.
Supports providing a FQL (Falcon Query Language) filter and paging details.
Returns a set of asset IDs which match the filter criteria.
Keyword arguments:
filter -- The filter expression that should be used to limit the results. FQL syntax.
Available Filters:
agent_version kernel_version
aid last_discoverer_aid
bios_manufacturer last_seen_timestamp
bios_version local_ips_count
cid machine_domain
city network_interfaces
confidence network_interfaces.interface_alias
country network_interfaces.interface_description
current_local_ip network_interfaces.local_ip
discoverer_aids network_interfaces.mac_address
discoverer_count network_interfaces.network_prefix
discoverer_platform_names os_version
discoverer_product_type_descs ou
discoverer_tags platform_name
entity_type product_type
external_ip product_type_desc
first_discoverer_aid site_name
first_discoverer_ip system_manufacturer
first_seen_timestamp system_product_name
groups system_serial_number
hostname tags
id
limit -- The number of asset IDs to return in this response. (Max: 100, default: 100)
Use with the offset parameter to manage pagination of results.
offset -- An offset used with the limit parameter to manage pagination of results.
On your first request, don’t provide an offset. On subsequent requests,
provide the offset from the previous response to continue from that place
in the results.
parameters - full parameters payload, not required if using other keywords.
sort -- Sort assets by their properties. A single sort field is allowed.
Common sort options include:
hostname|asc
product_type|desc
This method only supports keywords for providing arguments.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/query-hosts
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="query_hosts",
keywords=kwargs,
params=parameters
)
@force_default(defaults=["parameters"], default_types=["dict"])
def query_logins(self: object, parameters: dict = None, **kwargs) -> Dict[str, Union[int, dict]]:
"""Search for logins in your environment.
Supports providing a FQL (Falcon Query Language) filter and paging details.
Returns a set of asset IDs which match the filter criteria.
Keyword arguments:
filter -- The filter expression that should be used to limit the results. FQL syntax.
Common filter options include:
account_type:'Local'
login_type:'Interactive'
first_seen_timestamp:<'now-7d'
admin_privileges:'No'
Available Filters:
id login_timestamp
cid login_domain
login_status admin_privileges
account_id local_ip
host_id remote_ip
user_sid host_country
aid host_city
account_name is_suspicious
username failure_description
hostname login_event_count
account_type aggregation_time_interval
login_type
limit -- The number of login IDs to return in this response. (Max: 100, default: 100)
Use with the offset parameter to manage pagination of results.
offset -- An offset used with the limit parameter to manage pagination of results.
On your first request, don’t provide an offset. On subsequent requests,
provide the offset from the previous response to continue from that place
in the results.
parameters - full parameters payload, not required if using other keywords.
sort -- Sort logins by their properties. A single sort field is allowed.
Common sort options include:
account_name|asc
login_timestamp|desc
This method only supports keywords for providing arguments.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/query-logins
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="query_logins",
keywords=kwargs,
params=parameters
)
@force_default(defaults=["parameters"], default_types=["dict"])
def get_iot_hosts(self: object, *args, parameters: dict = None, **kwargs) -> dict:
"""Get details on IoT assets by providing one or more IDs.
Find IoT assets with `query_iot_hosts`.
Keyword arguments:
ids -- One or more login IDs (max: 100). String or list of strings.
parameters - full parameters payload, not required if ids is provided as a keyword.
Arguments: When not specified, the first argument to this method is assumed to be 'ids'.
All others are ignored.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/get-iot-hosts
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="get_iot_hosts",
keywords=kwargs,
params=handle_single_argument(args, parameters, "ids")
)
@force_default(defaults=["parameters"], default_types=["dict"])
def query_iot_hosts(self: object, parameters: dict = None, **kwargs) -> dict:
"""Search for IoT assets in your environment.
Supports providing a FQL (Falcon Query Language) filter and paging details.
Returns a set of asset IDs which match the filter criteria.
Keyword arguments:
filter -- The filter expression that should be used to limit the results. FQL syntax.
Common filter options include:
entity_type:'managed'
product_type_desc:'Workstation'
platform_name:'Windows'
last_seen_timestamp:>'now-7d'
Available Filters:
agent_version last_seen_timestamp
aid local_ip_addresses
bios_manufacturer local_ips_count
bios_version mac_addresses
business_criticality machine_domain
cid network_id
city network_interfaces
claroty_id number_of_disk_drives
confidence os_is_eol
country os_version
current_local_ip ou
data_providers physical_core_count
data_providers_count platform_name
device_class processor_package_count
device_family product_type_desc
device_type protocols
discoverer_count purdue_level
discoverer_product_type_descs reduced_functionality_mode
entity_type site_name
external_ip subnet
first_seen_timestamp system_manufacturer
groups system_product_name
hostname system_serial_number
ics_id tags
id virtual_zone
internet_exposure vlan
kernel_version
limit -- The number of asset IDs to return in this response. (Max: 100, default: 100)
Use with the offset parameter to manage pagination of results.
offset -- An offset used with the limit parameter to manage pagination of results.
On your first request, don’t provide an offset. On subsequent requests,
provide the offset from the previous response to continue from that place
in the results.
parameters - full parameters payload, not required if using other keywords.
sort -- Sort assets by their properties. A single sort field is allowed.
Common sort options include:
hostname|asc
product_type_desc|desc
This method only supports keywords for providing arguments.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover/query-iot-hosts
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="query_iot_hosts",
keywords=kwargs,
params=parameters
)
@force_default(defaults=["parameters"], default_types=["dict"])
def query_iot_hosts_v2(self: object, parameters: dict = None, **kwargs) -> dict:
"""Search for IoT assets in your environment.
Supports providing a FQL (Falcon Query Language) filter and paging details.
Returns a set of asset IDs which match the filter criteria.
Keyword arguments:
filter -- The filter expression that should be used to limit the results. FQL syntax.
Common filter options include:
entity_type:'managed'
product_type_desc:'Workstation'
platform_name:'Windows'
last_seen_timestamp:>'now-7d'
Available Filters:
agent_version last_seen_timestamp
aid local_ip_addresses
bios_manufacturer local_ips_count
bios_version mac_addresses
business_criticality machine_domain
cid network_id
city network_interfaces
claroty_id number_of_disk_drives
confidence os_is_eol
country os_version
current_local_ip ou
data_providers physical_core_count
data_providers_count platform_name
device_class processor_package_count
device_family product_type_desc
device_type protocols
discoverer_count purdue_level
discoverer_product_type_descs reduced_functionality_mode
entity_type site_name
external_ip subnet
first_seen_timestamp system_manufacturer
groups system_product_name
hostname system_serial_number
ics_id tags
id virtual_zone
internet_exposure vlan
kernel_version
limit -- The number of asset IDs to return in this response. (Max: 100, default: 100)
Use with the offset parameter to manage pagination of results.
offset -- An offset used with the limit parameter to manage pagination of results.
On your first request, don’t provide an offset. On subsequent requests,
provide the offset from the previous response to continue from that place
in the results.
parameters - full parameters payload, not required if using other keywords.
sort -- Sort assets by their properties. A single sort field is allowed.
Common sort options include:
hostname|asc
product_type_desc|desc
This method only supports keywords for providing arguments.
Returns: dict object containing API response.
HTTP Method: GET
Swagger URL
https://assets.falcon.crowdstrike.com/support/api/swagger.html#/discover-iot/query-iot-hostsV2
"""
return process_service_request(
calling_object=self,
endpoints=Endpoints,
operation_id="query_iot_hostsV2",
keywords=kwargs,
params=parameters
)