-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
188 lines (172 loc) · 7.34 KB
/
app.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
from flask import Blueprint,Flask, request, render_template, make_response
import re
#import regex
from multiprocessing import Process, Queue
from email_validator import validate_email
import re2
from oauthlib import uri_validate
from cve_2022_36087 import cve_2022_36087_blueprint
from cve_2021_23437 import cve_2021_23437_blueprint
# from cve_2021_27291 import cve_2021_27291_blueprint
app = Flask(__name__)
app.register_blueprint(cve_2022_36087_blueprint)
app.register_blueprint(cve_2021_23437_blueprint)
# app.register_blueprint(cve_2021_27291_blueprint)
@app.route('/index', methods=['GET', 'POST'])
def home():
message = None
if request.method == 'POST':
#pattern = r'^([a-zA-Z0-9._]+)+@gmail\.com$' # fixed - ((?:(?:[a-zA-Z0-9._])+))@gmail.com
pattern = r'A(B|C+)+D'
string = request.form.get('string')
if pattern and string:
match = re.findall(pattern, string)
if match:
response = make_response(render_template('index.html', message='200 OK'), 200)
else:
response = make_response(render_template('index.html', message='400 Bad Request'), 400)
return response
return render_template('index.html', message=message)
@app.route('/repair', methods=['GET', 'POST'])
def repair():
message = None
if request.method == 'POST':
#pattern = r'A((?:(?:(?!.).)|(?:(?:[BC])+)))D'
pattern = r'^((?:(?:[a-zA-Z0-9._])+))@gmail.com$'
string = request.form.get('string')
if pattern and string:
match = re.findall(pattern, string)
if match:
response = make_response(render_template('repair.html', message='200 OK'), 200)
else:
response = make_response(render_template('repair.html', message='400 Bad Request'), 400)
return response
return render_template('repair.html', message=message)
# fuction used for /timeout
def match_pattern(string, queue):
match = re.findall(r'^([a-zA-Z0-9._]+)+@gmail\.com$', string)
print(match)
queue.put(match)
# @app.route('/timeout', methods=['GET', 'POST'])
# def timeout():
# message = None
# if request.method == 'POST':
# string = request.form.get('string')
# if string:
# queue = Queue()
# p = Process(target=match_pattern, args=(string, queue))
# p.start()
# p.join(1) # Wait for 1 second
# if p.is_alive():
# p.terminate()
# p.join()
# response = make_response(render_template('timeout.html', message='500 Internal Server Error'), 500)
# else:
# result = queue.get()
# if result:
# response = make_response(render_template('timeout.html', message='200 OK'), 200)
# else:
# response = make_response(render_template('timeout.html', message='400 Bad Request'), 400)
# return response
# return render_template('timeout.html', message=message)
@app.route('/diff_regex_engine', methods=['GET', 'POST'])
def diff_regex_engine():
message = None
if request.method == 'POST':
pattern = r'^((?:(?:[a-zA-Z0-9._])+))@gmail.com$'
string = request.form.get('string')
try:
if pattern and string:
match = re2.match(pattern, string)
if match:
response = make_response(render_template('diff_regex_engine.html', message='200 OK'), 200)
else:
response = make_response(render_template('diff_regex_engine.html', message=re2.error), 400)
except re2.error:
response = make_response(render_template('diff_regex_engine.html', message='Error in regex pattern'), 500)
return response
return render_template('diff_regex_engine.html', message=message)
@app.route('/alternate_logic', methods=['GET', 'POST'])
def alternate_logic():
message = None
if request.method == 'POST':
string = request.form.get('string')
if string:
if validate_email(string):
response = make_response(render_template('alternate_logic.html', message='200 OK'), 200)
else:
response = make_response(render_template('alternate_logic.html', message='400 Bad Request'), 400)
return response
return render_template('alternate_logic.html', message=message)
@app.route('/limit_input', methods=['GET', 'POST'])
def limit_input():
message = None
if request.method == 'POST':
#pattern = r'^([a-zA-Z0-9._]+)+@gmail\.com$' # fixed - ((?:(?:[a-zA-Z0-9._])+))@gmail.com
pattern = r'A(B|C+)+D'
string = request.form.get('string')
if pattern and string:
if len(string) > 100: # Enter the value decided by the developers
response = make_response(render_template('limit_input.html', message='413 Request Entity Too Large'), 413)
else:
match = re.findall(pattern, string)
if match:
response = make_response(render_template('limit_input.html', message='200 OK'), 200)
else:
response = make_response(render_template('limit_input.html', message='400 Bad Request'), 400)
return response
return render_template('limit_input.html', message=message)
# Experimental
def search(r,s):
SECRET = "this_is_secret"
return re.match(r,SECRET)
@app.route('/regex_injection', methods=['GET', 'POST'])
def regex_injection():
message = None
if request.method == 'POST':
string = request.form.get('string')
if string:
queue = Queue()
p = Process(target=search, args=(string, queue))
p.start()
p.join(2) # Wait for 1 second
if p.is_alive():
p.terminate()
p.join()
response = make_response(render_template('timeout.html', message='500 Internal Server Error'), 500)
else:
result = queue.get()
if result:
response = make_response(render_template('timeout.html', message='200 OK'), 200)
else:
response = make_response(render_template('timeout.html', message='400 Bad Request'), 400)
return response
return render_template('timeout.html', message=message)
def uri_validate_cve(string, queue):
match = uri_validate.is_uri(string,2)
print(match)
queue.put(match)
@app.route('/timeout', methods=['GET', 'POST'])
def timeout():
message = None
if request.method == 'POST':
string = request.form.get('string')
if string:
queue = Queue()
p = Process(target=uri_validate_cve, args=(string, queue))
p.start()
p.join(1) # Wait for 1 second
if p.is_alive():
p.terminate()
p.join()
response = make_response('500 Internal Server Error', 500)
else:
result = queue.get()
if result:
response = make_response( '200 OK', 200)
else:
response = make_response( '400 Bad Request', 400)
return response
return render_template('timeout.html', message=message)
if __name__ == "__main__":
app.run(host='127.0.0.1',debug=False)