sqlmap 0.7-rc3: Reset takeover OOB features (if any of --os-pwn, --os-smbrelay or --os-bof is selected) when running under Windows because msfconsole and msfcli are not supported on the native Windows Ruby interpreter. Correctly handle fcntl to be imported only on systems different from Windows. Minor code refactoring.

This commit is contained in:
Bernardo Damele 2009-06-11 15:01:48 +00:00
parent 3bca0d4b28
commit 150abc0f1e
5 changed files with 45 additions and 21 deletions

View File

@ -43,7 +43,7 @@ from lib.core.data import paths
from lib.core.data import queries from lib.core.data import queries
from lib.core.data import temp from lib.core.data import temp
from lib.core.exception import sqlmapFilePathException from lib.core.exception import sqlmapFilePathException
from lib.core.settings import PLATFORM from lib.core.settings import IS_WIN
from lib.core.settings import SQL_STATEMENTS from lib.core.settings import SQL_STATEMENTS
from lib.core.settings import VERSION_STRING from lib.core.settings import VERSION_STRING
@ -832,7 +832,7 @@ def searchEnvPath(fileName):
envPaths = os.environ["PATH"] envPaths = os.environ["PATH"]
result = None result = None
if "darwin" not in PLATFORM and "win" in PLATFORM: if IS_WIN is True:
envPaths = envPaths.split(";") envPaths = envPaths.split(";")
else: else:
envPaths = envPaths.split(":") envPaths = envPaths.split(":")

View File

@ -55,6 +55,7 @@ from lib.core.exception import sqlmapUnsupportedDBMSException
from lib.core.optiondict import optDict from lib.core.optiondict import optDict
from lib.core.settings import MSSQL_ALIASES from lib.core.settings import MSSQL_ALIASES
from lib.core.settings import MYSQL_ALIASES from lib.core.settings import MYSQL_ALIASES
from lib.core.settings import IS_WIN
from lib.core.settings import PLATFORM from lib.core.settings import PLATFORM
from lib.core.settings import SITE from lib.core.settings import SITE
from lib.core.settings import SUPPORTED_DBMS from lib.core.settings import SUPPORTED_DBMS
@ -267,6 +268,26 @@ def __setMetasploit():
if not conf.osPwn and not conf.osSmb and not conf.osBof: if not conf.osPwn and not conf.osSmb and not conf.osBof:
return return
debugMsg = "setting the takeover out-of-band functionality"
logger.debug(debugMsg)
msfEnvPathExists = False
if IS_WIN is True:
warnMsg = "Metasploit's msfconsole and msfcli are not supported "
warnMsg += "on the native Windows Ruby interpreter. Please "
warnMsg += "install Metasploit, Python interpreter and sqlmap on "
warnMsg += "Cygwin or use Linux in VMWare to use sqlmap takeover "
warnMsg += "out-of-band features. sqlmap will now continue "
warnMsg += "without calling any takeover feature"
logger.warn(warnMsg)
conf.osPwn = None
conf.osSmb = None
conf.osBof = None
return
if conf.osSmb: if conf.osSmb:
isAdmin = False isAdmin = False
@ -276,7 +297,7 @@ def __setMetasploit():
if isinstance(isAdmin, (int, float, long)) and isAdmin == 0: if isinstance(isAdmin, (int, float, long)) and isAdmin == 0:
isAdmin = True isAdmin = True
elif "win" in PLATFORM: elif IS_WIN is True:
isAdmin = ctypes.windll.shell32.IsUserAnAdmin() isAdmin = ctypes.windll.shell32.IsUserAnAdmin()
if isinstance(isAdmin, (int, float, long)) and isAdmin == 1: if isinstance(isAdmin, (int, float, long)) and isAdmin == 1:
@ -292,18 +313,13 @@ def __setMetasploit():
isAdmin = True isAdmin = True
if isAdmin != True: if isAdmin is not True:
errMsg = "you need to run sqlmap as an administrator/root " errMsg = "you need to run sqlmap as an Administrator/root "
errMsg += "user if you want to perform a SMB relay attack " errMsg += "user if you want to perform a SMB relay attack "
errMsg += "because it will need to listen on a user-specified " errMsg += "because it will need to listen on a user-specified "
errMsg += "SMB TCP port for incoming connection attempts" errMsg += "SMB TCP port for incoming connection attempts"
raise sqlmapMissingPrivileges, errMsg raise sqlmapMissingPrivileges, errMsg
debugMsg = "setting the out-of-band functionality"
logger.debug(debugMsg)
msfEnvPathExists = False
if conf.msfPath: if conf.msfPath:
condition = os.path.exists(os.path.normpath(conf.msfPath)) condition = os.path.exists(os.path.normpath(conf.msfPath))
condition &= os.path.exists(os.path.normpath("%s/msfcli" % conf.msfPath)) condition &= os.path.exists(os.path.normpath("%s/msfcli" % conf.msfPath))
@ -337,7 +353,7 @@ def __setMetasploit():
envPaths = os.environ["PATH"] envPaths = os.environ["PATH"]
if "darwin" not in PLATFORM and "win" in PLATFORM: if IS_WIN is True:
envPaths = envPaths.split(";") envPaths = envPaths.split(";")
else: else:
envPaths = envPaths.split(":") envPaths = envPaths.split(":")

