From b70199cd8e9ad31ae7e8694f7c639185865167e8 Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 01/17] Patched introduction/mitre.py --- introduction/mitre.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/introduction/mitre.py b/introduction/mitre.py index c899c21..e522597 100644 --- a/introduction/mitre.py +++ b/introduction/mitre.py @@ -150,6 +150,8 @@ def mitre_top24(request): def mitre_top25(request): if request.method == 'GET': return render(request, 'mitre/mitre_top25.html') +import os +from django.http import JsonResponse @authentication_decorator def csrf_lab_login(request): @@ -158,23 +160,24 @@ def csrf_lab_login(request): 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=os.urandom(16), n=16384, r=8, p=1).hex() User = CSRF_user_tbl.objects.filter(username=username, password=password) if User: + secret = os.environ.get('JWT_SECRET_KEY', 'default_key') payload ={ 'username': username, 'exp': datetime.datetime.utcnow() + datetime.timedelta(seconds=300), 'iat': datetime.datetime.utcnow() } - cookie = jwt.encode(payload, 'csrf_vulneribility', algorithm='HS256') + cookie = jwt.encode(payload, secret, algorithm='HS256') 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 : return redirect('/mitre/9/lab/login') @authentication_decorator -@csrf_exempt def csrf_transfer_monei(request): if request.method == 'GET': try: @@ -208,14 +211,16 @@ def csrf_transfer_monei_api(request,recipent,amount): return redirect('/mitre/9/lab/transaction') else: return redirect ('/mitre/9/lab/transaction') +from ast import literal_eval - -# @authentication_decorator -@csrf_exempt +@authentication_decorator def mitre_lab_25_api(request): if request.method == "POST": expression = request.POST.get('expression') - result = eval(expression) + try: + result = literal_eval(expression) + except (SyntaxError, ValueError): + return JsonResponse({'error': 'Invalid expression'}) return JsonResponse({'result': result}) else: return redirect('/mitre/25/lab/') @@ -228,13 +233,10 @@ def mitre_lab_25(request): @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) + command = command.split() + process = subprocess.Popen(command, shell=False, 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') @@ -244,4 +246,4 @@ def mitre_lab_17_api(request): 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}) \ No newline at end of file + return JsonResponse({'raw_res': str(res), 'raw_err': str(err), 'ports': ports}) From 8c4fa74a57e7774a2c5858dca56662303e0c1ee8 Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 02/17] Patched introduction/templates/Lab/XSS/xss_lab_3.html --- introduction/templates/Lab/XSS/xss_lab_3.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/introduction/templates/Lab/XSS/xss_lab_3.html b/introduction/templates/Lab/XSS/xss_lab_3.html index a550b9a..7f9770d 100644 --- a/introduction/templates/Lab/XSS/xss_lab_3.html +++ b/introduction/templates/Lab/XSS/xss_lab_3.html @@ -17,9 +17,11 @@

Welcome to XSS Challenge


{{code}}

+{% json_script "safe_code" code %}
From f8c8a4d05a1565c920f28359618b73df81e95e89 Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 03/17] Patched introduction/templates/Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html --- .../Lab_2021/A1_BrokenAccessControl/broken_access_lab_1.html | 4 ++-- 1 file changed, 2 insertions(+), 2 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..e7dc04e 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,7 +9,7 @@

Admins Have the Secretkey

- + {% csrf_token %}

@@ -43,4 +43,4 @@

Please Provide Credentials

-{% endblock %} \ No newline at end of file +{% endblock %} From 6be39bc1fe06dbc9bd7a3a2c0b82a4ebde12f38e Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 04/17] Patched introduction/playground/A9/archive.py --- introduction/playground/A9/archive.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/introduction/playground/A9/archive.py b/introduction/playground/A9/archive.py index c9db8fc..d6f4be7 100644 --- a/introduction/playground/A9/archive.py +++ b/introduction/playground/A9/archive.py @@ -1,10 +1,7 @@ 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": @@ -33,12 +30,6 @@ def log_function_target(request): return JsonResponse({"message":"method not allowed"},status = 403) -# ====================================== - -import datetime - - -# f = open('test.log', 'a') --> use this file to log class Log: def __init__(self,request): self.request = request From 555be7a2ff83689219474b343635464923c3e774 Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 05/17] Patched 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 5ac64baf7c2f4c446c2c014122589f30d0aebfbc Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 06/17] Patched introduction/templates/Lab/A9/a9_lab2.html --- introduction/templates/Lab/A9/a9_lab2.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/introduction/templates/Lab/A9/a9_lab2.html b/introduction/templates/Lab/A9/a9_lab2.html index cace076..33b3a91 100644 --- a/introduction/templates/Lab/A9/a9_lab2.html +++ b/introduction/templates/Lab/A9/a9_lab2.html @@ -19,6 +19,7 @@

Some Example

+ {% csrf_token %} @@ -88,7 +89,11 @@

Some Example

form.submit(); } {% if error %} - alert("{{ data }}"); + {{ data }} + {% endif %} From 70fdd6cd32ddad47b53f7985920e3f330f599fd1 Mon Sep 17 00:00:00 2001 From: "patched.codes[bot]" <298395+patched.codes[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 14:58:44 +0800 Subject: [PATCH 07/17] Patched introduction/templates/Lab/ssrf/ssrf_discussion.html --- introduction/templates/Lab/ssrf/ssrf_discussion.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/introduction/templates/Lab/ssrf/ssrf_discussion.html b/introduction/templates/Lab/ssrf/ssrf_discussion.html index 7dc6678..2eb5868 100644 --- a/introduction/templates/Lab/ssrf/ssrf_discussion.html +++ b/introduction/templates/Lab/ssrf/ssrf_discussion.html @@ -123,22 +123,22 @@
ssrf_lab.html