-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmitre3.py
247 lines (199 loc) · 7.48 KB
/
mitre3.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import datetime
import re
import subprocess
from hashlib import md5
import jwt
from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse
from django.shortcuts import redirect, render
from django.views.decorators.csrf import csrf_exempt
from .models import CSRF_user_tbl
from .views import authentication_decorator
# import os
## Mitre top1 | CWE:787
# target zone
FLAG = "NOT_SUPPOSED_TO_BE_ACCESSED"
# target zone end
@authentication_decorator
def mitre_top1(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top1.html')
@authentication_decorator
def mitre_top2(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top2.html')
@authentication_decorator
def mitre_top3(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top3.html')
@authentication_decorator
def mitre_top4(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top4.html')
@authentication_decorator
def mitre_top5(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top5.html')
@authentication_decorator
def mitre_top6(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top6.html')
@authentication_decorator
def mitre_top7(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top7.html')
@authentication_decorator
def mitre_top8(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top8.html')
@authentication_decorator
def mitre_top9(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top9.html')
@authentication_decorator
def mitre_top10(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top10.html')
@authentication_decorator
def mitre_top11(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top11.html')
@authentication_decorator
def mitre_top12(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top12.html')
@authentication_decorator
def mitre_top13(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top13.html')
@authentication_decorator
def mitre_top14(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top14.html')
@authentication_decorator
def mitre_top15(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top15.html')
@authentication_decorator
def mitre_top16(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top16.html')
@authentication_decorator
def mitre_top17(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top17.html')
@authentication_decorator
def mitre_top18(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top18.html')
@authentication_decorator
def mitre_top19(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top19.html')
@authentication_decorator
def mitre_top20(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top20.html')
@authentication_decorator
def mitre_top21(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top21.html')
@authentication_decorator
def mitre_top22(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top22.html')
@authentication_decorator
def mitre_top23(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top23.html')
@authentication_decorator
def mitre_top24(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top24.html')
@authentication_decorator
def mitre_top25(request):
if request.method == 'GET':
return render(request, 'mitre/mitre_top25.html')
@authentication_decorator
def csrf_lab_login(request):
if request.method == 'GET':
return render(request, 'mitre/csrf_lab_login.html')
elif request.method == 'POST':
password = request.POST.get('password')
username = request.POST.get('username')
password = md5(password.encode()).hexdigest()
User = CSRF_user_tbl.objects.filter(username=username, password=password)
if User:
payload ={
'username': username,
'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=300),
'iat': datetime.datetime.utcnow()
}
cookie = jwt.encode(payload, 'csrf_vulneribility', algorithm='HS256')
response = redirect("/mitre/9/lab/transaction")
response.set_cookie('auth_cookiee', cookie)
return response
else :
return redirect('/mitre/9/lab/login')
@authentication_decorator
@csrf_exempt
def csrf_transfer_monei(request):
if request.method == 'GET':
try:
cookie = request.COOKIES['auth_cookiee']
payload = jwt.decode(cookie, 'csrf_vulneribility', algorithms=['HS256'])
username = payload['username']
User = CSRF_user_tbl.objects.filter(username=username)
if not User:
redirect('/mitre/9/lab/login')
return render(request, 'mitre/csrf_dashboard.html', {'balance': User[0].balance})
except:
return redirect('/mitre/9/lab/login')
def csrf_transfer_monei_api(request,recipent,amount):
if request.method == "GET":
cookie = request.COOKIES['auth_cookiee']
payload = jwt.decode(cookie, 'csrf_vulneribility', algorithms=['HS256'])
username = payload['username']
User = CSRF_user_tbl.objects.filter(username=username)
if not User:
return redirect('/mitre/9/lab/login')
if int(amount) > 0:
if int(amount) <= User[0].balance:
recipent = CSRF_user_tbl.objects.filter(username=recipent)
if recipent:
recipent = recipent[0]
recipent.balance = recipent.balance + int(amount)
recipent.save()
User[0].balance = User[0].balance - int(amount)
User[0].save()
return redirect('/mitre/9/lab/transaction')
else:
return redirect ('/mitre/9/lab/transaction')
# @authentication_decorator
@csrf_exempt
def mitre_lab_25_api(request):
if request.method == "POST":
expression = request.POST.get('expression')
result = eval(expression)
return JsonResponse({'result': result})
else:
return redirect('/mitre/25/lab/')
@authentication_decorator
def mitre_lab_25(request):
return render(request, 'mitre/mitre_lab_25.html')
@authentication_decorator
def mitre_lab_17(request):
return render(request, 'mitre/mitre_lab_17.html')
def command_out(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return process.communicate()
@csrf_exempt
def mitre_lab_17_api(request):
if request.method == "POST":
ip = request.POST.get('ip')
command = "nmap " + ip
res, err = command_out(command)
res = res.decode()
err = err.decode()
pattern = "STATE SERVICE.*\\n\\n"
ports = re.findall(pattern, res,re.DOTALL)[0][14:-2].split('\n')
return JsonResponse({'raw_res': str(res), 'raw_err': str(err), 'ports': ports})