|
8 | 8 | from extra.safe2bin.safe2bin import safechardecode
|
9 | 9 | from lib.core.common import dataToStdout
|
10 | 10 | from lib.core.common import Backend
|
| 11 | +from lib.core.common import getSPQLSnippet |
11 | 12 | from lib.core.common import isTechniqueAvailable
|
12 | 13 | from lib.core.common import readInput
|
13 | 14 | from lib.core.data import conf
|
|
16 | 17 | from lib.core.enums import PAYLOAD
|
17 | 18 | from lib.core.exception import sqlmapUnsupportedFeatureException
|
18 | 19 | from lib.core.shell import autoCompletion
|
| 20 | +from lib.request import inject |
19 | 21 | from lib.takeover.udf import UDF
|
20 | 22 | from lib.takeover.web import Web
|
21 | 23 | from lib.takeover.xp_cmdshell import xp_cmdshell
|
@@ -139,7 +141,39 @@ def shell(self):
|
139 | 141 |
|
140 | 142 | self.runCmd(command)
|
141 | 143 |
|
| 144 | + def __initRunAs(self): |
| 145 | + if not conf.dCred: |
| 146 | + return |
| 147 | + |
| 148 | + if not conf.direct and not isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED): |
| 149 | + errMsg = "stacked queries is not supported hence sqlmap cannot " |
| 150 | + errMsg += "execute statements as another user. The execution " |
| 151 | + errMsg += "will continue and the DBMS credentials provided " |
| 152 | + errMsg += "will simply be ignored" |
| 153 | + logger.error(errMsg) |
| 154 | + |
| 155 | + return |
| 156 | + |
| 157 | + if Backend.isDbms(DBMS.MSSQL): |
| 158 | + msg = "on Microsoft SQL Server 2005 and 2008, OPENROWSET function " |
| 159 | + msg += "is disabled by default. This function is needed to execute " |
| 160 | + msg += "statements as another DBMS user since you provided the " |
| 161 | + msg += "--dbms-creds switch. If you are DBA, you can enable it. " |
| 162 | + msg += "Do you want to enable it? [Y/n] " |
| 163 | + choice = readInput(msg, default="Y") |
| 164 | + |
| 165 | + if not choice or choice in ("y", "Y"): |
| 166 | + expression = getSPQLSnippet(DBMS.MSSQL, "configure_openrowset", ENABLE="1") |
| 167 | + inject.goStacked(expression) |
| 168 | + |
| 169 | + # TODO: add support for PostgreSQL |
| 170 | + #elif Backend.isDbms(DBMS.PGSQL): |
| 171 | + # expression = getSPQLSnippet(DBMS.PGSQL, "configure_dblink", ENABLE="1") |
| 172 | + # inject.goStacked(expression) |
| 173 | + |
142 | 174 | def initEnv(self, mandatory=True, detailed=False, web=False):
|
| 175 | + self.__initRunAs() |
| 176 | + |
143 | 177 | if self.envInitialized:
|
144 | 178 | return
|
145 | 179 |
|
|
0 commit comments