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.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):

View File

@ -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