@@ -90,6 +90,7 @@ class WebSocketException(Exception):
90
90
from lib .core .exception import SqlmapCompressionException
91
91
from lib .core .exception import SqlmapConnectionException
92
92
from lib .core .exception import SqlmapGenericException
93
+ from lib .core .exception import SqlmapMissingDependence
93
94
from lib .core .exception import SqlmapSkipTargetException
94
95
from lib .core .exception import SqlmapSyntaxException
95
96
from lib .core .exception import SqlmapTokenException
@@ -603,11 +604,6 @@ class _(dict):
603
604
if not chunked :
604
605
requestMsg += "\r \n "
605
606
606
- if not multipart :
607
- threadData .lastRequestMsg = requestMsg
608
-
609
- logger .log (CUSTOM_LOGGING .TRAFFIC_OUT , requestMsg )
610
-
611
607
if conf .cj :
612
608
for cookie in conf .cj :
613
609
if cookie .value is None :
@@ -616,7 +612,46 @@ class _(dict):
616
612
for char in (r"\r" , r"\n" ):
617
613
cookie .value = re .sub (r"(%s)([^ \t])" % char , r"\g<1>\t\g<2>" , cookie .value )
618
614
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 )
620
655
621
656
if not kb .authHeader and getRequestHeader (req , HTTP_HEADER .AUTHORIZATION ) and (conf .authType or "" ).lower () == AUTH_TYPE .BASIC .lower ():
622
657
kb .authHeader = getUnicode (getRequestHeader (req , HTTP_HEADER .AUTHORIZATION ))
@@ -699,7 +734,7 @@ class _(dict):
699
734
# Explicit closing of connection object
700
735
if conn and not conf .keepAlive :
701
736
try :
702
- if hasattr (conn .fp , '_sock' ):
737
+ if hasattr (conn , "fp" ) and hasattr ( conn .fp , '_sock' ):
703
738
conn .fp ._sock .close ()
704
739
conn .close ()
705
740
except Exception as ex :
0 commit comments