140140from lib .request .connect import Connect as Request
141141from lib .request .dns import DNSServer
142142from lib .request .basicauthhandler import SmartHTTPBasicAuthHandler
143- from lib .request .httphandler import HTTPHandler
143+ from lib .request .chunkedhandler import ChunkedHandler
144144from lib .request .httpshandler import HTTPSHandler
145145from lib .request .pkihandler import HTTPSPKIAuthHandler
146146from lib .request .rangehandler import HTTPRangeHandler
158158from xml .etree .ElementTree import ElementTree
159159
160160authHandler = urllib2 .BaseHandler ()
161- httpHandler = HTTPHandler ()
161+ chunkedHandler = ChunkedHandler ()
162162httpsHandler = HTTPSHandler ()
163163keepAliveHandler = keepalive .HTTPHandler ()
164164proxyHandler = urllib2 .ProxyHandler ()
@@ -1109,7 +1109,7 @@ def _setHTTPHandlers():
11091109 debugMsg = "creating HTTP requests opener object"
11101110 logger .debug (debugMsg )
11111111
1112- handlers = filter (None , [multipartPostHandler , proxyHandler if proxyHandler .proxies else None , authHandler , redirectHandler , rangeHandler , httpHandler , httpsHandler ])
1112+ handlers = filter (None , [multipartPostHandler , proxyHandler if proxyHandler .proxies else None , authHandler , redirectHandler , rangeHandler , chunkedHandler if conf . chunked else None , httpsHandler ])
11131113
11141114 if not conf .dropSetCookie :
11151115 if not conf .loadCookies :
@@ -2314,6 +2314,10 @@ def _setTorSocksProxySettings():
23142314 socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if conf .torType == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , LOCALHOST , port )
23152315 socks .wrapmodule (urllib2 )
23162316
2317+ def _setHttpChunked ():
2318+ if conf .chunked and conf .data :
2319+ httplib .HTTPConnection ._set_content_length = lambda self , a , b : None
2320+
23172321def _checkWebSocket ():
23182322 if conf .url and (conf .url .startswith ("ws:/" ) or conf .url .startswith ("wss:/" )):
23192323 try :
@@ -2401,6 +2405,10 @@ def _basicOptionValidation():
24012405 errMsg = "switch '--dump' is incompatible with switch '--search'"
24022406 raise SqlmapSyntaxException (errMsg )
24032407
2408+ if conf .chunked and not any ((conf .data , conf .requestFile )):
2409+ errMsg = "switch '--chunked' requires usage of option '--data' or '-r'"
2410+ raise SqlmapSyntaxException (errMsg )
2411+
24042412 if conf .api and not conf .configFile :
24052413 errMsg = "switch '--api' requires usage of option '-c'"
24062414 raise SqlmapSyntaxException (errMsg )
@@ -2605,15 +2613,6 @@ def initOptions(inputOptions=AttribDict(), overrideOptions=False):
26052613 _setKnowledgeBaseAttributes ()
26062614 _mergeOptions (inputOptions , overrideOptions )
26072615
2608- def _setHttpChunked ():
2609- conf .chunk = conf .chunk and conf .data
2610- if conf .chunk :
2611- def hook (self , a , b ):
2612- pass
2613-
2614- httplib .HTTPConnection ._set_content_length = hook
2615-
2616-
26172616def init ():
26182617 """
26192618 Set attributes into both configuration and knowledge base singletons
@@ -2639,11 +2638,11 @@ def init():
26392638 _listTamperingFunctions ()
26402639 _setTamperingFunctions ()
26412640 _setPreprocessFunctions ()
2642- _setHttpChunked ()
26432641 _setWafFunctions ()
26442642 _setTrafficOutputFP ()
26452643 _setupHTTPCollector ()
26462644 _resolveCrossReferences ()
2645+ _setHttpChunked ()
26472646 _checkWebSocket ()
26482647
26492648 parseTargetDirect ()
0 commit comments