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

Skip to content

Commit 7eab1bc

Browse files
committed
Automating even more switch --tor
1 parent 4c05307 commit 7eab1bc

4 files changed

Lines changed: 49 additions & 29 deletions

File tree

lib/core/common.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
from lib.core.settings import ISSUES_PAGE
120120
from lib.core.settings import IS_WIN
121121
from lib.core.settings import LARGE_OUTPUT_THRESHOLD
122+
from lib.core.settings import LOCALHOST
122123
from lib.core.settings import MIN_ENCODED_LEN_CHECK
123124
from lib.core.settings import MIN_TIME_RESPONSES
124125
from lib.core.settings import MIN_VALID_DELAYED_RESPONSE
@@ -2400,6 +2401,29 @@ def extractErrorMessage(page):
24002401

24012402
return retVal
24022403

2404+
def findLocalPort(ports):
2405+
"""
2406+
Find the first opened localhost port from a given list of ports (e.g. for Tor port checks)
2407+
"""
2408+
2409+
retVal = None
2410+
2411+
for port in ports:
2412+
try:
2413+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2414+
s.connect((LOCALHOST, port))
2415+
retVal = port
2416+
break
2417+
except socket.error:
2418+
pass
2419+
finally:
2420+
try:
2421+
s.close()
2422+
except socket.error:
2423+
pass
2424+
2425+
return retVal
2426+
24032427
def findMultipartPostBoundary(post):
24042428
"""
24052429
Finds value for a boundary parameter in given multipart POST body

lib/core/option.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from lib.core.common import getSafeExString
3939
from lib.core.common import extractRegexResult
4040
from lib.core.common import filterStringValue
41+
from lib.core.common import findLocalPort
4142
from lib.core.common import findPageForms
4243
from lib.core.common import getConsoleWidth
4344
from lib.core.common import getFileItems
@@ -108,7 +109,7 @@
108109
from lib.core.settings import DBMS_ALIASES
109110
from lib.core.settings import DEFAULT_PAGE_ENCODING
110111
from 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
112113
from lib.core.settings import DUMMY_URL
113114
from lib.core.settings import IGNORE_SAVE_OPTIONS
114115
from 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

23512347
def _checkWebSocket():

lib/core/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.0.10.23"
22+
VERSION = "1.0.10.24"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -430,10 +430,10 @@
430430
# IP address of the localhost
431431
LOCALHOST = "127.0.0.1"
432432

433-
# Default port used by Tor
434-
DEFAULT_TOR_SOCKS_PORT = 9050
433+
# Default SOCKS ports used by Tor
434+
DEFAULT_TOR_SOCKS_PORTS = (9050, 9150)
435435

436-
# Default ports used in Tor proxy bundles
436+
# Default HTTP ports used by Tor
437437
DEFAULT_TOR_HTTP_PORTS = (8123, 8118)
438438

439439
# Percentage below which comparison engine could have problems

txt/checksum.md5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ f15544a4c9c365ae8f2f8fa2e3a69aa5 lib/controller/checks.py
2626
cc9c82cfffd8ee9b25ba3af6284f057e lib/controller/__init__.py
2727
04f16204c899438dc7599a9a8426bfee lib/core/agent.py
2828
eb0bd28b0bd9fbf67dcc3119116df377 lib/core/bigarray.py
29-
c5aebf5a8a28af6290c45d403f4a1ac8 lib/core/common.py
29+
8bf4949483128163a34334207f1b78a7 lib/core/common.py
3030
5680d0c446a3bed5c0f2a0402d031557 lib/core/convert.py
3131
e77cca1cb063016f71f6e6bdebf4ec73 lib/core/data.py
3232
1d042f0bc0557d3fd564ea5a46deb77e lib/core/datatype.py
@@ -39,13 +39,13 @@ e4aec2b11c1ad6039d0c3dbbfbc5eb1a lib/core/exception.py
3939
cc9c82cfffd8ee9b25ba3af6284f057e lib/core/__init__.py
4040
91c514013daa796e2cdd940389354eac lib/core/log.py
4141
5b079749c50240602ea92637e268ed31 lib/core/optiondict.py
42-
e430ec19a22443205bba6cd811990bf3 lib/core/option.py
42+
b6f8d72812531ae010fc5b9ce4faba51 lib/core/option.py
4343
7af487340c138f7b5dbd443161cbb428 lib/core/profiling.py
4444
e60456db5380840a586654344003d4e6 lib/core/readlineng.py
4545
5ef56abb8671c2ca6ceecb208258e360 lib/core/replication.py
4646
99a2b496b9d5b546b335653ca801153f lib/core/revision.py
4747
7c15dd2777af4dac2c89cab6df17462e lib/core/session.py
48-
9af61d6fa1333a6635084ce02ea14643 lib/core/settings.py
48+
a226f17fafb974d0bc88f0a47171353b lib/core/settings.py
4949
7af83e4f18cab6dff5e67840eb65be80 lib/core/shell.py
5050
23657cd7d924e3c6d225719865855827 lib/core/subprocessng.py
5151
c3ace7874a536d801f308cf1fd03df99 lib/core/target.py

0 commit comments

Comments
 (0)