|
4 | 4 | from introduction.playground.A9.main import Log |
5 | 5 | from introduction.playground.A6.utility import check_vuln |
6 | 6 | from django.contrib.auth import login,authenticate |
| 7 | +from .utility import * |
7 | 8 | from django.views.decorators.csrf import csrf_exempt |
8 | 9 | import time |
9 | 10 | from .views import authentication_decorator |
|
17 | 18 | def ssrf_code_checker(request): |
18 | 19 | if request.user.is_authenticated: |
19 | 20 | if request.method == 'POST': |
| 21 | + python_code = request.POST['python_code'] |
| 22 | + html_code = request.POST['html_code'] |
| 23 | + if not (ssrf_code_converter(python_code)): |
| 24 | + return JsonResponse({"status": "error", "message": "Invalid code"}) |
| 25 | + test_bench1 = ssrf_html_input_extractor(html_code) |
| 26 | + |
| 27 | + if (len(test_bench1) >4): |
| 28 | + return JsonResponse({'message':'too many inputs in Html\n Try again'},status = 400) |
| 29 | + test_bench2 = ['secret.txt'] |
| 30 | + correct_output1 = [{"blog": "blog1-passed"}, {"blog": "blog2-passed"}, {"blog": "blog3-passed"}, {"blog": "blog4-passed"}] |
| 31 | + outputs = [] |
| 32 | + for inputs in test_bench1: |
| 33 | + outputs.append(main.ssrf_lab(inputs)) |
| 34 | + if outputs == correct_output1: |
| 35 | + outputs = [] |
| 36 | + else: |
| 37 | + return JsonResponse({'message':'Testbench failed, Code is not working\n Try again'},status = 200) |
| 38 | + |
| 39 | + correct_output2 = [{"blog": "No blog found"}] |
| 40 | + for inputs in test_bench2: |
| 41 | + outputs.append(main.ssrf_lab(inputs)) |
| 42 | + if outputs == correct_output2: |
| 43 | + return JsonResponse({'message':'Congratulation, you have written a secure code.', 'passed':1}, status = 200) |
20 | 44 |
|
21 | 45 | return JsonResponse({'message':'Test bench passed but the code is not secure'}, status = 200,safe = False) |
22 | 46 | else: |
23 | | - return JsonResponse({'message':'1method not allowed'},status = 405) |
| 47 | + return JsonResponse({'message':'method not allowed'},status = 405) |
24 | 48 | else: |
25 | 49 | return JsonResponse({'message':'UnAuthenticated User'},status = 401) |
26 | 50 |
|
@@ -58,7 +82,7 @@ def log_function_checker(request): |
58 | 82 | f.close() |
59 | 83 | return JsonResponse({"message":"success", "logs": lines},status = 200) |
60 | 84 | else: |
61 | | - return JsonResponse({"message":"2method not allowed"},status = 405) |
| 85 | + return JsonResponse({"message":"method not allowed"},status = 405) |
62 | 86 |
|
63 | 87 | #a7 codechecking api |
64 | 88 | @csrf_exempt |
@@ -96,7 +120,7 @@ def A6_disscussion_api(request): |
96 | 120 | @csrf_exempt |
97 | 121 | def A6_disscussion_api_2(request): |
98 | 122 | if request.method != 'POST': |
99 | | - return JsonResponse({"message":"3method not allowed"},status = 405) |
| 123 | + return JsonResponse({"message":"method not allowed"},status = 405) |
100 | 124 | try: |
101 | 125 | code = request.POST.get('code') |
102 | 126 | dirname = os.path.dirname(__file__) |
|
0 commit comments