Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a1b1f96

Browse files
committed
Finally fixed and adapted all code around to the new isWindowsDriveLetterPath() function
1 parent 0f80768 commit a1b1f96

11 files changed

Lines changed: 30 additions & 25 deletions

File tree

lib/core/common.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,14 @@ def getDocRoot(webApi=None):
249249
for absFilePath in kb.absFilePaths:
250250
if directoryPath(absFilePath) == '/':
251251
continue
252+
252253
absFilePath = normalizePath(absFilePath)
253254
absFilePathWin = None
254255

255256
if isWindowsPath(absFilePath):
256257
absFilePathWin = posixToNtSlashes(absFilePath)
257258
absFilePath = ntToPosixSlashes(absFilePath[2:])
258-
elif isWindowsDriveLetterPath(absFilePath): #e.g. C:/xampp/htdocs
259+
elif isWindowsDriveLetterPath(absFilePath): # E.g. C:/xampp/htdocs
259260
absFilePath = absFilePath[2:]
260261

261262
if pagePath in absFilePath:
@@ -309,10 +310,13 @@ def getDirs(webApi=None):
309310
for absFilePath in kb.absFilePaths:
310311
if absFilePath:
311312
directory = directoryPath(absFilePath)
313+
312314
if isWindowsPath(directory):
313315
directory = ntToPosixSlashes(directory)
316+
314317
if directory == '/':
315318
continue
319+
316320
directories.add(directory)
317321
else:
318322
warnMsg = "unable to retrieve any web server path"
@@ -981,21 +985,17 @@ def urlEncodeCookieValues(cookieStr):
981985
def directoryPath(path):
982986
retVal = None
983987

984-
if isWindowsPath(path):
988+
if isWindowsDriveLetterPath(path):
985989
retVal = ntpath.dirname(path)
986990
else:
987991
retVal = posixpath.dirname(path)
988992

989993
return retVal
990994

991995
def normalizePath(path):
992-
"""
993-
This function must be called only after posixToNtSlashes()
994-
and ntToPosixSlashes()
995-
"""
996996
retVal = None
997997

998-
if isWindowsPath(path):
998+
if isWindowsDriveLetterPath(path):
999999
retVal = ntpath.normpath(path)
10001000
else:
10011001
retVal = posixpath.normpath(path)

lib/core/option.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -852,19 +852,19 @@ def __cleanupOptions():
852852
conf.delay = float(conf.delay)
853853

854854
if conf.rFile:
855-
conf.rFile = normalizePath(ntToPosixSlashes(conf.rFile))
855+
conf.rFile = ntToPosixSlashes(normalizePath(conf.rFile))
856856

857857
if conf.wFile:
858-
conf.wFile = normalizePath(ntToPosixSlashes(conf.wFile))
858+
conf.wFile = ntToPosixSlashes(normalizePath(conf.wFile))
859859

860860
if conf.dFile:
861-
conf.dFile = normalizePath(ntToPosixSlashes(conf.dFile))
861+
conf.dFile = ntToPosixSlashes(normalizePath(conf.dFile))
862862

863863
if conf.msfPath:
864-
conf.msfPath = normalizePath(ntToPosixSlashes(conf.msfPath))
864+
conf.msfPath = ntToPosixSlashes(normalizePath(conf.msfPath))
865865

866866
if conf.tmpPath:
867-
conf.tmpPath = normalizePath(ntToPosixSlashes(conf.tmpPath))
867+
conf.tmpPath = ntToPosixSlashes(normalizePath(conf.tmpPath))
868868

869869
if conf.googleDork or conf.list:
870870
conf.multipleTargets = True

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"grant ", ),
114114

115115
"SQL data execution": (
116-
"exec ",
116+
" exec ",
117117
"execute ", ),
118118

