proper Tor settings (reverted r3915 and implemented it the right way)

This commit is contained in:
Miroslav Stampar 2011-05-24 11:06:58 +00:00
parent 0486d1cdaa
commit f774d8fea0
4 changed files with 51 additions and 25 deletions

View File

@ -99,7 +99,6 @@ class WARNFLAGS:
RANDOM_AGENT = 'randomAgent' RANDOM_AGENT = 'randomAgent'
DATA_TO_STDOUT = 'dataToStdout' DATA_TO_STDOUT = 'dataToStdout'
THREADS = 'threads' THREADS = 'threads'
TOR = 'tor'
class EXPECTED: class EXPECTED:
BOOL = "bool" BOOL = "bool"

View File

@ -62,6 +62,7 @@ from lib.core.enums import HTTPMETHOD
from lib.core.enums import MOBILES from lib.core.enums import MOBILES
from lib.core.enums import PAYLOAD from lib.core.enums import PAYLOAD
from lib.core.enums import PRIORITY from lib.core.enums import PRIORITY
from lib.core.exception import sqlmapConnectionException
from lib.core.exception import sqlmapFilePathException from lib.core.exception import sqlmapFilePathException
from lib.core.exception import sqlmapGenericException from lib.core.exception import sqlmapGenericException
from lib.core.exception import sqlmapMissingDependence from lib.core.exception import sqlmapMissingDependence
@ -74,6 +75,7 @@ from lib.core.exception import sqlmapUserQuitException
from lib.core.optiondict import optDict from lib.core.optiondict import optDict
from lib.core.settings import CODECS_LIST_PAGE from lib.core.settings import CODECS_LIST_PAGE
from lib.core.settings import DEFAULT_PAGE_ENCODING from lib.core.settings import DEFAULT_PAGE_ENCODING
from lib.core.settings import DEFAULT_TOR_PORTS
from lib.core.settings import IS_WIN from lib.core.settings import IS_WIN
from lib.core.settings import PLATFORM from lib.core.settings import PLATFORM
from lib.core.settings import PYVERSION from lib.core.settings import PYVERSION
@ -92,6 +94,7 @@ from lib.core.settings import FIREBIRD_ALIASES
from lib.core.settings import MAXDB_ALIASES from lib.core.settings import MAXDB_ALIASES
from lib.core.settings import SYBASE_ALIASES from lib.core.settings import SYBASE_ALIASES
from lib.core.settings import BURP_SPLITTER from lib.core.settings import BURP_SPLITTER
from lib.core.settings import LOCALHOST
from lib.core.settings import MAX_NUMBER_OF_THREADS from lib.core.settings import MAX_NUMBER_OF_THREADS
from lib.core.settings import TIME_DEFAULT_DELAY from lib.core.settings import TIME_DEFAULT_DELAY
from lib.core.settings import TIME_DELAY_CANDIDATES from lib.core.settings import TIME_DELAY_CANDIDATES
@ -1241,13 +1244,6 @@ def __cleanupOptions():
conf.nullConnection = not conf.textOnly conf.nullConnection = not conf.textOnly
conf.threads = 3 if conf.threads < 3 else conf.threads conf.threads = 3 if conf.threads < 3 else conf.threads
if conf.tor:
infoMsg = "setting Tor socks settings"
logger.info(infoMsg)
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, 'localhost', 9050)
socks.wrapmodule(urllib2)
if conf.data: if conf.data:
conf.data = urldecode(conf.data) conf.data = urldecode(conf.data)
@ -1575,6 +1571,42 @@ def __setTrafficOutputFP():
if conf.trafficFile: if conf.trafficFile:
conf.trafficFP = openFile(conf.trafficFile, "w+") conf.trafficFP = openFile(conf.trafficFile, "w+")
def __setTorProxySettings():
if not conf.tor:
return
infoMsg = "setting Tor proxy settings"
logger.info(infoMsg)
found = None
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
for port in DEFAULT_TOR_PORTS:
try:
s.connect((LOCALHOST, port))
found = port
break
except socket.error:
pass
s.close()
if found:
conf.proxy = "http://%s:%d" % (LOCALHOST, found)
else:
errMsg = "can't establish connection with the Tor proxy. "
errMsg += "please make sure that you have "
errMsg += "some kind of Vidalia/Privoxy/Polipo "
errMsg += "Tor proxy bundle installed for "
errMsg += "you to be able to successfully use "
errMsg += "--tor switch "
if IS_WIN:
errMsg += "(e.g. https://www.torproject.org/projects/vidalia.html.en)"
else:
errMsg += "(e.g. http://www.coresec.org/2011/04/24/sqlmap-with-tor/)"
raise sqlmapConnectionException, errMsg
def __basicOptionValidation(): def __basicOptionValidation():
if conf.limitStart is not None and not (isinstance(conf.limitStart, int) and conf.limitStart > 0): if conf.limitStart is not None and not (isinstance(conf.limitStart, int) and conf.limitStart > 0):
errMsg = "value for --start (limitStart) option must be an integer value greater than zero (>0)" errMsg = "value for --start (limitStart) option must be an integer value greater than zero (>0)"
@ -1670,6 +1702,7 @@ def init(inputOptions=advancedDict(), overrideOptions=False):
__setRequestFromFile() __setRequestFromFile()
__cleanupOptions() __cleanupOptions()
__basicOptionValidation() __basicOptionValidation()
__setTorProxySettings()
__setMultipleTargets() __setMultipleTargets()
__setTamperingFunctions() __setTamperingFunctions()
__setTrafficOutputFP() __setTrafficOutputFP()

