@@ -1338,6 +1338,9 @@ class _(unicode): pass
13381338 if conf .csvDel :
13391339 conf .csvDel = conf .csvDel .decode ('string_escape' ) # e.g. '\\t' -> '\t'
13401340
1341+ if conf .torPort and conf .torPort .isdigit ():
1342+ conf .torPort = int (conf .torPort )
1343+
13411344 if conf .torType :
13421345 conf .torType = conf .torType .upper ()
13431346
@@ -1701,7 +1704,7 @@ def __setTorHttpProxySettings():
17011704
17021705 found = None
17031706
1704- for port in DEFAULT_TOR_HTTP_PORTS :
1707+ for port in ( DEFAULT_TOR_HTTP_PORTS if not conf . torPort else ( conf . torPort , )) :
17051708 try :
17061709 s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
17071710 s .connect ((LOCALHOST , port ))
@@ -1732,7 +1735,7 @@ def __setTorSocksProxySettings():
17321735 logger .info (infoMsg )
17331736
17341737 # Has to be SOCKS5 to prevent DNS leaks (http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29)
1735- socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if conf .torType == PROXYTYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , LOCALHOST , DEFAULT_TOR_SOCKS_PORT )
1738+ socks .setdefaultproxy (socks .PROXY_TYPE_SOCKS5 if conf .torType == PROXYTYPE .SOCKS5 else socks .PROXY_TYPE_SOCKS4 , LOCALHOST , conf . torPort or DEFAULT_TOR_SOCKS_PORT )
17361739 socks .wrapmodule (urllib2 )
17371740
17381741def __checkTor ():
@@ -1821,6 +1824,10 @@ def __basicOptionValidation():
18211824 errMsg = "switch --check-tor requires usage of switch --tor (or --proxy with HTTP proxy address using Tor)"
18221825 raise sqlmapSyntaxException , errMsg
18231826
1827+ if conf .torPort is not None and not (isinstance (conf .torPort , int ) and conf .torPort > 0 ):
1828+ errMsg = "value for --tor-port (torPort) option must be an integer value greater than zero (>0)"
1829+ raise sqlmapSyntaxException , errMsg
1830+
18241831 if conf .torType not in getPublicTypeMembers (PROXYTYPE , True ):
18251832 errMsg = "switch --tor-type accepts one of following values: %s" % ", " .join (getPublicTypeMembers (PROXYTYPE , True ))
18261833 raise sqlmapSyntaxException , errMsg
0 commit comments