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 @@
{{code}}
+{% json_script "safe_code" code %}