119119
"SQL transaction": (

lib/request/basic.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
import StringIO
2929
import zlib
3030

31-
from lib.core.common import directoryPath
32-
from lib.core.common import isWindowsPath
31+
from lib.core.common import isWindowsDriveLetterPath
3332
from lib.core.common import posixToNtSlashes
3433
from lib.core.common import urlEncodeCookieValues
3534
from lib.core.data import conf
@@ -83,8 +82,10 @@ def parseResponse(page, headers):
8382
for match in reobj.finditer(page):
8483
absFilePath = match.group("result").strip()
8584
page = page.replace(absFilePath, "")
86-
if isWindowsPath(absFilePath):
85+
86+
if isWindowsDriveLetterPath(absFilePath):
8787
absFilePath = posixToNtSlashes(absFilePath)
88+
8889
if absFilePath not in kb.absFilePaths:
8990
kb.absFilePaths.add(absFilePath)
9091

lib/request/connect.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from lib.core.data import logger
3939
from lib.core.common import sanitizeAsciiString
4040
from lib.core.exception import sqlmapConnectionException
41-
from lib.core.settings import SQL_STATEMENTS
4241
from lib.request.basic import decodePage
4342
from lib.request.basic import forgeHeaders
4443
from lib.request.basic import parseResponse

lib/request/inject.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
from lib.core.data import temp
3939
from lib.request.connect import Connect as Request
4040
from lib.request.direct import direct
41-
from lib.core.settings import SQL_STATEMENTS
4241
from lib.techniques.inband.union.use import unionUse
4342
from lib.techniques.blind.inference import bisection
4443
from lib.utils.resume import queryOutputLength

lib/takeover/metasploit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
from lib.core.common import getLocalIP
3737
from lib.core.common import getRemoteIP
3838
from lib.core.common import normalizePath
39+
from lib.core.common import ntToPosixSlashes
3940
from lib.core.common import pollProcess
4041
from lib.core.common import randomRange
4142
from lib.core.common import randomStr
@@ -635,7 +636,7 @@ def uploadMsfPayloadStager(self, web=False):
635636
else:
636637
self.exeFilePathRemote = "%s/%s" % (conf.tmpPath, os.path.basename(self.exeFilePathLocal))
637638

638-
self.exeFilePathRemote = normalizePath(self.exeFilePathRemote)
639+
self.exeFilePathRemote = ntToPosixSlashes(normalizePath(self.exeFilePathRemote))
639640

640641
logger.info("uploading payload stager to '%s'" % self.exeFilePathRemote)
641642

lib/takeover/web.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,16 @@ def webInit(self):
178178
# Upload the uploader agent
179179
self.__webFileInject(uploaderContent, uploaderName, directory)
180180
requestDir = ntToPosixSlashes(directory)
181+
181182
if requestDir[-1] != '/':
182183
requestDir += '/'
183-
requestDir = requestDir.replace(ntToPosixSlashes(kb.docRoot), "/")
184+
185+
requestDir = requestDir.replace(ntToPosixSlashes(kb.docRoot), "/")
186+
184187
if isWindowsDriveLetterPath(requestDir):
185188
requestDir = requestDir[2:]
186-
requestDir = normalizePath(requestDir)
189+
190+
requestDir = normalizePath(requestDir)
187191

188192
self.webBaseUrl = "%s://%s:%d%s" % (conf.scheme, conf.hostname, conf.port, requestDir)
189193
self.webUploaderUrl = "%s/%s" % (self.webBaseUrl.rstrip('/'), uploaderName)

plugins/dbms/mssqlserver/filesystem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25+
import ntpath
2526
import os
2627

2728
from lib.core.common import getRange
@@ -146,8 +147,8 @@ def stackedWriteFile(self, wFile, dFile, fileType, confirm=True):
146147

147148
debugSize = 0xFF00
148149
tmpPath = posixToNtSlashes(conf.tmpPath)
149-
dFileName = os.path.split(dFile)[1]
150150
dFile = posixToNtSlashes(dFile)
151+
dFileName = ntpath.basename(dFile)
151152
wFileSize = os.path.getsize(wFile)
152153
wFilePointer = open(wFile, "rb")
153154
wFileContent = wFilePointer.read()

plugins/dbms/mysql/takeover.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def udfSetRemotePath(self):
5757

5858
# Reference: http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_basedir
5959
self.__basedir = inject.getValue("SELECT @@basedir")
60-
self.__basedir = normalizePath(ntToPosixSlashes(self.__basedir))
60+
self.__basedir = ntToPosixSlashes(normalizePath(self.__basedir))
6161

6262
if re.search("^[\w]\:[\/\\\\]+", self.__basedir, re.I):
6363
kb.os = "Windows"
@@ -78,7 +78,7 @@ def udfSetRemotePath(self):
7878
# NOTE: specifying the relative path as './udf.dll'
7979
# saves in @@datadir on both MySQL 4.1 and MySQL 5.0
8080
self.__datadir = "."
81-
self.__datadir = normalizePath(ntToPosixSlashes(self.__datadir))
81+
self.__datadir = ntToPosixSlashes(normalizePath(self.__datadir))
8282

8383
if re.search("[\w]\:\/", self.__datadir, re.I):
8484
kb.os = "Windows"

0 commit comments

Comments
 (0)