-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
daff_server.py
138 lines (114 loc) · 3.85 KB
/
daff_server.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
"""
Fuzz Server
"""
import os
import re
import sys
import atexit
from flask import (
Flask,
abort,
send_from_directory,
request,
jsonify
)
from browser_fuzz import (
generate_html,
start_browser_fuzz
)
from pdf_fuzz import (
start_pdf_fuzz
)
import settings
import utils
sys.tracebacklimit = 0
APP = Flask(__name__)
FILENAME_REGEX = re.compile(r"^[^\\\/]*\.(\w{3,4})$")
@APP.route('/html/<filename>')
def serve_html_pregenerated_files(filename):
"""Pre Generated HTML Files"""
if filename.endswith(".html") and re.match(FILENAME_REGEX, filename):
pregen_html_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "generators/html/htmls/")
return send_from_directory(pregen_html_dir, filename)
abort(404)
@APP.route('/pdf/<filename>')
def serve_pdf_pregenerated_files(filename):
"""Pre Generated Files"""
if filename.endswith(".pdf") and re.match(FILENAME_REGEX, filename):
pregen_pdf_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "generators/pdf/pdfs")
return send_from_directory(pregen_pdf_dir, filename)
abort(404)
@APP.route('/fuzz_html/<req_id>', methods=['GET', 'POST'])
def gen_fuzz_html(req_id):
"""Generate Fuzz HTML"""
if req_id.isdigit():
return generate_html(req_id)
abort(404)
@APP.route('/fuzz_pdf/<filename>')
def serve_pdf_fuzz_files(filename):
"""Fuzzer Generated Files"""
if filename.endswith(".pdf") and re.match(FILENAME_REGEX, filename):
fuzz_output_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "fuzz_files")
return send_from_directory(fuzz_output_dir, filename)
abort(404)
@APP.route('/browser_fuzz', methods=['POST'])
def browser_fuzz():
"""Start Browser Fuzzer"""
browser = request.form.get('browser')
fuzzer = request.form.get('fuzzer')
iteration = request.form.get('iteration')
start_browser_fuzz(browser, fuzzer, int(iteration))
return "Browser Fuzzing Started"
@APP.route('/pdf_fuzz', methods=['POST'])
def pdf_fuzz():
"""Start PDF Fuzzer"""
pdf_reader = request.form.get('pdf_reader')
fuzzer = request.form.get('fuzzer')
iteration = request.form.get('iteration')
start_pdf_fuzz(pdf_reader, fuzzer, int(iteration))
return "PDF Reader Fuzzing Started"
@APP.route('/crashes', methods=['POST'])
def get_crashes():
"""Get Crashes if any"""
crash_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "crash")
if os.path.exists(crash_dir):
allfiles = os.listdir(crash_dir)
file_list = [filename for filename in allfiles if filename.endswith(
".html") or filename.endswith(".pdf")]
if len(file_list) > 0:
return jsonify({"crash": len(file_list), "files": file_list})
return jsonify({"crash": 0, "files": []})
@APP.route('/stop', methods=['POST'])
def shutdown():
"""Shut down the server"""
utils.adb_kill()
func = request.environ.get('werkzeug.server.shutdown')
if func is None:
raise RuntimeError('Not running with the Werkzeug Server')
func()
return 'Server shutting down...'
@APP.route('/js/<path:path>')
def send_js(path):
js_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "static", "js")
return send_from_directory(js_dir, path)
@APP.route('/css/<path:path>')
def send_css(path):
css_dir = os.path.join(os.path.dirname(
os.path.realpath(__file__)), "static", "css")
return send_from_directory(css_dir, path)
@APP.route('/', methods=['GET'])
def main():
"""UI"""
with open('static/index.html', 'r') as filep:
return filep.read()
def cleanup():
utils.adb_kill()
if __name__ == '__main__':
atexit.register(cleanup)
APP.run(threaded=True, host=settings.SERVER_IP,
port=settings.SERVER_PORT, debug=settings.DEBUG)