-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #128 from AikidoSec/fix-ssrf-https-bug
Fix ssrf https bug
- Loading branch information
Showing
20 changed files
with
263 additions
and
499 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Empty file.
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
"""Helper function file, exports normalize_url""" | ||
|
||
from urllib.parse import urlparse, urlunparse | ||
|
||
|
||
def normalize_url(url): | ||
"""Normalizes the url""" | ||
# Parse the URL | ||
parsed_url = urlparse(url) | ||
|
||
# Normalize components | ||
scheme = parsed_url.scheme.lower() # Lowercase scheme | ||
netloc = parsed_url.netloc.lower() # Lowercase netloc | ||
path = parsed_url.path.rstrip("/") # Remove trailing slash | ||
query = parsed_url.query # Keep query as is | ||
fragment = parsed_url.fragment # Keep fragment as is | ||
|
||
# Remove default ports (80 for http, 443 for https) | ||
if scheme == "http" and parsed_url.port == 80: | ||
netloc = netloc.replace(":80", "") | ||
elif scheme == "https" and parsed_url.port == 443: | ||
netloc = netloc.replace(":443", "") | ||
|
||
# Reconstruct the normalized URL | ||
normalized_url = urlunparse((scheme, netloc, path, "", query, fragment)) | ||
return normalized_url |
This file contains 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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
from .normalize_url import normalize_url | ||
|
||
|
||
def test_normalize_url(): | ||
# Test with standard URLs | ||
assert normalize_url("http://example.com") == "http://example.com" | ||
assert normalize_url("https://example.com") == "https://example.com" | ||
assert normalize_url("http://example.com/") == "http://example.com" | ||
assert normalize_url("http://example.com/path/") == "http://example.com/path" | ||
assert normalize_url("http://example.com/path") == "http://example.com/path" | ||
|
||
# Test with lowercase and uppercase schemes | ||
assert normalize_url("HTTP://EXAMPLE.COM") == "http://example.com" | ||
assert normalize_url("Https://EXAMPLE.COM") == "https://example.com" | ||
|
||
# Test with default ports | ||
assert normalize_url("http://example.com:80/path") == "http://example.com/path" | ||
assert normalize_url("https://example.com:443/path") == "https://example.com/path" | ||
|
||
# Test with non-default ports | ||
assert ( | ||
normalize_url("http://example.com:8080/path") == "http://example.com:8080/path" | ||
) | ||
assert ( | ||
normalize_url("https://example.com:8443/path") | ||
== "https://example.com:8443/path" | ||
) | ||
|
||
# Test with query parameters | ||
assert ( | ||
normalize_url("http://example.com/path?query=1") | ||
== "http://example.com/path?query=1" | ||
) | ||
assert ( | ||
normalize_url("http://example.com/path/?query=1") | ||
== "http://example.com/path?query=1" | ||
) | ||
|
||
# Test with fragments | ||
assert ( | ||
normalize_url("http://example.com/path#fragment") | ||
== "http://example.com/path#fragment" | ||
) | ||
assert ( | ||
normalize_url("http://example.com/path/?query=1#fragment") | ||
== "http://example.com/path?query=1#fragment" | ||
) | ||
|
||
# Test with URLs that have trailing slashes and mixed cases | ||
assert normalize_url("http://Example.com/Path/") == "http://example.com/Path" | ||
assert ( | ||
normalize_url("http://example.com/path/another/") | ||
== "http://example.com/path/another" | ||
) | ||
|
||
# Test with empty URL | ||
assert normalize_url("") == "" |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,29 +0,0 @@ | ||
"""Exports scan_for_ssrf_in_request function""" | ||
|
||
from aikido_firewall.helpers.logging import logger | ||
from .check_context_for_ssrf import check_context_for_ssrf | ||
from .is_redirect_to_private_ip import is_redirect_to_private_ip | ||
|
||
|
||
def scan_for_ssrf_in_request(url, port, operation, context): | ||
"""Scans for SSRF attacks""" | ||
|
||
# Check if the request is a SSRF : | ||
context_contains_ssrf_results = check_context_for_ssrf( | ||
url.hostname, port, operation, context | ||
) | ||
if context_contains_ssrf_results: | ||
return context_contains_ssrf_results | ||
|
||
# Check if the request is a SSRF with redirects : | ||
logger.debug("Redirects : %s", context.outgoing_req_redirects) | ||
redirected_ssrf_results = is_redirect_to_private_ip(url, context) | ||
if redirected_ssrf_results: | ||
return { | ||
"operation": operation, | ||
"kind": "ssrf", | ||
"source": redirected_ssrf_results["source"], | ||
"pathToPayload": redirected_ssrf_results["pathToPayload"], | ||
"metadata": {}, | ||
"payload": redirected_ssrf_results["payload"], | ||
} | ||
35 changes: 0 additions & 35 deletions
35
aikido_firewall/vulnerabilities/ssrf/check_context_for_ssrf.py
This file was deleted.
Oops, something went wrong.
77 changes: 0 additions & 77 deletions
77
aikido_firewall/vulnerabilities/ssrf/check_context_for_ssrf_test.py
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
aikido_firewall/vulnerabilities/ssrf/contains_private_ip_address.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.