|
|
|
@ -31,24 +31,25 @@ def make_request(method, url, max_retries=SSRF_DEFAULT_MAX_RETRIES, **kwargs):
|
|
|
|
allow_redirects = kwargs.pop("allow_redirects")
|
|
|
|
allow_redirects = kwargs.pop("allow_redirects")
|
|
|
|
if "follow_redirects" not in kwargs:
|
|
|
|
if "follow_redirects" not in kwargs:
|
|
|
|
kwargs["follow_redirects"] = allow_redirects
|
|
|
|
kwargs["follow_redirects"] = allow_redirects
|
|
|
|
|
|
|
|
stream = kwargs.pop("stream", False)
|
|
|
|
retries = 0
|
|
|
|
retries = 0
|
|
|
|
while retries <= max_retries:
|
|
|
|
while retries <= max_retries:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
if SSRF_PROXY_ALL_URL:
|
|
|
|
client_args = {"proxy": SSRF_PROXY_ALL_URL} if SSRF_PROXY_ALL_URL else {}
|
|
|
|
with httpx.Client(proxy=SSRF_PROXY_ALL_URL) as client:
|
|
|
|
if proxy_mounts:
|
|
|
|
response = client.request(method=method, url=url, **kwargs)
|
|
|
|
client_args["mounts"] = proxy_mounts
|
|
|
|
elif proxy_mounts:
|
|
|
|
|
|
|
|
with httpx.Client(mounts=proxy_mounts) as client:
|
|
|
|
with httpx.Client(**client_args) as client:
|
|
|
|
response = client.request(method=method, url=url, **kwargs)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
with httpx.Client() as client:
|
|
|
|
|
|
|
|
response = client.request(method=method, url=url, **kwargs)
|
|
|
|
response = client.request(method=method, url=url, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
if response.status_code not in STATUS_FORCELIST:
|
|
|
|
if response.status_code not in STATUS_FORCELIST:
|
|
|
|
|
|
|
|
if stream:
|
|
|
|
|
|
|
|
return response.iter_bytes()
|
|
|
|
return response
|
|
|
|
return response
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
logging.warning(f"Received status code {response.status_code} for URL {url} which is in the force list")
|
|
|
|
logging.warning(
|
|
|
|
|
|
|
|
f"Received status code {response.status_code} for URL {url} which is in the force list"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
except httpx.RequestError as e:
|
|
|
|
except httpx.RequestError as e:
|
|
|
|
logging.warning(f"Request to URL {url} failed on attempt {retries + 1}: {e}")
|
|
|
|
logging.warning(f"Request to URL {url} failed on attempt {retries + 1}: {e}")
|
|
|
|
|