Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f163892

Browse files
committed
Bug fix for --proxy-file (only first element was fetched in case of fail)
1 parent 4774795 commit f163892

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

lib/core/option.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import lib.core.threads
2828
import lib.core.convert
2929
import lib.request.connect
30+
import lib.utils.google
3031

3132
from lib.controller.checks import checkConnection
3233
from lib.core.common import Backend
@@ -91,6 +92,7 @@
9192
from lib.core.exception import SqlmapMissingDependence
9293
from lib.core.exception import SqlmapMissingMandatoryOptionException
9394
from lib.core.exception import SqlmapMissingPrivileges
95+
from lib.core.exception import SqlmapNoneDataException
9496
from lib.core.exception import SqlmapSilentQuitException
9597
from lib.core.exception import SqlmapSyntaxException
9698
from lib.core.exception import SqlmapSystemException
@@ -1084,18 +1086,22 @@ def _setHTTPProxy():
10841086
if hasattr(proxyHandler, "%s_open" % _):
10851087
delattr(proxyHandler, "%s_open" % _)
10861088

1087-
if not conf.proxy:
1088-
if conf.proxyList:
1089-
conf.proxy = conf.proxyList[0]
1090-
conf.proxyList = conf.proxyList[1:] + conf.proxyList[:1]
1089+
if conf.proxyList is not None:
1090+
if not conf.proxyList:
1091+
errMsg = "list of usable proxies is empty"
1092+
raise SqlmapNoneDataException(errMsg)
10911093

1092-
infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy
1093-
logger.info(infoMsg)
1094-
else:
1095-
if conf.hostname in ('localhost', '127.0.0.1') or conf.ignoreProxy:
1096-
proxyHandler.proxies = {}
1094+
conf.proxy = conf.proxyList[0]
1095+
conf.proxyList = conf.proxyList[1:]
10971096

1098-
return
1097+
infoMsg = "loading proxy '%s' from a supplied proxy list file" % conf.proxy
1098+
logger.info(infoMsg)
1099+
1100+
elif not conf.proxy:
1101+
if conf.hostname in ("localhost", "127.0.0.1") or conf.ignoreProxy:
1102+
proxyHandler.proxies = {}
1103+
1104+
return
10991105

11001106
debugMsg = "setting the HTTP/SOCKS proxy for all HTTP requests"
11011107
logger.debug(debugMsg)
@@ -1127,7 +1133,7 @@ def _setHTTPProxy():
11271133
if conf.proxyCred:
11281134
_ = re.search("^(.*?):(.*?)$", conf.proxyCred)
11291135
if not _:
1130-
errMsg = "Proxy authentication credentials "
1136+
errMsg = "proxy authentication credentials "
11311137
errMsg += "value must be in format username:password"
11321138
raise SqlmapSyntaxException(errMsg)
11331139
else:
@@ -1735,7 +1741,7 @@ def _setConfAttributes():
17351741
conf.parameters = {}
17361742
conf.path = None
17371743
conf.port = None
1738-
conf.proxyList = []
1744+
conf.proxyList = None
17391745
conf.resultsFilename = None
17401746
conf.resultsFP = None
17411747
conf.scheme = None
@@ -2413,6 +2419,10 @@ def _basicOptionValidation():
24132419
errMsg = "switch '--tor' is incompatible with option '--proxy'"
24142420
raise SqlmapSyntaxException(errMsg)
24152421

2422+
if conf.proxy and conf.proxyFile:
2423+
errMsg = "switch '--proxy' is incompatible with option '--proxy-file'"
2424+
raise SqlmapSyntaxException(errMsg)
2425+
24162426
if conf.checkTor and not any((conf.tor, conf.proxy)):
24172427
errMsg = "switch '--check-tor' requires usage of switch '--tor' (or option '--proxy' with HTTP proxy address using Tor)"
24182428
raise SqlmapSyntaxException(errMsg)
@@ -2480,6 +2490,7 @@ def _resolveCrossReferences():
24802490
lib.core.common.getPageTemplate = getPageTemplate
24812491
lib.core.convert.singleTimeWarnMessage = singleTimeWarnMessage
24822492
lib.request.connect.setHTTPProxy = _setHTTPProxy
2493+
lib.utils.google.setHTTPProxy = _setHTTPProxy
24832494
lib.controller.checks.setVerbosity = setVerbosity
24842495

24852496
def initOptions(inputOptions=AttribDict(), overrideOptions=False):

lib/utils/google.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, handlers):
4848
self.opener.addheaders = conf.httpHeaders
4949

5050
try:
51-
conn = self.opener.open("http://www.google.com/ncr")
51+
conn = self.opener.open("https://www.google.com/ncr")
5252
conn.info() # retrieve session cookie
5353
except Exception, ex:
5454
errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex)
@@ -66,7 +66,7 @@ def search(self, dork):
6666
if not dork:
6767
return None
6868

69-
url = "http://www.google.com/search?"
69+
url = "https://www.google.com/search?"
7070
url += "q=%s&" % urlencode(dork, convall=True)
7171
url += "num=100&hl=en&complete=0&safe=off&filter=0&btnG=Search"
7272
url += "&start=%d" % ((gpage - 1) * 100)
@@ -176,3 +176,6 @@ def search(self, dork):
176176
retVal = [urllib.unquote(match.group(1)) for match in re.finditer(regex, page, re.I | re.S)]
177177

178178
return retVal
179+
180+
def setHTTPProxy(): # Cross-linked function
181+
raise NotImplementedError

0 commit comments

Comments
 (0)