View File

@ -32,6 +32,7 @@ boolean and _outputfile variable used in genutils.
import sys import sys
from lib.core.data import logger from lib.core.data import logger
from lib.core.settings import IS_WIN
from lib.core.settings import PLATFORM from lib.core.settings import PLATFORM
@ -49,7 +50,7 @@ except ImportError:
except ImportError: except ImportError:
haveReadline = False haveReadline = False
if 'win' in PLATFORM and 'darwin' not in PLATFORM and haveReadline: if IS_WIN is True and haveReadline:
try: try:
_outputfile=_rl.GetOutputFile() _outputfile=_rl.GetOutputFile()
except AttributeError: except AttributeError:

View File

@ -25,11 +25,12 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging import logging
import subprocess
import sys import sys
# sqlmap version and site # sqlmap version and site
VERSION = "0.7rc2" VERSION = "0.7rc3"
VERSION_STRING = "sqlmap/%s" % VERSION VERSION_STRING = "sqlmap/%s" % VERSION
SITE = "http://sqlmap.sourceforge.net" SITE = "http://sqlmap.sourceforge.net"
@ -46,6 +47,7 @@ LOGGER.addHandler(LOGGER_HANDLER)
LOGGER.setLevel(logging.WARN) LOGGER.setLevel(logging.WARN)
# System variables # System variables
IS_WIN = subprocess.mswindows
PLATFORM = sys.platform.lower() PLATFORM = sys.platform.lower()
PYVERSION = sys.version.split()[0] PYVERSION = sys.version.split()[0]

View File

@ -24,16 +24,20 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import fcntl
import errno import errno
import os import os
import sys import sys
import time import time
from lib.core.settings import IS_WIN
if (sys.hexversion >> 16) >= 0x202:
if IS_WIN is not True:
import fcntl
if (sys.hexversion >> 16) >= 0x202:
FCNTL = fcntl FCNTL = fcntl
else: else:
import FCNTL import FCNTL
@ -84,6 +88,7 @@ def setNonBlocking(fd):
Make a file descriptor non-blocking Make a file descriptor non-blocking
""" """
if IS_WIN is not True:
flags = fcntl.fcntl(fd, FCNTL.F_GETFL) flags = fcntl.fcntl(fd, FCNTL.F_GETFL)
flags = flags | os.O_NONBLOCK flags = flags | os.O_NONBLOCK
fcntl.fcntl(fd, FCNTL.F_SETFL, flags) fcntl.fcntl(fd, FCNTL.F_SETFL, flags)