-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathusage.py
More file actions
131 lines (113 loc) · 3.53 KB
/
usage.py
File metadata and controls
131 lines (113 loc) · 3.53 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
import argparse
import os
import sys
from datetime import datetime
default_blackbox_mapping_file = os.path.join(
os.path.dirname(__file__),
'vulnerability_definitions',
'blackbox_mapping.json'
)
default_trigger_word_file = os.path.join(
os.path.dirname(__file__),
'vulnerability_definitions',
'all_trigger_words.pyt'
)
def valid_date(s):
date_format = "%Y-%m-%d"
try:
return datetime.strptime(s, date_format).date()
except ValueError:
msg = "Not a valid date: '{0}'. Format: {1}".format(s, date_format)
raise argparse.ArgumentTypeError(msg)
def _add_required_group(parser):
required_group = parser.add_argument_group('required arguments')
required_group.add_argument(
'-f', '--filepath',
help='Path to the file that should be analysed.',
type=str
)
def _add_optional_group(parser):
optional_group = parser.add_argument_group('optional arguments')
optional_group.add_argument(
'-a', '--adaptor',
help='Choose a web framework adaptor: '
'Flask(Default), Django, Every or Pylons',
type=str
)
optional_group.add_argument(
'-pr', '--project-root',
help='Add project root, only important when the entry '
'file is not at the root of the project.',
type=str
)
optional_group.add_argument(
'-b', '--baseline',
help='Path of a baseline report to compare against '
'(only JSON-formatted files are accepted)',
type=str,
default=False,
metavar='BASELINE_JSON_FILE',
)
optional_group.add_argument(
'-j', '--json',
help='Prints JSON instead of report.',
action='store_true',
default=False
)
optional_group.add_argument(
'-m', '--blackbox-mapping-file',
help='Input blackbox mapping file.',
type=str,
default=default_blackbox_mapping_file
)
optional_group.add_argument(
'-t', '--trigger-word-file',
help='Input file with a list of sources and sinks',
type=str,
default=default_trigger_word_file
)
optional_group.add_argument(
'-o', '--output',
help='write report to filename',
dest='output_file',
action='store',
type=argparse.FileType('w'),
default=sys.stdout,
)
optional_group.add_argument(
'--ignore-nosec',
dest='ignore_nosec',
action='store_true',
help='do not skip lines with # nosec comments'
)
def _add_print_group(parser):
print_group = parser.add_argument_group('print arguments')
print_group.add_argument(
'-trim', '--trim-reassigned-in',
help='Trims the reassigned list to just the vulnerability chain.',
action='store_true',
default=True
)
print_group.add_argument(
'-i', '--interactive',
help='Will ask you about each blackbox function call in vulnerability chains.',
action='store_true',
default=False
)
def _check_required_and_mutually_exclusive_args(parser, args):
if args.filepath is None:
parser.error('The -f/--filepath argument is required')
def parse_args(args):
if len(args) == 0:
args.append('-h')
parser = argparse.ArgumentParser(prog='python -m pyt')
parser._action_groups.pop()
_add_required_group(parser)
_add_optional_group(parser)
_add_print_group(parser)
args = parser.parse_args(args)
_check_required_and_mutually_exclusive_args(
parser,
args
)
return args