forked from opencybersecurityalliance/stix-shifter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (45 loc) · 1.96 KB
/
main.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
import argparse
import sys
from stix_shifter import stix_shifter
def __main__():
"""
In the case of converting a stix pattern to datasource query, arguments will take the form of...
<module> <translate_type> <data>
The module and translate_type will determine what module and method gets called
"""
# process arguments
parser = argparse.ArgumentParser(description='stix_shifter')
subparsers = parser.add_subparsers(dest='command')
# translate parser
translate_parser = subparsers.add_parser(
'translate', help='Translate a query or result set using a specific translation module')
# positional arguments
translate_parser.add_argument(
'module', choices=stix_shifter.MODULES, help='what translation module to use')
translate_parser.add_argument('translate_type', choices=[
stix_shifter.RESULTS, stix_shifter.QUERY], help='what translation action to perform')
translate_parser.add_argument(
'data_source', help='STIX identity object representing a datasource')
translate_parser.add_argument(
'data', type=str, help='the data to be translated')
# optional arguments
translate_parser.add_argument('-x', '--stix-validator', action='store_true',
help='run stix2 validator against the converted results')
translate_parser.add_argument('-m', '--data-mapper',
help='module to use for the data mapper')
args = parser.parse_args()
if args.command is None:
parser.print_help(sys.stderr)
sys.exit(1)
options = {}
if args.stix_validator:
options['stix_validator'] = args.stix_validator
if args.data_mapper:
options['data_mapper'] = args.data_mapper
shifter = stix_shifter.StixShifter()
result = shifter.translate(
args.module, args.translate_type, args.data_source, args.data, options=options)
print(result)
exit(0)
if __name__ == "__main__":
__main__()