Skip to content
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

修复--replay-proxy选项在命中一次请求后,后续所有的请求都走该选项设置的代理 #1251

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions db/dicc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4281,6 +4281,7 @@ CVS/Entries
CVS/Root
cvsadmin
cwadmin
cxf-service
d
d.php
d0main.php
Expand Down Expand Up @@ -4629,6 +4630,7 @@ dumper/
dumps/
dvdadmin
dvwa/
dwr/
dwsync.xml
dyn
DynaCacheESI
Expand Down Expand Up @@ -5289,6 +5291,7 @@ home.tar.bz2
home.tar.gz
home.zip
homepage
homepage.%EXT%
homepage.nsf
Homestead.json
Homestead.yaml
Expand Down Expand Up @@ -5788,6 +5791,7 @@ keygen
keys.json
kibana/
killer.php
kkconfig.xml
kmitaadmin
known_tokens.csv
kontakt
Expand Down Expand Up @@ -6169,6 +6173,7 @@ manage.py
manage/
manage/admin.asp
manage/fckeditor
manage/log
manage/login.asp
manage_admin
manage_index
Expand Down Expand Up @@ -9474,6 +9479,7 @@ WS_FTP.LOG
WS_FTP.log
WS_FTP/
WS_FTP/Sites/ws_ftp.ini
ws_utc/config.do
wsadmin.traceout
wsadmin.valout
wsadminListener.out
Expand Down
19 changes: 13 additions & 6 deletions lib/connection/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def set_proxy_auth(self, credential):
self._proxy_cred = credential

# :path: is expected not to start with "/"
def request(self, path, proxy=None):
def request(self, path, proxy=None, temp_proxies=None):
# Pause if the request rate exceeded the maximum
while self.is_rate_exceeded():
time.sleep(0.1)
Expand Down Expand Up @@ -175,6 +175,7 @@ def request(self, path, proxy=None):
allow_redirects=options["follow_redirects"],
timeout=options["timeout"],
stream=True,
proxies=temp_proxies
)
response = Response(response)

Expand All @@ -197,14 +198,20 @@ def request(self, path, proxy=None):
elif "TooManyRedirects" in str(e):
err_msg = f"Too many redirects: {url}"
elif "ProxyError" in str(e):
err_msg = f"Error with the proxy: {proxy}"
# Prevent from re-using it in the future
if proxy in options["proxies"] and len(options["proxies"]) > 1:
options["proxies"].remove(proxy)
if proxy:
err_msg = f"Error with the proxy: {proxy}"
# Prevent from re-using it in the future
if proxy in options["proxies"] and len(options["proxies"]) > 1:
options["proxies"].remove(proxy)
else:
err_msg = f"Error with the temp proxy: {temp_proxies}"
elif "InvalidURL" in str(e):
err_msg = f"Invalid URL: {url}"
elif "InvalidProxyURL" in str(e):
err_msg = f"Invalid proxy URL: {proxy}"
if proxy:
err_msg = f"Invalid proxy URL: {proxy}"
else:
err_msg = f"Invalid temp proxies: {temp_proxies}"
elif "ConnectionError" in str(e):
err_msg = f"Cannot connect to: {urlparse(url).netloc}"
elif re.search(READ_RESPONSE_ERROR_REGEX, str(e)):
Expand Down
16 changes: 15 additions & 1 deletion lib/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
SCRIPT_PATH,
STANDARD_PORTS,
UNKNOWN,
PROXY_SCHEMES,
)
from lib.parse.rawrequest import parse_raw
from lib.parse.url import clean_path, parse_path
Expand Down Expand Up @@ -461,7 +462,20 @@ def match_callback(self, response):

if options["replay_proxy"]:
# Replay the request with new proxy
self.requester.request(response.full_path, proxy=options["replay_proxy"])
proxy = options["replay_proxy"]

if not proxy.startswith(PROXY_SCHEMES):
proxy = f"http://{proxy}"

proxies = {"https": proxy}
if not proxy.startswith("https://"):
proxies["http"] = proxy

try:
self.requester.request(response.full_path, temp_proxies=proxies)
except RequestException as e:
logger.error(e)
options["replay_proxy"] = None

if self.report:
self.results.append(response)
Expand Down