2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2011-02-07 02:25:55 +03:00
|
|
|
|
|
|
|
"""
|
2022-01-03 13:30:34 +03:00
|
|
|
Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2011-02-07 02:25:55 +03:00
|
|
|
"""
|
|
|
|
|
2019-03-27 15:33:46 +03:00
|
|
|
from thirdparty.six.moves import urllib as _urllib
|
2011-02-07 02:25:55 +03:00
|
|
|
|
2019-03-27 15:33:46 +03:00
|
|
|
class SmartHTTPBasicAuthHandler(_urllib.request.HTTPBasicAuthHandler):
|
2011-02-07 02:25:55 +03:00
|
|
|
"""
|
|
|
|
Reference: http://selenic.com/hg/rev/6c51a5056020
|
|
|
|
Fix for a: http://bugs.python.org/issue8797
|
|
|
|
"""
|
2019-10-04 15:12:15 +03:00
|
|
|
|
2011-02-07 02:25:55 +03:00
|
|
|
def __init__(self, *args, **kwargs):
|
2019-03-27 15:33:46 +03:00
|
|
|
_urllib.request.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
|
2011-02-07 02:25:55 +03:00
|
|
|
self.retried_req = set()
|
2011-03-02 13:42:17 +03:00
|
|
|
self.retried_count = 0
|
2011-02-07 02:25:55 +03:00
|
|
|
|
|
|
|
def reset_retry_count(self):
|
|
|
|
# Python 2.6.5 will call this on 401 or 407 errors and thus loop
|
|
|
|
# forever. We disable reset_retry_count completely and reset in
|
|
|
|
# http_error_auth_reqed instead.
|
|
|
|
pass
|
|
|
|
|
|
|
|
def http_error_auth_reqed(self, auth_header, host, req, headers):
|
|
|
|
# Reset the retry counter once for each request.
|
|
|
|
if hash(req) not in self.retried_req:
|
|
|
|
self.retried_req.add(hash(req))
|
2011-03-02 13:42:17 +03:00
|
|
|
self.retried_count = 0
|
2011-03-02 13:29:38 +03:00
|
|
|
else:
|
2012-12-27 18:14:40 +04:00
|
|
|
if self.retried_count > 5:
|
2019-03-27 15:33:46 +03:00
|
|
|
raise _urllib.error.HTTPError(req.get_full_url(), 401, "basic auth failed", headers, None)
|
2012-12-27 18:14:40 +04:00
|
|
|
else:
|
|
|
|
self.retried_count += 1
|
2011-03-02 13:29:38 +03:00
|
|
|
|
2019-03-27 15:33:46 +03:00
|
|
|
return _urllib.request.HTTPBasicAuthHandler.http_error_auth_reqed(self, auth_header, host, req, headers)
|