Skip to content

Commit 614ff60

Browse files
committed
working on sqlmapproject#396 - handle the case when we dont have a web backdoor/file stager for the language API, added a few more log messages to give further information about what is going on, minor bug fix to docRoot
1 parent 3b38b20 commit 614ff60

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

lib/takeover/web.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ def webUpload(self, destFileName, directory, stream=None, content=None, filepath
8888
else:
8989
with open(filepath, "rb") as f:
9090
content = f.read()
91+
9192
if content is not None:
9293
stream = StringIO.StringIO(content) # string content
94+
9395
return self._webFileStreamUpload(stream, destFileName, directory)
9496

9597
def _webFileStreamUpload(self, stream, destFileName, directory):
@@ -114,12 +116,15 @@ def _webFileStreamUpload(self, stream, destFileName, directory):
114116
page = Request.getPage(url=self.webStagerUrl, multipart=multipartParams, raise404=False)
115117

116118
if "File uploaded" not in page:
117-
warnMsg = "unable to upload the backdoor through "
118-
warnMsg += "the file stager on '%s'" % directory
119+
warnMsg = "unable to upload the file through the web file "
120+
warnMsg += "stager to '%s'" % directory
119121
logger.warn(warnMsg)
120122
return False
121123
else:
122124
return True
125+
else:
126+
logger.error("sqlmap has not got a web backdoor nor a web file stager for %s" % self.webApi)
127+
return False
123128

124129
def _webFileInject(self, fileContent, fileName, directory):
125130
outFile = posixpath.normpath("%s/%s" % (directory, fileName))
@@ -152,9 +157,6 @@ def webInit(self):
152157

153158
self.checkDbmsOs()
154159

155-
infoMsg = "trying to upload the file stager"
156-
logger.info(infoMsg)
157-
158160
default = None
159161
choices = list(getPublicTypeMembers(WEB_API, True))
160162

@@ -199,7 +201,6 @@ def webInit(self):
199201

200202
stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webApi)
201203
stagerContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stager.%s_" % self.webApi))
202-
203204
success = False
204205

205206
for docRoot in kb.docRoot:
@@ -226,7 +227,6 @@ def webInit(self):
226227
else:
227228
localPath = directory
228229
uriPath = directory[2:] if isWindowsDriveLetterPath(directory) else directory
229-
docRoot = docRoot[2:] if isWindowsDriveLetterPath(docRoot) else docRoot
230230

231231
if docRoot in uriPath:
232232
uriPath = uriPath.replace(docRoot, "/")
@@ -243,6 +243,9 @@ def webInit(self):
243243
uriPath = posixpath.normpath(uriPath).rstrip('/')
244244

245245
# Upload the file stager with the LIMIT 0, 1 INTO OUTFILE technique
246+
infoMsg = "trying to upload the file stager on '%s' " % localPath
247+
infoMsg += "via LIMIT INTO OUTFILE technique"
248+
logger.info(infoMsg)
246249
self._webFileInject(stagerContent, stagerName, localPath)
247250

248251
self.webBaseUrl = "%s://%s:%d%s" % (conf.scheme, conf.hostname, conf.port, uriPath)
@@ -259,8 +262,8 @@ def webInit(self):
259262
singleTimeWarnMessage(warnMsg)
260263

261264
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION):
262-
infoMsg = "trying to upload the file stager via "
263-
infoMsg += "UNION technique"
265+
infoMsg = "trying to upload the file stager on '%s' " % localPath
266+
infoMsg += "via UNION technique"
264267
logger.info(infoMsg)
265268

266269
handle, filename = mkstemp()

0 commit comments

Comments
 (0)