diff --git a/lib/core/option.py b/lib/core/option.py index 45fbed789..bcdb05716 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -163,42 +163,6 @@ proxyHandler = urllib2.ProxyHandler() redirectHandler = SmartRedirectHandler() rangeHandler = HTTPRangeHandler() -def _urllib2Opener(): - """ - This function creates the urllib2 OpenerDirector. - """ - - debugMsg = "creating HTTP requests opener object" - logger.debug(debugMsg) - - handlers = [proxyHandler, authHandler, redirectHandler, rangeHandler, httpsHandler] - - if not conf.dropSetCookie: - if not conf.loadCookies: - conf.cj = cookielib.CookieJar() - else: - conf.cj = cookielib.MozillaCookieJar() - resetCookieJar(conf.cj) - - handlers.append(urllib2.HTTPCookieProcessor(conf.cj)) - - # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html - if conf.keepAlive: - warnMsg = "persistent HTTP(s) connections, Keep-Alive, has " - warnMsg += "been disabled because of its incompatibility " - - if conf.proxy: - warnMsg += "with HTTP(s) proxy" - logger.warn(warnMsg) - elif conf.authType: - warnMsg += "with authentication methods" - logger.warn(warnMsg) - else: - handlers.append(keepAliveHandler) - - opener = urllib2.build_opener(*handlers) - urllib2.install_opener(opener) - def _feedTargetsDict(reqFile, addedTargetUrls): """ Parses web scarab and burp logs and adds results to the target URL list @@ -1160,6 +1124,37 @@ def _setHTTPProxy(): proxyHandler.__init__(proxyHandler.proxies) + debugMsg = "creating HTTP requests opener object" + logger.debug(debugMsg) + + handlers = filter(None, [proxyHandler if proxyHandler.proxies else None, authHandler, redirectHandler, rangeHandler, httpsHandler]) + + if not conf.dropSetCookie: + if not conf.loadCookies: + conf.cj = cookielib.CookieJar() + else: + conf.cj = cookielib.MozillaCookieJar() + resetCookieJar(conf.cj) + + handlers.append(urllib2.HTTPCookieProcessor(conf.cj)) + + # Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html + if conf.keepAlive: + warnMsg = "persistent HTTP(s) connections, Keep-Alive, has " + warnMsg += "been disabled because of its incompatibility " + + if conf.proxy: + warnMsg += "with HTTP(s) proxy" + logger.warn(warnMsg) + elif conf.authType: + warnMsg += "with authentication methods" + logger.warn(warnMsg) + else: + handlers.append(keepAliveHandler) + + opener = urllib2.build_opener(*handlers) + urllib2.install_opener(opener) + def _setSafeVisit(): """ Check and set the safe visit options. @@ -2550,7 +2545,6 @@ def init(): _setGoogleDorking() _setBulkMultipleTargets() _setSitemapTargets() - _urllib2Opener() _checkTor() _setCrawler() _findPageForms()