View File

@ -333,3 +333,9 @@ CODECS_LIST_PAGE = 'http://docs.python.org/library/codecs.html#standard-encoding
# Simple regular expression used to distinguish scalar from multiple-row commands (not sole condition) # Simple regular expression used to distinguish scalar from multiple-row commands (not sole condition)
SQL_SCALAR_REGEX = r"\A(SELECT(?!\s+DISTINCT\(?))?\s*\w*\(" SQL_SCALAR_REGEX = r"\A(SELECT(?!\s+DISTINCT\(?))?\s*\w*\("
# IP address of the localhost
LOCALHOST = "127.0.0.1"
# Default ports used in Tor proxy bundles
DEFAULT_TOR_PORTS = (8118, 8123)

View File

@ -17,7 +17,6 @@ import urlparse
import traceback import traceback
from extra.multipart import multipartpost from extra.multipart import multipartpost
from extra.socks.socks import GeneralProxyError
from lib.core.agent import agent from lib.core.agent import agent
from lib.core.common import average from lib.core.common import average
from lib.core.common import calculateDeltaSeconds from lib.core.common import calculateDeltaSeconds
@ -362,7 +361,7 @@ class Connect:
page = processResponse(page, responseHeaders) page = processResponse(page, responseHeaders)
return page, responseHeaders return page, responseHeaders
except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead, GeneralProxyError), e: except (urllib2.URLError, socket.error, socket.timeout, httplib.BadStatusLine, httplib.IncompleteRead), e:
tbMsg = traceback.format_exc() tbMsg = traceback.format_exc()
if "no host given" in tbMsg: if "no host given" in tbMsg:
@ -399,21 +398,10 @@ class Connect:
logger.critical(warnMsg) logger.critical(warnMsg)
if kb.originalPage is None: if kb.originalPage is None:
if conf.tor: warnMsg = "if the problem persists please try to rerun "
warnMsg = "please make sure that you have " warnMsg += "with the --random-agent switch turned on "
warnMsg += "Tor installed and running for " warnMsg += "and/or try to use proxy switches (--ignore-proxy, --proxy,...)"
warnMsg += "you to be able to successfully use " singleTimeLogMessage(warnMsg, logging.WARN, WARNFLAGS.RANDOM_AGENT)
warnMsg += "--tor switch "
if IS_WIN:
warnMsg += "(e.g. https://www.torproject.org/download/download.html.en)"
else:
warnMsg += "(e.g. https://help.ubuntu.com/community/Tor)"
singleTimeLogMessage(warnMsg, logging.WARN, WARNFLAGS.TOR)
else:
warnMsg = "if the problem persists please try to rerun "
warnMsg += "with the --random-agent switch turned on "
warnMsg += "and/or try to use proxy switches (--ignore-proxy, --proxy,...)"
singleTimeLogMessage(warnMsg, logging.WARN, WARNFLAGS.RANDOM_AGENT)
elif conf.threads > 1: elif conf.threads > 1:
warnMsg = "if the problem persists please try to lower " warnMsg = "if the problem persists please try to lower "
warnMsg += "the number of used threads (--threads)" warnMsg += "the number of used threads (--threads)"