From f16389232f8822d82d958b650a2c3e48a8ced985 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Fri, 25 Sep 2015 15:23:42 +0200 Subject: [PATCH] Bug fix for --proxy-file (only first element was fetched in case of fail) --- lib/core/option.py | 35 +++++++++++++++++++++++------------ lib/utils/google.py | 7 +++++-- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/lib/core/option.py b/lib/core/option.py index 6eb4433a5..91f2996f9 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -27,6 +27,7 @@ import lib.core.common import lib.core.threads import lib.core.convert import lib.request.connect +import lib.utils.google from lib.controller.checks import checkConnection from lib.core.common import Backend @@ -91,6 +92,7 @@ from lib.core.exception import SqlmapInstallationException from lib.core.exception import SqlmapMissingDependence from lib.core.exception import SqlmapMissingMandatoryOptionException from lib.core.exception import SqlmapMissingPrivileges +from lib.core.exception import SqlmapNoneDataException from lib.core.exception import SqlmapSilentQuitException from lib.core.exception import SqlmapSyntaxException from lib.core.exception import SqlmapSystemException @@ -1084,18 +1086,22 @@ def _setHTTPProxy(): if hasattr(proxyHandler, "%s_open" % _): delattr(proxyHandler, "%s_open" % _) - if not conf.proxy: - if conf.proxyList: - conf.proxy = conf.proxyList[0] - conf.proxyList = conf.proxyList[1:] + conf.proxyList[:1] + if conf.proxyList is not None: + if not conf.proxyList: + errMsg = "list of usable proxies is empty" + raise SqlmapNoneDataException(errMsg) - infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy - logger.info(infoMsg) - else: - if conf.hostname in ('localhost', '127.0.0.1') or conf.ignoreProxy: - proxyHandler.proxies = {} + conf.proxy = conf.proxyList[0] + conf.proxyList = conf.proxyList[1:] - return + infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy + logger.info(infoMsg) + + elif not conf.proxy: + if conf.hostname in ("localhost", "127.0.0.1") or conf.ignoreProxy: + proxyHandler.proxies = {} + + return debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests" logger.debug(debugMsg) @@ -1127,7 +1133,7 @@ def _setHTTPProxy(): if conf.proxyCred: _ = re.search("^(.*?):(.*?)$", conf.proxyCred) if not _: - errMsg = "Proxy authentication credentials " + errMsg = "proxy authentication credentials " errMsg += "value must be in format username:password" raise SqlmapSyntaxException(errMsg) else: @@ -1735,7 +1741,7 @@ def _setConfAttributes(): conf.parameters = {} conf.path = None conf.port = None - conf.proxyList = [] + conf.proxyList = None conf.resultsFilename = None conf.resultsFP = None conf.scheme = None @@ -2413,6 +2419,10 @@ def _basicOptionValidation(): errMsg = "switch '--tor' is incompatible with option '--proxy'" raise SqlmapSyntaxException(errMsg) + if conf.proxy and conf.proxyFile: + errMsg = "switch '--proxy' is incompatible with option '--proxy-file'" + raise SqlmapSyntaxException(errMsg) + if conf.checkTor and not any((conf.tor, conf.proxy)): errMsg = "switch '--check-tor' requires usage of switch '--tor' (or option '--proxy' with HTTP proxy address using Tor)" raise SqlmapSyntaxException(errMsg) @@ -2480,6 +2490,7 @@ def _resolveCrossReferences(): lib.core.common.getPageTemplate = getPageTemplate lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage lib.request.connect.setHTTPProxy = _setHTTPProxy + lib.utils.google.setHTTPProxy = _setHTTPProxy lib.controller.checks.setVerbosity = setVerbosity def initOptions(inputOptions=AttribDict(), overrideOptions=False): diff --git a/lib/utils/google.py b/lib/utils/google.py index 8ee1ba99c..677fc4c72 100644 --- a/lib/utils/google.py +++ b/lib/utils/google.py @@ -48,7 +48,7 @@ class Google(object): self.opener.addheaders = conf.httpHeaders try: - conn = self.opener.open("http://www.google.com/ncr") + conn = self.opener.open("https://www.google.com/ncr") conn.info() # retrieve session cookie except Exception, ex: errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex) @@ -66,7 +66,7 @@ class Google(object): if not dork: return None - url = "http://www.google.com/search?" + url = "https://www.google.com/search?" url += "q=%s&" % urlencode(dork, convall=True) url += "num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search" url += "&start=%d" % ((gpage - 1) * 100) @@ -176,3 +176,6 @@ class Google(object): retVal = [urllib.unquote(match.group(1)) for match in re.finditer(regex, page, re.I | re.S)] return retVal + +def setHTTPProxy(): # Cross-linked function + raise NotImplementedError