@@ -90,6 +90,7 @@ class WebSocketException(Exception):
9090from lib .core .exception import SqlmapCompressionException
9191from lib .core .exception import SqlmapConnectionException
9292from lib .core .exception import SqlmapGenericException
93+ from lib .core .exception import SqlmapMissingDependence
9394from lib .core .exception import SqlmapSkipTargetException
9495from lib .core .exception import SqlmapSyntaxException
9596from lib .core .exception import SqlmapTokenException
@@ -603,11 +604,6 @@ class _(dict):
603604 if not chunked :
604605 requestMsg += "\r \n "
605606
606- if not multipart :
607- threadData .lastRequestMsg = requestMsg
608-
609- logger .log (CUSTOM_LOGGING .TRAFFIC_OUT , requestMsg )
610-
611607 if conf .cj :
612608 for cookie in conf .cj :
613609 if cookie .value is None :
@@ -616,7 +612,46 @@ class _(dict):
616612 for char in (r"\r" , r"\n" ):
617613 cookie .value = re .sub (r"(%s)([^ \t])" % char , r"\g<1>\t\g<2>" , cookie .value )
618614
619- conn = _urllib .request .urlopen (req )
615+ if conf .http2 :
616+ try :
617+ import httpx
618+ with httpx .Client (verify = False , http2 = True , timeout = timeout , follow_redirects = True , cookies = conf .cj ) as client :
619+ conn = client .request (method or (HTTPMETHOD .POST if post is not None else HTTPMETHOD .GET ), url , headers = headers , data = post )
620+ except ImportError :
621+ raise SqlmapMissingDependence ("httpx[http2] not available (e.g. 'pip%s install httpx[http2]')" % ('3' if six .PY3 else "" ))
622+ else :
623+ conn .code = conn .status_code
624+ conn .msg = conn .reason_phrase
625+ conn .info = lambda c = conn : c .headers
626+
627+ conn ._read_buffer = conn .read ()
628+ conn ._read_offset = 0
629+
630+ requestMsg = re .sub (" HTTP/[0-9.]+\r \n " , " %s\r \n " % conn .http_version , requestMsg , count = 1 )
631+
632+ if not multipart :
633+ threadData .lastRequestMsg = requestMsg
634+
635+ logger .log (CUSTOM_LOGGING .TRAFFIC_OUT , requestMsg )
636+
637+ def _read (count = None ):
638+ offset = conn ._read_offset
639+ if count is None :
640+ result = conn ._read_buffer [offset :]
641+ conn ._read_offset = len (conn ._read_buffer )
642+ else :
643+ result = conn ._read_buffer [offset : offset + count ]
644+ conn ._read_offset += len (result )
645+ return result
646+
647+ conn .read = _read
648+ else :
649+ if not multipart :
650+ threadData .lastRequestMsg = requestMsg
651+
652+ logger .log (CUSTOM_LOGGING .TRAFFIC_OUT , requestMsg )
653+
654+ conn = _urllib .request .urlopen (req )
620655
621656 if not kb .authHeader and getRequestHeader (req , HTTP_HEADER .AUTHORIZATION ) and (conf .authType or "" ).lower () == AUTH_TYPE .BASIC .lower ():
622657 kb .authHeader = getUnicode (getRequestHeader (req , HTTP_HEADER .AUTHORIZATION ))
@@ -699,7 +734,7 @@ class _(dict):
699734 # Explicit closing of connection object
700735 if conn and not conf .keepAlive :
701736 try :
702- if hasattr (conn .fp , '_sock' ):
737+ if hasattr (conn , "fp" ) and hasattr ( conn .fp , '_sock' ):
703738 conn .fp ._sock .close ()
704739 conn .close ()
705740 except Exception as ex :
0 commit comments