From 902c65ce2843a87ea78b13ae8ecf092682eb70ee Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:21 +0800
Subject: [PATCH 01/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/mitre.py
---
introduction/mitre.py | 40 ++++++++++++++++++++++++++++------------
1 file changed, 28 insertions(+), 12 deletions(-)
diff --git a/introduction/mitre.py b/introduction/mitre.py
index c899c21..61f5b24 100644
--- a/introduction/mitre.py
+++ b/introduction/mitre.py
@@ -152,13 +152,19 @@ def mitre_top25(request):
return render(request, 'mitre/mitre_top25.html')
@authentication_decorator
+import hashlib
+import jwt
+import datetime
+from django.shortcuts import render, redirect
+from .models import CSRF_user_tbl
+
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()
+ password = hashlib.scrypt(password.encode(), salt=b'salt', n=16384, r=8, p=1, dklen=32).hex()
User = CSRF_user_tbl.objects.filter(username=username, password=password)
if User:
payload ={
@@ -166,20 +172,24 @@ def csrf_lab_login(request):
'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=300),
'iat': datetime.datetime.utcnow()
}
- cookie = jwt.encode(payload, 'csrf_vulneribility', algorithm='HS256')
+ cookie = jwt.encode(payload, key=None, algorithm='HS256') # Removed hardcoded secret
response = redirect("/mitre/9/lab/transaction")
- response.set_cookie('auth_cookiee', cookie)
+ response.set_cookie('auth_cookiee', cookie, secure=True, httponly=True, samesite='Lax')
return response
- else :
+ else:
return redirect('/mitre/9/lab/login')
@authentication_decorator
@csrf_exempt
-def csrf_transfer_monei(request):
+import os
+
+SECRET_KEY = os.getenv('SECRET_KEY')
+
+def csrf_transfer_money(request):
if request.method == 'GET':
try:
- cookie = request.COOKIES['auth_cookiee']
- payload = jwt.decode(cookie, 'csrf_vulneribility', algorithms=['HS256'])
+ cookie = request.COOKIES.get('auth_cookie')
+ payload = jwt.decode(cookie, SECRET_KEY, algorithms=['HS256'])
username = payload['username']
User = CSRF_user_tbl.objects.filter(username=username)
if not User:
@@ -188,10 +198,14 @@ def csrf_transfer_monei(request):
except:
return redirect('/mitre/9/lab/login')
-def csrf_transfer_monei_api(request,recipent,amount):
+import os
+
+SECRET_KEY = os.getenv('SECRET_KEY')
+
+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'])
+ payload = jwt.decode(cookie, SECRET_KEY, algorithms=['HS256'])
username = payload['username']
User = CSRF_user_tbl.objects.filter(username=username)
if not User:
@@ -207,15 +221,17 @@ def csrf_transfer_monei_api(request,recipent,amount):
User[0].save()
return redirect('/mitre/9/lab/transaction')
else:
- return redirect ('/mitre/9/lab/transaction')
+ return redirect('/mitre/9/lab/transaction')
# @authentication_decorator
@csrf_exempt
+import ast
+
def mitre_lab_25_api(request):
if request.method == "POST":
expression = request.POST.get('expression')
- result = eval(expression)
+ result = ast.literal_eval(expression)
return JsonResponse({'result': result})
else:
return redirect('/mitre/25/lab/')
@@ -230,7 +246,7 @@ 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)
+ process = subprocess.Popen(command, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return process.communicate()
From a9ae8e30c1d1c506599847c8a5a4572f5aa78d33 Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:21 +0800
Subject: [PATCH 02/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab/CMD/cmd_lab2.html
---
introduction/templates/Lab/CMD/cmd_lab2.html | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/introduction/templates/Lab/CMD/cmd_lab2.html b/introduction/templates/Lab/CMD/cmd_lab2.html
index a71a605..7319130 100644
--- a/introduction/templates/Lab/CMD/cmd_lab2.html
+++ b/introduction/templates/Lab/CMD/cmd_lab2.html
@@ -7,6 +7,7 @@
Evaluate any expression!
@@ -29,4 +30,4 @@
Output
-{% endblock %}
\ No newline at end of file
+{% endblock %}
From 7d690e4e3ce2c65e4f643a45ecc306018c471cdd Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:21 +0800
Subject: [PATCH 03/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab/BrokenAccess/ba_lab.html
---
introduction/templates/Lab/BrokenAccess/ba_lab.html | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/introduction/templates/Lab/BrokenAccess/ba_lab.html b/introduction/templates/Lab/BrokenAccess/ba_lab.html
index d45da9b..ef859c9 100644
--- a/introduction/templates/Lab/BrokenAccess/ba_lab.html
+++ b/introduction/templates/Lab/BrokenAccess/ba_lab.html
@@ -9,12 +9,11 @@
Admins Have the Secretkey
@@ -34,7 +33,6 @@ {{not_admin}}
{% if no_creds %}
Please Provide Credentials
{% endif %}
-
@@ -43,4 +41,4 @@ Please Provide Credentials
-{% endblock %}
\ No newline at end of file
+{% endblock %}
From 804f686644e2c09cfd09b3e9d7da2057131fd6eb Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:22 +0800
Subject: [PATCH 04/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/playground/A9/api.py
---
introduction/playground/A9/api.py | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/introduction/playground/A9/api.py b/introduction/playground/A9/api.py
index 35e1bd2..156280a 100644
--- a/introduction/playground/A9/api.py
+++ b/introduction/playground/A9/api.py
@@ -1,33 +1,29 @@
from django.http import JsonResponse
-from django.views.decorators.csrf import csrf_exempt
-
from .main import Log
-
-@csrf_exempt
def log_function_target(request):
L = Log(request)
if request.method == "GET":
L.info("GET request")
- return JsonResponse({"message":"normal get request", "method":"get"},status = 200)
+ return JsonResponse({"message":"normal get request", "method":"get"}, status=200)
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
L.info(f"POST request with username {username} and password {password}")
if username == "admin" and password == "admin":
- return JsonResponse({"message":"Loged in successfully", "method":"post"},status = 200)
- return JsonResponse({"message":"Invalid credentials", "method":"post"},status = 401)
+ return JsonResponse({"message":"Loged in successfully", "method":"post"}, status=200)
+ return JsonResponse({"message":"Invalid credentials", "method":"post"}, status=401)
if request.method == "PUT":
L.info("PUT request")
- return JsonResponse({"message":"success", "method":"put"},status = 200)
+ return JsonResponse({"message":"success", "method":"put"}, status=200)
if request.method == "DELETE":
if request.user.is_authenticated:
- return JsonResponse({"message":"User is authenticated", "method":"delete"},status = 200)
+ return JsonResponse({"message":"User is authenticated", "method":"delete"}, status=200)
L.error("DELETE request")
- return JsonResponse({"message":"permission denied", "method":"delete"},status = 200)
+ return JsonResponse({"message":"permission denied", "method":"delete"}, status=200)
if request.method == "PATCH":
L.info("PATCH request")
- return JsonResponse({"message":"success", "method":"patch"},status = 200)
+ return JsonResponse({"message":"success", "method":"patch"}, status=200)
if request.method == "UPDATE":
- return JsonResponse({"message":"success", "method":"update"},status = 200)
- return JsonResponse({"message":"method not allowed"},status = 403)
\ No newline at end of file
+ return JsonResponse({"message":"success", "method":"update"}, status=200)
+ return JsonResponse({"message":"method not allowed"}, status=403)
From aa7265274d4572c9a22ac66c88cbab50c2173b32 Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:22 +0800
Subject: [PATCH 05/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab/BrokenAuth/otp.html
---
introduction/templates/Lab/BrokenAuth/otp.html | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/introduction/templates/Lab/BrokenAuth/otp.html b/introduction/templates/Lab/BrokenAuth/otp.html
index 3d12cda..0ba29be 100644
--- a/introduction/templates/Lab/BrokenAuth/otp.html
+++ b/introduction/templates/Lab/BrokenAuth/otp.html
@@ -7,15 +7,15 @@
Login Through Otp
-
-{% endblock %}
\ No newline at end of file
+{% endblock %}
From 2ddbeed08597d1650d44ce044c5c78164cb49c6d Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:22 +0800
Subject: [PATCH 06/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html
---
.../A1_BrokenAccessControl/broken_access_lab_1.html | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html b/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html
index 1fa4c91..59e6947 100644
--- a/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html
+++ b/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html
@@ -9,12 +9,10 @@
Admins Have the Secretkey
@@ -34,13 +32,11 @@ {{not_admin}}
{% if no_creds %}
Please Provide Credentials
{% endif %}
-
-
-{% endblock %}
\ No newline at end of file
+{% endblock %}
From b8d155f56aed5d77488921021cb05e557f91b1c7 Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:22 +0800
Subject: [PATCH 07/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_2.html
---
.../A1_BrokenAccessControl/broken_access_lab_2.html | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_2.html b/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_2.html
index cce8b6e..7940ed9 100644
--- a/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_2.html
+++ b/introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_2.html
@@ -9,12 +9,10 @@
Can you log in as an admin and get the secretkey?
@@ -50,4 +48,4 @@ Please Provide Credentials
-{% endblock %}
\ No newline at end of file
+{% endblock %}
From 52a91bfc2f193ca8f169b6d386053f5b5191e787 Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:22 +0800
Subject: [PATCH 08/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab/CMD/cmd_lab.html
---
introduction/templates/Lab/CMD/cmd_lab.html | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/introduction/templates/Lab/CMD/cmd_lab.html b/introduction/templates/Lab/CMD/cmd_lab.html
index 2998cd3..19f2da1 100644
--- a/introduction/templates/Lab/CMD/cmd_lab.html
+++ b/introduction/templates/Lab/CMD/cmd_lab.html
@@ -7,6 +7,7 @@
Name Server Lookup
-
-
-{% endblock %}
\ No newline at end of file
+{% endblock %}
From 22685e6232c6f24f729ed2d307be4a281722da35 Mon Sep 17 00:00:00 2001
From: "patched.codes[bot]"
<298395+patched.codes[bot]@users.noreply.github.com>
Date: Tue, 25 Jun 2024 09:57:22 +0800
Subject: [PATCH 09/15] Patched
/private/var/folders/61/dwx9fsqs2k931dkwz6dg1ymw0000gn/T/tmp980zihnh/introduction/templates/Lab/A9/a9_lab.html
---
introduction/templates/Lab/A9/a9_lab.html | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/introduction/templates/Lab/A9/a9_lab.html b/introduction/templates/Lab/A9/a9_lab.html
index 5a70b46..7145c34 100644
--- a/introduction/templates/Lab/A9/a9_lab.html
+++ b/introduction/templates/Lab/A9/a9_lab.html
@@ -8,6 +8,7 @@