diff --git a/doc/THANKS b/doc/THANKS index 2a42b36ce..891704404 100644 --- a/doc/THANKS +++ b/doc/THANKS @@ -470,6 +470,9 @@ Ryan Sears Uemit Seren for reporting a minor adjustment when running with python 2.6 +Shane Sewell + for suggesting a feature + Ahmed Shawky for reporting a major bug with improper handling of parameter values for reporting a bug diff --git a/lib/core/option.py b/lib/core/option.py index 0ccc5377e..a2a072276 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1338,6 +1338,9 @@ def __cleanupOptions(): if conf.csvDel: conf.csvDel = conf.csvDel.decode('string_escape') # e.g. '\\t' -> '\t' + if conf.torPort and conf.torPort.isdigit(): + conf.torPort = int(conf.torPort) + if conf.torType: conf.torType = conf.torType.upper() @@ -1701,7 +1704,7 @@ def __setTorHttpProxySettings(): found = None - for port in DEFAULT_TOR_HTTP_PORTS: + for port in (DEFAULT_TOR_HTTP_PORTS if not conf.torPort else (conf.torPort, )): try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((LOCALHOST, port)) @@ -1732,7 +1735,7 @@ def __setTorSocksProxySettings(): logger.info(infoMsg) # Has to be SOCKS5 to prevent DNS leaks (http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29) - socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 if conf.torType == PROXYTYPE.SOCKS5 else socks.PROXY_TYPE_SOCKS4, LOCALHOST, DEFAULT_TOR_SOCKS_PORT) + socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 if conf.torType == PROXYTYPE.SOCKS5 else socks.PROXY_TYPE_SOCKS4, LOCALHOST, conf.torPort or DEFAULT_TOR_SOCKS_PORT) socks.wrapmodule(urllib2) def __checkTor(): @@ -1821,6 +1824,10 @@ def __basicOptionValidation(): errMsg = "switch --check-tor requires usage of switch --tor (or --proxy with HTTP proxy address using Tor)" raise sqlmapSyntaxException, errMsg + if conf.torPort is not None and not (isinstance(conf.torPort, int) and conf.torPort > 0): + errMsg = "value for --tor-port (torPort) option must be an integer value greater than zero (>0)" + raise sqlmapSyntaxException, errMsg + if conf.torType not in getPublicTypeMembers(PROXYTYPE, True): errMsg = "switch --tor-type accepts one of following values: %s" % ", ".join(getPublicTypeMembers(PROXYTYPE, True)) raise sqlmapSyntaxException, errMsg diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index 1928f5d2b..0f811de26 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -173,6 +173,7 @@ optDict = { "replicate": "boolean", "updateAll": "boolean", "tor": "boolean", + "torPort": "integer", "torType": "string", }, diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 872688308..1ef689c77 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -534,6 +534,9 @@ def cmdLineParser(): action="store_true", help="Use Tor anonymity network") + general.add_option("--tor-port", dest="torPort", + help="Set Tor proxy port other than default") + general.add_option("--tor-type", dest="torType", help="Set Tor proxy type (HTTP - default, SOCKS4 or SOCKS5)") diff --git a/sqlmap.conf b/sqlmap.conf index 6bd57c12f..cff6d7705 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -577,6 +577,9 @@ replicate = False # Valid: True or False tor = False +# Set Tor proxy port other than default +torPort = + # Set Tor proxy type. # Valid: HTTP, SOCKS4, SOCKS5 torType = HTTP