mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-09-04 09:00:51 +02:00
Add files via upload
This commit is contained in:
@@ -13,6 +13,7 @@ args:
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import urllib.request
|
||||||
from typing import Dict, List, Tuple
|
from typing import Dict, List, Tuple
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -150,39 +151,29 @@ args:
|
|||||||
|
|
||||||
|
|
||||||
def resolve_forward_proxy(explicit_proxy: str, trust_env: bool, url: str) -> str:
|
def resolve_forward_proxy(explicit_proxy: str, trust_env: bool, url: str) -> str:
|
||||||
"""Effective forward-proxy URL for absolute-form decisions (explicit > env)."""
|
"""Return the proxy that the custom transport must actually use."""
|
||||||
if explicit_proxy:
|
if explicit_proxy:
|
||||||
return explicit_proxy
|
return explicit_proxy
|
||||||
if not trust_env:
|
if not trust_env:
|
||||||
return ""
|
return ""
|
||||||
scheme = (urllib.parse.urlsplit(url).scheme or "").lower()
|
parsed = urllib.parse.urlsplit(url)
|
||||||
if scheme == "https":
|
host = parsed.hostname or ""
|
||||||
return (
|
# urllib handles NO_PROXY/no_proxy matching, including suffixes and '*'.
|
||||||
os.environ.get("HTTPS_PROXY")
|
if host and urllib.request.proxy_bypass(host):
|
||||||
or os.environ.get("https_proxy")
|
return ""
|
||||||
or os.environ.get("ALL_PROXY")
|
proxies = urllib.request.getproxies()
|
||||||
or os.environ.get("all_proxy")
|
scheme = (parsed.scheme or "").lower()
|
||||||
or ""
|
return proxies.get(scheme) or proxies.get("all") or ""
|
||||||
)
|
|
||||||
return (
|
|
||||||
os.environ.get("HTTP_PROXY")
|
|
||||||
or os.environ.get("http_proxy")
|
|
||||||
or os.environ.get("ALL_PROXY")
|
|
||||||
or os.environ.get("all_proxy")
|
|
||||||
or ""
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def needs_http_absolute_form(proxy: str, url: str) -> bool:
|
def needs_http_absolute_form(proxy: str, url: str) -> bool:
|
||||||
"""HTTP(S) forward proxy expects absolute-form target for plaintext HTTP."""
|
"""
|
||||||
if not proxy:
|
Keep the custom raw target in origin-form.
|
||||||
return False
|
|
||||||
try:
|
httpcore adds the scheme/authority itself when an HTTP forward proxy needs
|
||||||
proxy_scheme = urllib.parse.urlsplit(proxy).scheme.lower()
|
absolute-form. Supplying an absolute raw_path here would duplicate the URL.
|
||||||
url_scheme = urllib.parse.urlsplit(url).scheme.lower()
|
"""
|
||||||
except ValueError:
|
return False
|
||||||
return False
|
|
||||||
return url_scheme == "http" and proxy_scheme in {"http", "https"}
|
|
||||||
|
|
||||||
|
|
||||||
def display_url_for_target(url: str, wire_target: bytes) -> str:
|
def display_url_for_target(url: str, wire_target: bytes) -> str:
|
||||||
@@ -375,9 +366,31 @@ args:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def explain_request_error(exc: BaseException) -> str:
|
def explain_request_error(exc: BaseException, url: str = "", proxy: str = "") -> str:
|
||||||
text = str(exc)
|
text = str(exc)
|
||||||
lowered = text.lower()
|
lowered = text.lower()
|
||||||
|
if any(
|
||||||
|
marker in lowered
|
||||||
|
for marker in (
|
||||||
|
"temporary failure in name resolution",
|
||||||
|
"name or service not known",
|
||||||
|
"nodename nor servname provided",
|
||||||
|
"getaddrinfo failed",
|
||||||
|
)
|
||||||
|
):
|
||||||
|
target_host = urllib.parse.urlsplit(url).hostname or "目标主机"
|
||||||
|
if proxy:
|
||||||
|
proxy_host = urllib.parse.urlsplit(proxy).hostname or "代理服务器"
|
||||||
|
return (
|
||||||
|
text
|
||||||
|
+ f"\nHint: DNS 解析失败。当前请求经环境/显式代理 {proxy_host} 转发;"
|
||||||
|
"请确认代理进程可达,并检查代理地址本身能否解析。"
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
text
|
||||||
|
+ f"\nHint: DNS 暂时无法解析 {target_host}。请检查域名、容器/主机 DNS 与网络;"
|
||||||
|
"若运行环境要求代理,请设置 HTTPS_PROXY/HTTP_PROXY,或通过 proxy 参数显式传入。"
|
||||||
|
)
|
||||||
if "unexpected_eof" in lowered or "eof occurred in violation of protocol" in lowered:
|
if "unexpected_eof" in lowered or "eof occurred in violation of protocol" in lowered:
|
||||||
return (
|
return (
|
||||||
text
|
text
|
||||||
@@ -1114,8 +1127,11 @@ args:
|
|||||||
}
|
}
|
||||||
if cert:
|
if cert:
|
||||||
transport_kwargs["cert"] = cert
|
transport_kwargs["cert"] = cert
|
||||||
if explicit_proxy:
|
# Supplying a custom transport makes httpx.Client stop installing proxies
|
||||||
transport_kwargs["proxy"] = explicit_proxy
|
# from the environment. Pass the resolved env/explicit proxy directly so
|
||||||
|
# trust_env=true retains its documented behavior.
|
||||||
|
if forward_proxy:
|
||||||
|
transport_kwargs["proxy"] = forward_proxy
|
||||||
|
|
||||||
# Always path-as-is (security-testing default; matches curl --path-as-is)
|
# Always path-as-is (security-testing default; matches curl --path-as-is)
|
||||||
initial_absolute = needs_http_absolute_form(forward_proxy, encoded_url)
|
initial_absolute = needs_http_absolute_form(forward_proxy, encoded_url)
|
||||||
@@ -1148,7 +1164,7 @@ args:
|
|||||||
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
verify_tls = verify_option if isinstance(verify_option, bool) else True
|
verify_tls = verify_option if isinstance(verify_option, bool) else True
|
||||||
skip_probe = bool(explicit_proxy)
|
skip_probe = bool(forward_proxy)
|
||||||
|
|
||||||
client = httpx.Client(**client_kwargs)
|
client = httpx.Client(**client_kwargs)
|
||||||
try:
|
try:
|
||||||
@@ -1292,7 +1308,10 @@ args:
|
|||||||
exit_code = 1
|
exit_code = 1
|
||||||
elapsed = time.perf_counter() - start
|
elapsed = time.perf_counter() - start
|
||||||
print(f"\n===== Response #{run_index + 1} =====")
|
print(f"\n===== Response #{run_index + 1} =====")
|
||||||
print(f"Request failed after {elapsed:.6f}s: {explain_request_error(exc)}")
|
print(
|
||||||
|
f"Request failed after {elapsed:.6f}s: "
|
||||||
|
f"{explain_request_error(exc, encoded_url, forward_proxy)}"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if aggregate and repeat > 1:
|
if aggregate and repeat > 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user