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

Skip to content

Commit b71a810

Browse files
committed
implemented --tor-port by request
1 parent 89d2c7c commit b71a810

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

doc/THANKS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,9 @@ Ryan Sears <[email protected]>
470470
Uemit Seren <[email protected]>
471471
for reporting a minor adjustment when running with python 2.6
472472

473+
Shane Sewell <[email protected]>
474+
for suggesting a feature
475+
473476
Ahmed Shawky <[email protected]>
474477
for reporting a major bug with improper handling of parameter values
475478
for reporting a bug

lib/core/option.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

17381741
def __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

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173
"replicate": "boolean",
174174
"updateAll": "boolean",
175175
"tor": "boolean",
176+
"torPort": "integer",
176177
"torType": "string",
177178
},
178179

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ def cmdLineParser():
534534
action="store_true",
535535
help="Use Tor anonymity network")
536536

537+
general.add_option("--tor-port", dest="torPort",
538+
help="Set Tor proxy port other than default")
539+
537540
general.add_option("--tor-type", dest="torType",
538541
help="Set Tor proxy type (HTTP - default, SOCKS4 or SOCKS5)")
539542

sqlmap.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ replicate = False
577577
# Valid: True or False
578578
tor = False
579579

580+
# Set Tor proxy port other than default
581+
torPort =
582+
580583
# Set Tor proxy type.
581584
# Valid: HTTP, SOCKS4, SOCKS5
582585
torType = HTTP

0 commit comments

Comments
 (0)