3838from lib .core .common import getSafeExString
3939from lib .core .common import extractRegexResult
4040from lib .core .common import filterStringValue
41+ from lib .core .common import findLocalPort
4142from lib .core .common import findPageForms
4243from lib .core .common import getConsoleWidth
4344from lib .core .common import getFileItems
108109from lib .core .settings import DBMS_ALIASES
109110from lib .core .settings import DEFAULT_PAGE_ENCODING
110111from lib .core .settings import DEFAULT_TOR_HTTP_PORTS
111- from lib .core .settings import DEFAULT_TOR_SOCKS_PORT
112+ from lib .core .settings import DEFAULT_TOR_SOCKS_PORTS
112113from lib .core .settings import DUMMY_URL
113114from lib .core .settings import IGNORE_SAVE_OPTIONS
114115from lib .core .settings import INJECT_HERE_MARK
@@ -2307,28 +2308,14 @@ def _setTorHttpProxySettings():
23072308 infoMsg = "setting Tor HTTP proxy settings"
23082309 logger .info (infoMsg )
23092310
2310- s = None
2311- found = None
2311+ port = findLocalPort (DEFAULT_TOR_HTTP_PORTS if not conf .torPort else (conf .torPort ,))
23122312
2313- for port in (DEFAULT_TOR_HTTP_PORTS if not conf .torPort else (conf .torPort ,)):
2314- try :
2315- s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
2316- s .connect ((LOCALHOST , port ))
2317- found = port
2318- break
2319- except socket .error :
2320- pass
2321-
2322- if s :
2323- s .close ()
2324-
2325- if found :
2326- conf .proxy = "http://%s:%d" % (LOCALHOST , found )
2313+ if port :
2314+ conf .proxy = "http://%s:%d" % (LOCALHOST , port )
23272315 else :
23282316 errMsg = "can't establish connection with the Tor HTTP proxy. "
2329- errMsg += "Please make sure that you have Vidalia, Privoxy or "
2330- errMsg += "Polipo bundle installed for you to be able to "
2331- errMsg += "successfully use switch '--tor' "
2317+ errMsg += "Please make sure that you have Tor (bundle) installed and setup "
2318+ errMsg += "so you could be able to successfully use switch '--tor' "
23322319
23332320 raise SqlmapConnectionException (errMsg )
23342321
@@ -2344,8 +2331,17 @@ def _setTorSocksProxySettings():
23442331 infoMsg = "setting Tor SOCKS proxy settings"
23452332 logger .info (infoMsg )
23462333
2347- # Has to be SOCKS5 to prevent DNS leaks (http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29)
2348- socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if conf .torType == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , LOCALHOST , conf .torPort or DEFAULT_TOR_SOCKS_PORT )
2334+ port = findLocalPort (DEFAULT_TOR_SOCKS_PORTS if not conf .torPort else (conf .torPort ,))
2335+
2336+ if not port :
2337+ errMsg = "can't establish connection with the Tor SOCKS proxy. "
2338+ errMsg += "Please make sure that you have Tor service installed and setup "
2339+ errMsg += "so you could be able to successfully use switch '--tor' "
2340+
2341+ raise SqlmapConnectionException (errMsg )
2342+
2343+ # SOCKS5 to prevent DNS leaks (http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29)
2344+ socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if conf .torType == PROXY_TYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , LOCALHOST , port )
23492345 socks .wrapmodule (urllib2 )
23502346
23512347def _checkWebSocket ():
0 commit comments