mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-22 17:46:37 +03:00
Refactoring of funcionality for finding out if stacking is available
This commit is contained in:
parent
8b4f72322a
commit
dc41484b3f
|
@ -2399,6 +2399,24 @@ def isTechniqueAvailable(technique):
|
||||||
else:
|
else:
|
||||||
return getTechniqueData(technique) is not None
|
return getTechniqueData(technique) is not None
|
||||||
|
|
||||||
|
def isStackingAvailable():
|
||||||
|
"""
|
||||||
|
Returns True whether techniques using stacking are available
|
||||||
|
"""
|
||||||
|
|
||||||
|
retVal = False
|
||||||
|
|
||||||
|
if PAYLOAD.TECHNIQUE.STACKED in kb.injection.data:
|
||||||
|
retVal = True
|
||||||
|
else:
|
||||||
|
for technique in getPublicTypeMembers(PAYLOAD.TECHNIQUE, True):
|
||||||
|
_ = getTechniqueData(technique)
|
||||||
|
if _ and "stacked" in _["title"].lower():
|
||||||
|
retVal = True
|
||||||
|
break
|
||||||
|
|
||||||
|
return retVal
|
||||||
|
|
||||||
def isInferenceAvailable():
|
def isInferenceAvailable():
|
||||||
"""
|
"""
|
||||||
Returns True whether techniques using inference technique are available
|
Returns True whether techniques using inference technique are available
|
||||||
|
|
|
@ -9,6 +9,7 @@ from extra.safe2bin.safe2bin import safechardecode
|
||||||
from lib.core.common import dataToStdout
|
from lib.core.common import dataToStdout
|
||||||
from lib.core.common import Backend
|
from lib.core.common import Backend
|
||||||
from lib.core.common import getSQLSnippet
|
from lib.core.common import getSQLSnippet
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.common import readInput
|
from lib.core.common import readInput
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
|
@ -39,7 +40,7 @@ class Abstraction(Web, UDF, Xp_cmdshell):
|
||||||
Xp_cmdshell.__init__(self)
|
Xp_cmdshell.__init__(self)
|
||||||
|
|
||||||
def execCmd(self, cmd, silent=False):
|
def execCmd(self, cmd, silent=False):
|
||||||
if self.webBackdoorUrl and not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if self.webBackdoorUrl and not isStackingAvailable():
|
||||||
self.webBackdoorRunCmd(cmd)
|
self.webBackdoorRunCmd(cmd)
|
||||||
|
|
||||||
elif Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
elif Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
||||||
|
@ -55,7 +56,7 @@ class Abstraction(Web, UDF, Xp_cmdshell):
|
||||||
def evalCmd(self, cmd, first=None, last=None):
|
def evalCmd(self, cmd, first=None, last=None):
|
||||||
retVal = None
|
retVal = None
|
||||||
|
|
||||||
if self.webBackdoorUrl and not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if self.webBackdoorUrl and not isStackingAvailable():
|
||||||
retVal = self.webBackdoorRunCmd(cmd)
|
retVal = self.webBackdoorRunCmd(cmd)
|
||||||
|
|
||||||
elif Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
elif Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
||||||
|
@ -92,7 +93,7 @@ class Abstraction(Web, UDF, Xp_cmdshell):
|
||||||
self.execCmd(cmd)
|
self.execCmd(cmd)
|
||||||
|
|
||||||
def shell(self):
|
def shell(self):
|
||||||
if self.webBackdoorUrl and not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if self.webBackdoorUrl and not isStackingAvailable():
|
||||||
infoMsg = "calling OS shell. To quit type "
|
infoMsg = "calling OS shell. To quit type "
|
||||||
infoMsg += "'x' or 'q' and press ENTER"
|
infoMsg += "'x' or 'q' and press ENTER"
|
||||||
logger.info(infoMsg)
|
logger.info(infoMsg)
|
||||||
|
@ -146,7 +147,7 @@ class Abstraction(Web, UDF, Xp_cmdshell):
|
||||||
if not conf.dbmsCred:
|
if not conf.dbmsCred:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not conf.direct and not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if not conf.direct and not isStackingAvailable():
|
||||||
errMsg = "stacked queries is not supported hence sqlmap cannot "
|
errMsg = "stacked queries is not supported hence sqlmap cannot "
|
||||||
errMsg += "execute statements as another user. The execution "
|
errMsg += "execute statements as another user. The execution "
|
||||||
errMsg += "will continue and the DBMS credentials provided "
|
errMsg += "will continue and the DBMS credentials provided "
|
||||||
|
|
|
@ -10,6 +10,7 @@ import os
|
||||||
from lib.core.agent import agent
|
from lib.core.agent import agent
|
||||||
from lib.core.common import dataToStdout
|
from lib.core.common import dataToStdout
|
||||||
from lib.core.common import Backend
|
from lib.core.common import Backend
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.common import readInput
|
from lib.core.common import readInput
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
|
@ -188,7 +189,7 @@ class UDF:
|
||||||
logger.error(errMsg)
|
logger.error(errMsg)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and not conf.direct:
|
if not isStackingAvailable() and not conf.direct:
|
||||||
errMsg = "UDF injection feature requires stacked queries SQL injection"
|
errMsg = "UDF injection feature requires stacked queries SQL injection"
|
||||||
logger.error(errMsg)
|
logger.error(errMsg)
|
||||||
return
|
return
|
||||||
|
|
|
@ -9,6 +9,7 @@ import re
|
||||||
|
|
||||||
from lib.core.agent import agent
|
from lib.core.agent import agent
|
||||||
from lib.core.common import Backend
|
from lib.core.common import Backend
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.common import normalizePath
|
from lib.core.common import normalizePath
|
||||||
from lib.core.common import ntToPosixSlashes
|
from lib.core.common import ntToPosixSlashes
|
||||||
|
@ -100,7 +101,7 @@ class Takeover(GenericTakeover):
|
||||||
logger.debug("keeping existing UDF '%s' as requested" % udf)
|
logger.debug("keeping existing UDF '%s' as requested" % udf)
|
||||||
|
|
||||||
def uncPathRequest(self):
|
def uncPathRequest(self):
|
||||||
if not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if not isStackingAvailable():
|
||||||
query = agent.prefixQuery("AND LOAD_FILE('%s')" % self.uncPath)
|
query = agent.prefixQuery("AND LOAD_FILE('%s')" % self.uncPath)
|
||||||
query = agent.suffixQuery(query)
|
query = agent.suffixQuery(query)
|
||||||
payload = agent.payload(newValue=query)
|
payload = agent.payload(newValue=query)
|
||||||
|
|
|
@ -12,6 +12,7 @@ from lib.core.common import dataToStdout
|
||||||
from lib.core.common import getPublicTypeMembers
|
from lib.core.common import getPublicTypeMembers
|
||||||
from lib.core.common import getSQLSnippet
|
from lib.core.common import getSQLSnippet
|
||||||
from lib.core.common import getTechniqueData
|
from lib.core.common import getTechniqueData
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.convert import utf8decode
|
from lib.core.convert import utf8decode
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
|
@ -41,15 +42,6 @@ class Custom:
|
||||||
sqlType = sqlTitle
|
sqlType = sqlTitle
|
||||||
break
|
break
|
||||||
|
|
||||||
stacked = isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED)
|
|
||||||
|
|
||||||
if not stacked:
|
|
||||||
for technique in getPublicTypeMembers(PAYLOAD.TECHNIQUE, True):
|
|
||||||
_ = getTechniqueData(technique)
|
|
||||||
if _ and "stacked" in _["title"].lower():
|
|
||||||
stacked = True
|
|
||||||
break
|
|
||||||
|
|
||||||
if "OPENROWSET" not in query.upper() and (not sqlType or "SELECT" in sqlType):
|
if "OPENROWSET" not in query.upper() and (not sqlType or "SELECT" in sqlType):
|
||||||
infoMsg = "fetching %s query output: '%s'" % (sqlType if sqlType is not None else "SQL", query)
|
infoMsg = "fetching %s query output: '%s'" % (sqlType if sqlType is not None else "SQL", query)
|
||||||
logger.info(infoMsg)
|
logger.info(infoMsg)
|
||||||
|
@ -57,7 +49,7 @@ class Custom:
|
||||||
output = inject.getValue(query, fromUser=True)
|
output = inject.getValue(query, fromUser=True)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
elif not stacked and not conf.direct:
|
elif not isStackingAvailable() and not conf.direct:
|
||||||
warnMsg = "execution of custom SQL queries is only "
|
warnMsg = "execution of custom SQL queries is only "
|
||||||
warnMsg += "available when stacked queries are supported"
|
warnMsg += "available when stacked queries are supported"
|
||||||
logger.warn(warnMsg)
|
logger.warn(warnMsg)
|
||||||
|
|
|
@ -14,6 +14,7 @@ from lib.core.common import decloakToTemp
|
||||||
from lib.core.common import decodeHexValue
|
from lib.core.common import decodeHexValue
|
||||||
from lib.core.common import isNumPosStrValue
|
from lib.core.common import isNumPosStrValue
|
||||||
from lib.core.common import isListLike
|
from lib.core.common import isListLike
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.common import readInput
|
from lib.core.common import readInput
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
|
@ -189,8 +190,8 @@ class Filesystem:
|
||||||
fileContent = None
|
fileContent = None
|
||||||
kb.fileReadMode = True
|
kb.fileReadMode = True
|
||||||
|
|
||||||
if conf.direct or isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if conf.direct or isStackingAvailable():
|
||||||
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if isStackingAvailable():
|
||||||
debugMsg = "going to read the file with stacked query SQL "
|
debugMsg = "going to read the file with stacked query SQL "
|
||||||
debugMsg += "injection technique"
|
debugMsg += "injection technique"
|
||||||
logger.debug(debugMsg)
|
logger.debug(debugMsg)
|
||||||
|
@ -260,8 +261,8 @@ class Filesystem:
|
||||||
if localFile.endswith('_'):
|
if localFile.endswith('_'):
|
||||||
localFile = decloakToTemp(localFile)
|
localFile = decloakToTemp(localFile)
|
||||||
|
|
||||||
if conf.direct or isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if conf.direct or isStackingAvailable():
|
||||||
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
|
if isStackingAvailable():
|
||||||
debugMsg = "going to upload the %s file with " % fileType
|
debugMsg = "going to upload the %s file with " % fileType
|
||||||
debugMsg += "stacked query SQL injection technique"
|
debugMsg += "stacked query SQL injection technique"
|
||||||
logger.debug(debugMsg)
|
logger.debug(debugMsg)
|
||||||
|
|
|
@ -10,6 +10,7 @@ import re
|
||||||
|
|
||||||
from lib.core.common import Backend
|
from lib.core.common import Backend
|
||||||
from lib.core.common import hashDBWrite
|
from lib.core.common import hashDBWrite
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.common import normalizePath
|
from lib.core.common import normalizePath
|
||||||
from lib.core.common import ntToPosixSlashes
|
from lib.core.common import ntToPosixSlashes
|
||||||
|
@ -125,7 +126,7 @@ class Miscellaneous:
|
||||||
self.delRemoteFile(self.webStagerFilePath)
|
self.delRemoteFile(self.webStagerFilePath)
|
||||||
self.delRemoteFile(self.webBackdoorFilePath)
|
self.delRemoteFile(self.webBackdoorFilePath)
|
||||||
|
|
||||||
if not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and not conf.direct:
|
if not isStackingAvailable() and not conf.direct:
|
||||||
return
|
return
|
||||||
|
|
||||||
if Backend.isOs(OS.WINDOWS):
|
if Backend.isOs(OS.WINDOWS):
|
||||||
|
|
|
@ -8,6 +8,7 @@ See the file 'doc/COPYING' for copying permission
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from lib.core.common import Backend
|
from lib.core.common import Backend
|
||||||
|
from lib.core.common import isStackingAvailable
|
||||||
from lib.core.common import isTechniqueAvailable
|
from lib.core.common import isTechniqueAvailable
|
||||||
from lib.core.common import readInput
|
from lib.core.common import readInput
|
||||||
from lib.core.common import runningAsAdmin
|
from lib.core.common import runningAsAdmin
|
||||||
|
@ -41,9 +42,9 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
Abstraction.__init__(self)
|
Abstraction.__init__(self)
|
||||||
|
|
||||||
def osCmd(self):
|
def osCmd(self):
|
||||||
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) or conf.direct:
|
if isStackingAvailable() or conf.direct:
|
||||||
web = False
|
web = False
|
||||||
elif not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and Backend.isDbms(DBMS.MYSQL):
|
elif not isStackingAvailable() and Backend.isDbms(DBMS.MYSQL):
|
||||||
infoMsg = "going to use a web backdoor for command execution"
|
infoMsg = "going to use a web backdoor for command execution"
|
||||||
logger.info(infoMsg)
|
logger.info(infoMsg)
|
||||||
|
|
||||||
|
@ -63,9 +64,9 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
self.cleanup(web=web)
|
self.cleanup(web=web)
|
||||||
|
|
||||||
def osShell(self):
|
def osShell(self):
|
||||||
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) or conf.direct:
|
if isStackingAvailable() or conf.direct:
|
||||||
web = False
|
web = False
|
||||||
elif not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and Backend.isDbms(DBMS.MYSQL):
|
elif not isStackingAvailable() and Backend.isDbms(DBMS.MYSQL):
|
||||||
infoMsg = "going to use a web backdoor for command prompt"
|
infoMsg = "going to use a web backdoor for command prompt"
|
||||||
logger.info(infoMsg)
|
logger.info(infoMsg)
|
||||||
|
|
||||||
|
@ -153,7 +154,7 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
if Backend.getIdentifiedDbms() in (DBMS.MYSQL, DBMS.PGSQL):
|
||||||
self.sysUdfs.pop("sys_bineval")
|
self.sysUdfs.pop("sys_bineval")
|
||||||
|
|
||||||
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) or conf.direct:
|
if isStackingAvailable() or conf.direct:
|
||||||
web = False
|
web = False
|
||||||
|
|
||||||
self.getRemoteTempPath()
|
self.getRemoteTempPath()
|
||||||
|
@ -202,7 +203,7 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
self.uploadIcmpshSlave(web=web)
|
self.uploadIcmpshSlave(web=web)
|
||||||
self.icmpPwn()
|
self.icmpPwn()
|
||||||
|
|
||||||
elif not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and Backend.isDbms(DBMS.MYSQL):
|
elif not isStackingAvailable() and Backend.isDbms(DBMS.MYSQL):
|
||||||
web = True
|
web = True
|
||||||
|
|
||||||
infoMsg = "going to use a web backdoor to establish the tunnel"
|
infoMsg = "going to use a web backdoor to establish the tunnel"
|
||||||
|
@ -250,7 +251,7 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
errMsg += "relay attack"
|
errMsg += "relay attack"
|
||||||
raise SqlmapUnsupportedDBMSException(errMsg)
|
raise SqlmapUnsupportedDBMSException(errMsg)
|
||||||
|
|
||||||
if not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and not conf.direct:
|
if not isStackingAvailable() and not conf.direct:
|
||||||
if Backend.getIdentifiedDbms() in (DBMS.PGSQL, DBMS.MSSQL):
|
if Backend.getIdentifiedDbms() in (DBMS.PGSQL, DBMS.MSSQL):
|
||||||
errMsg = "on this back-end DBMS it is only possible to "
|
errMsg = "on this back-end DBMS it is only possible to "
|
||||||
errMsg += "perform the SMB relay attack if stacked "
|
errMsg += "perform the SMB relay attack if stacked "
|
||||||
|
@ -292,7 +293,7 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
self.smb()
|
self.smb()
|
||||||
|
|
||||||
def osBof(self):
|
def osBof(self):
|
||||||
if not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and not conf.direct:
|
if not isStackingAvailable() and not conf.direct:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not Backend.isDbms(DBMS.MSSQL) or not Backend.isVersionWithin(("2000", "2005")):
|
if not Backend.isDbms(DBMS.MSSQL) or not Backend.isVersionWithin(("2000", "2005")):
|
||||||
|
@ -328,7 +329,7 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous):
|
||||||
raise SqlmapUndefinedMethod(errMsg)
|
raise SqlmapUndefinedMethod(errMsg)
|
||||||
|
|
||||||
def _regInit(self):
|
def _regInit(self):
|
||||||
if not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED) and not conf.direct:
|
if not isStackingAvailable() and not conf.direct:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.checkDbmsOs()
|
self.checkDbmsOs()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user