Bug fix for --proxy-file (only first element was fetched in case of fail)

This commit is contained in:
Miroslav Stampar 2015-09-25 15:23:42 +02:00
parent 4774795d8c
commit f16389232f
2 changed files with 28 additions and 14 deletions

View File

@ -27,6 +27,7 @@ import lib.core.common
import lib.core.threads import lib.core.threads
import lib.core.convert import lib.core.convert
import lib.request.connect import lib.request.connect
import lib.utils.google
from lib.controller.checks import checkConnection from lib.controller.checks import checkConnection
from lib.core.common import Backend 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 SqlmapMissingDependence
from lib.core.exception import SqlmapMissingMandatoryOptionException from lib.core.exception import SqlmapMissingMandatoryOptionException
from lib.core.exception import SqlmapMissingPrivileges from lib.core.exception import SqlmapMissingPrivileges
from lib.core.exception import SqlmapNoneDataException
from lib.core.exception import SqlmapSilentQuitException from lib.core.exception import SqlmapSilentQuitException
from lib.core.exception import SqlmapSyntaxException from lib.core.exception import SqlmapSyntaxException
from lib.core.exception import SqlmapSystemException from lib.core.exception import SqlmapSystemException
@ -1084,18 +1086,22 @@ def _setHTTPProxy():
if hasattr(proxyHandler, "%s_open" % _): if hasattr(proxyHandler, "%s_open" % _):
delattr(proxyHandler, "%s_open" % _) delattr(proxyHandler, "%s_open" % _)
if not conf.proxy: if conf.proxyList is not None:
if conf.proxyList: if not conf.proxyList:
conf.proxy = conf.proxyList[0] errMsg = "list of usable proxies is empty"
conf.proxyList = conf.proxyList[1:] + conf.proxyList[:1] raise SqlmapNoneDataException(errMsg)
infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy conf.proxy = conf.proxyList[0]
logger.info(infoMsg) conf.proxyList = conf.proxyList[1:]
else:
if conf.hostname in ('localhost', '127.0.0.1') or conf.ignoreProxy:
proxyHandler.proxies = {}
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" debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
logger.debug(debugMsg) logger.debug(debugMsg)
@ -1127,7 +1133,7 @@ def _setHTTPProxy():
if conf.proxyCred: if conf.proxyCred:
_ = re.search("^(.*?):(.*?)$", conf.proxyCred) _ = re.search("^(.*?):(.*?)$", conf.proxyCred)
if not _: if not _:
errMsg = "Proxy authentication credentials " errMsg = "proxy authentication credentials "
errMsg += "value must be in format username:password" errMsg += "value must be in format username:password"
raise SqlmapSyntaxException(errMsg) raise SqlmapSyntaxException(errMsg)
else: else:
@ -1735,7 +1741,7 @@ def _setConfAttributes():
conf.parameters = {} conf.parameters = {}
conf.path = None conf.path = None
conf.port = None conf.port = None
conf.proxyList = [] conf.proxyList = None
conf.resultsFilename = None conf.resultsFilename = None
conf.resultsFP = None conf.resultsFP = None
conf.scheme = None conf.scheme = None
@ -2413,6 +2419,10 @@ def _basicOptionValidation():
errMsg = "switch '--tor' is incompatible with option '--proxy'" errMsg = "switch '--tor' is incompatible with option '--proxy'"
raise SqlmapSyntaxException(errMsg) 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)): 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)" errMsg = "switch '--check-tor' requires usage of switch '--tor' (or option '--proxy' with HTTP proxy address using Tor)"
raise SqlmapSyntaxException(errMsg) raise SqlmapSyntaxException(errMsg)
@ -2480,6 +2490,7 @@ def _resolveCrossReferences():
lib.core.common.getPageTemplate = getPageTemplate lib.core.common.getPageTemplate = getPageTemplate
lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage
lib.request.connect.setHTTPProxy = _setHTTPProxy lib.request.connect.setHTTPProxy = _setHTTPProxy
lib.utils.google.setHTTPProxy = _setHTTPProxy
lib.controller.checks.setVerbosity = setVerbosity lib.controller.checks.setVerbosity = setVerbosity
def initOptions(inputOptions=AttribDict(), overrideOptions=False): def initOptions(inputOptions=AttribDict(), overrideOptions=False):

View File

@ -48,7 +48,7 @@ class Google(object):
self.opener.addheaders = conf.httpHeaders self.opener.addheaders = conf.httpHeaders
try: try:
conn = self.opener.open("http://www.google.com/ncr") conn = self.opener.open("https://www.google.com/ncr")
conn.info() # retrieve session cookie conn.info() # retrieve session cookie
except Exception, ex: except Exception, ex:
errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex) errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex)
@ -66,7 +66,7 @@ class Google(object):
if not dork: if not dork:
return None return None
url = "http://www.google.com/search?" url = "https://www.google.com/search?"
url += "q=%s&" % urlencode(dork, convall=True) url += "q=%s&" % urlencode(dork, convall=True)
url += "num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search" url += "num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search"
url += "&start=%d" % ((gpage - 1) * 100) 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)] retVal = [urllib.unquote(match.group(1)) for match in re.finditer(regex, page, re.I | re.S)]
return retVal return retVal
def setHTTPProxy(): # Cross-linked function
raise NotImplementedError