-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdoublex.py
More file actions
80 lines (62 loc) · 3.63 KB
/
doublex.py
File metadata and controls
80 lines (62 loc) · 3.63 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
# Copyright (C) 2021 Aurore Fass
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
To call DoubleX from the command-line.
"""
import os
import argparse
from vulnerability_detection import analyze_extension
SRC_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__)))
def main():
""" Parsing command line parameters. """
parser = argparse.ArgumentParser(prog='doublex',
formatter_class=argparse.RawTextHelpFormatter,
description="Static analysis of a browser extension to detect "
"suspicious data flows")
parser.add_argument("-cs", "--content-script", dest='cs', metavar="path", type=str,
help="path of the content script. "
"Default: empty/contentscript.js (i.e., empty JS file)")
parser.add_argument("-bp", "--background-page", dest='bp', metavar="path", type=str,
help="path of the background page "
"or path of the WAR if the parameter '--war' is given. "
"Default for background: empty/background.js (i.e., empty JS file)")
parser.add_argument("--war", action='store_true',
help="indicate that the parameter '-bp' is the path of a WAR")
parser.add_argument("--not-chrome", dest='not_chrome', action='store_true',
help="indicate that the extension is not based on Chromium, e.g., for a Firefox extension")
parser.add_argument("--manifest", metavar="path", type=str,
help="path of the extension manifest.json file. "
"Default: parent-path-of-content-script/manifest.json")
parser.add_argument("--analysis", metavar="path", type=str,
help="path of the file to store the analysis results in. "
"Default: parent-path-of-content-script/analysis.json")
parser.add_argument("--apis", metavar="str", type=str, default='permissions',
help='''specify the sensitive APIs to consider for the analysis:
- 'permissions' (default): DoubleX selected APIs iff the extension has the corresponding permissions;
- 'all': DoubleX selected APIs irrespective of the extension permissions;
- 'empoweb': APIs from the EmPoWeb paper; to use ONLY on the EmPoWeb ground-truth dataset;
- path: APIs listed in the corresponding json file; a template can be found in src/suspicious_apis/README.md.''')
# TODO: control verbosity of logging?
args = parser.parse_args()
cs = args.cs
bp = args.bp
if cs is None:
cs = os.path.join(os.path.dirname(SRC_PATH), 'empty', 'contentscript.js')
if bp is None:
bp = os.path.join(os.path.dirname(SRC_PATH), 'empty', 'background.js')
analyze_extension(cs, bp, json_analysis=args.analysis, chrome=not args.not_chrome,
war=args.war, json_apis=args.apis, manifest_path=args.manifest)
if __name__ == "__main__":
main()