forked from adeyosemanputra/pygoat
-
Notifications
You must be signed in to change notification settings - Fork 8
Hardening suggestions for pygoat / view-returns-hash #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pixeebot
wants to merge
7
commits into
view-returns-hash
Choose a base branch
from
pixeebot/view-returns-hash
base: view-returns-hash
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
10be97d
Replace unsafe `pyyaml` loader with `SafeLoader`
pixeebot[bot] 179cc72
Use `shell=False` in `subprocess` Function Calls
pixeebot[bot] b8c8ca0
Use `defusedxml` for Parsing XML
pixeebot[bot] 5f7f3e6
Secure Source of Randomness
pixeebot[bot] 8f206bc
Sandbox Process Creation
pixeebot[bot] 580dcf0
Add timeout to `requests` calls
pixeebot[bot] 0f59e93
Sandbox URL Creation
pixeebot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,8 @@ | ||
| import hashlib | ||
| from django.shortcuts import render,redirect | ||
| from django.http import HttpResponse, HttpResponseBadRequest, JsonResponse | ||
| from .models import FAANG, AF_session_id,info,login,comments,authLogin, tickits, sql_lab_table,Blogs,CF_user,AF_admin | ||
| from django.core import serializers | ||
| from requests.structures import CaseInsensitiveDict | ||
| from django.contrib.auth import login,authenticate | ||
| from django.contrib.auth.forms import UserCreationForm | ||
| import random | ||
| from django.http import HttpResponse, HttpResponseBadRequest | ||
| from .models import FAANG, AF_session_id,login,comments,authLogin, tickits, sql_lab_table,Blogs,CF_user,AF_admin | ||
| from django.contrib.auth import login | ||
| import string | ||
| import os | ||
| from hashlib import md5 | ||
|
|
@@ -15,19 +11,15 @@ | |
| from django.contrib import messages | ||
| #*****************************************Lab Requirements****************************************************# | ||
|
|
||
| from .models import FAANG,info,login,comments,otp | ||
| from random import randint | ||
| from xml.dom.pulldom import parseString, START_ELEMENT | ||
| from .models import FAANG,login,comments,otp | ||
| from xml.dom.pulldom import START_ELEMENT | ||
| from xml.sax.handler import feature_external_ges | ||
| from xml.sax import make_parser | ||
| from django.views.decorators.csrf import csrf_exempt | ||
| from django.template import loader | ||
| from django.template.loader import render_to_string | ||
| import subprocess | ||
| import pickle | ||
| import base64 | ||
| import yaml | ||
| import json | ||
| from dataclasses import dataclass | ||
| import uuid | ||
| from .utility import filter_blog, customHash | ||
|
|
@@ -37,8 +29,12 @@ | |
| from io import BytesIO | ||
| from argon2 import PasswordHasher | ||
| import logging | ||
| import requests | ||
| import re | ||
| import defusedxml.pulldom | ||
| import defusedxml.sax | ||
| import secrets | ||
| from security import safe_requests, safe_command | ||
|
|
||
| #*****************************************Login and Registration****************************************************# | ||
|
|
||
| def get_hash(request): | ||
|
|
@@ -255,9 +251,9 @@ def xxe_see(request): | |
| @csrf_exempt | ||
| def xxe_parse(request): | ||
|
|
||
| parser = make_parser() | ||
| parser = defusedxml.sax.make_parser() | ||
| parser.setFeature(feature_external_ges, True) | ||
| doc = parseString(request.body.decode('utf-8'), parser=parser) | ||
| doc = defusedxml.pulldom.parseString(request.body.decode('utf-8'), parser=parser) | ||
| for event, node in doc: | ||
| if event == START_ELEMENT and node.tagName == 'text': | ||
| doc.expandNode(node) | ||
|
|
@@ -426,10 +422,8 @@ def cmd_lab(request): | |
|
|
||
| try: | ||
| # output=subprocess.check_output(command,shell=True,encoding="UTF-8") | ||
| process = subprocess.Popen( | ||
| command, | ||
| shell=True, | ||
| stdout=subprocess.PIPE, | ||
| process = safe_command.run(subprocess.Popen, command, | ||
| shell=False, stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE) | ||
| stdout, stderr = process.communicate() | ||
| data = stdout.decode('utf-8') | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set |
||
|
|
@@ -492,7 +486,7 @@ def login_otp(request): | |
| def Otp(request): | ||
| if request.method=="GET": | ||
| email=request.GET.get('email') | ||
| otpN=randint(100,999) | ||
| otpN=secrets.SystemRandom().randint(100,999) | ||
| if email and otpN: | ||
| if email=="[email protected]": | ||
| otp.objects.filter(id=2).update(otp=otpN) | ||
|
|
@@ -556,7 +550,7 @@ def a9_lab(request): | |
| try : | ||
| file=request.FILES["file"] | ||
| try : | ||
| data = yaml.load(file,yaml.Loader) | ||
| data = yaml.load(file,yaml.SafeLoader) | ||
|
|
||
| return render(request,"Lab/A9/a9_lab.html",{"data":data}) | ||
| except: | ||
|
|
@@ -676,7 +670,7 @@ def a10_lab2(request): | |
| #*********************************************************A11*************************************************# | ||
|
|
||
| def gentckt(): | ||
| return (''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase, k=10))) | ||
| return (''.join(secrets.SystemRandom().choices(string.ascii_uppercase + string.ascii_lowercase, k=10))) | ||
|
|
||
| def insec_desgine(request): | ||
| if request.user.is_authenticated: | ||
|
|
@@ -959,7 +953,7 @@ def ssrf_lab2(request): | |
| elif request.method == "POST": | ||
| url = request.POST["url"] | ||
| try: | ||
| response = requests.get(url) | ||
| response = safe_requests.get(url, timeout=60) | ||
| return render(request, "Lab/ssrf/ssrf_lab2.html", {"response": response.content.decode()}) | ||
| except: | ||
| return render(request, "Lab/ssrf/ssrf_lab2.html", {"error": "Invalid URL"}) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ urllib3==1.26.9 | |
| Werkzeug==2.1.2 | ||
| whitenoise==6.2.0 | ||
| zipp==3.8.0 | ||
| security==1.2.1 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This library holds security tools for protecting Python API calls. License: MIT ✅ Open Source ✅ More facts |
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace builtin XML method with safe
defusedxmlmethod