@@ -63,7 +63,6 @@ class WebSocketException(Exception):
6363from lib .core .common import urldecode
6464from lib .core .common import urlencode
6565from lib .core .common import wasLastResponseDelayed
66- from lib .core .compat import LooseVersion
6766from lib .core .compat import patchHeaders
6867from lib .core .compat import xrange
6968from lib .core .convert import encodeBase64
@@ -111,7 +110,6 @@ class WebSocketException(Exception):
111110from lib .core .settings import JAVASCRIPT_HREF_REGEX
112111from lib .core .settings import LARGE_READ_TRIM_MARKER
113112from lib .core .settings import LIVE_COOKIES_TIMEOUT
114- from lib .core .settings import MIN_HTTPX_VERSION
115113from lib .core .settings import MAX_CONNECTION_READ_SIZE
116114from lib .core .settings import MAX_CONNECTIONS_REGEX
117115from lib .core .settings import MAX_CONNECTION_TOTAL_SIZE
@@ -632,49 +630,29 @@ class _(dict):
632630 cookie .value = re .sub (r"(%s)([^ \t])" % char , r"\g<1>\t\g<2>" , cookie .value )
633631
634632 if conf .http2 :
635- try :
636- import httpx
637- except ImportError :
638- raise SqlmapMissingDependence ("httpx[http2] not available (e.g. 'pip%s install httpx[http2]')" % ('3' if six .PY3 else "" ))
633+ from lib .request .http2 import open_url as http2OpenUrl
639634
640- if LooseVersion (httpx .__version__ ) < LooseVersion (MIN_HTTPX_VERSION ):
641- raise SqlmapMissingDependence ("outdated version of httpx detected (%s<%s)" % (httpx .__version__ , MIN_HTTPX_VERSION ))
635+ h2proxy = None
636+ if conf .proxy :
637+ _proxyParts = _urllib .parse .urlsplit (conf .proxy if "://" in conf .proxy else "http://%s" % conf .proxy )
638+ if (_proxyParts .scheme or "" ).lower ().startswith ("socks" ):
639+ raise SqlmapMissingDependence ("native HTTP/2 client does not support SOCKS proxies (omit '--http2' or use an HTTP proxy)" )
640+ h2proxy = (_proxyParts .hostname , _proxyParts .port or 8080 , conf .proxyCred or None )
642641
643642 try :
644- proxy_mounts = dict (("%s://" % key , httpx .HTTPTransport (proxy = "%s%s" % ("http://" if "://" not in kb .proxies [key ] else "" , kb .proxies [key ]))) for key in kb .proxies ) if kb .proxies else None
645- with httpx .Client (verify = False , http2 = True , timeout = timeout , follow_redirects = True , cookies = conf .cj , mounts = proxy_mounts ) as client :
646- conn = client .request (method or (HTTPMETHOD .POST if post is not None else HTTPMETHOD .GET ), url , headers = headers , data = post )
647- except (httpx .HTTPError , httpx .InvalidURL , httpx .CookieConflict , httpx .StreamError ) as ex :
643+ conn = http2OpenUrl (url , method or (HTTPMETHOD .POST if post is not None else HTTPMETHOD .GET ), headers , post , timeout , follow_redirects = kb .choices .redirect != REDIRECTION .NO , proxy = h2proxy )
644+ except IOError as ex :
648645 raise _http_client .HTTPException (getSafeExString (ex ))
649646 else :
650- if conn .status_code >= 400 :
651- raise _urllib .error .HTTPError (url , conn .status_code , conn .reason_phrase , conn .headers , io .BytesIO (conn .read ()))
652-
653- conn .code = conn .status_code
654- conn .msg = conn .reason_phrase
655- conn .info = lambda c = conn : c .headers
656-
657- conn ._read_buffer = conn .read ()
658- conn ._read_offset = 0
647+ if conn .code >= 400 :
648+ raise _urllib .error .HTTPError (url , conn .code , conn .msg , conn .info (), io .BytesIO (conn .read ()))
659649
660650 requestMsg = re .sub (r" HTTP/[0-9.]+\r\n" , " %s\r \n " % conn .http_version , requestMsg , count = 1 )
661651
662652 if not multipart :
663653 threadData .lastRequestMsg = requestMsg
664654
665655 logger .log (CUSTOM_LOGGING .TRAFFIC_OUT , requestMsg )
666-
667- def _read (count = None ):
668- offset = conn ._read_offset
669- if count is None :
670- result = conn ._read_buffer [offset :]
671- conn ._read_offset = len (conn ._read_buffer )
672- else :
673- result = conn ._read_buffer [offset : offset + count ]
674- conn ._read_offset += len (result )
675- return result
676-
677- conn .read = _read
678656 else :
679657 if not multipart :
680658 threadData .lastRequestMsg = requestMsg
0 commit comments