code refactoring regarding path normalization

This commit is contained in:
Miroslav Stampar 2010-02-04 14:50:54 +00:00
parent dbd52c52e4
commit d291464cd4
4 changed files with 25 additions and 22 deletions

View File

@ -35,6 +35,7 @@ import urlparse
from ConfigParser import ConfigParser
from lib.core.common import getFileType
from lib.core.common import normalizePath
from lib.core.common import ntToPosixSlashes
from lib.core.common import parseTargetUrl
from lib.core.common import paths
@ -427,11 +428,11 @@ def __setMetasploit():
raise sqlmapMissingPrivileges, errMsg
if conf.msfPath:
condition = os.path.exists(os.path.normpath(conf.msfPath))
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfcli")))
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfconsole")))
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfencode")))
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfpayload")))
condition = os.path.exists(normalizePath(conf.msfPath))
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfcli")))
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfconsole")))
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfencode")))
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfpayload")))
if condition:
debugMsg = "provided Metasploit Framework 3 path "
@ -466,11 +467,11 @@ def __setMetasploit():
for envPath in envPaths:
envPath = envPath.replace(";", "")
condition = os.path.exists(os.path.normpath(envPath))
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfcli")))
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfconsole")))
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfencode")))
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfpayload")))
condition = os.path.exists(normalizePath(envPath))
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfcli")))
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfconsole")))
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfencode")))
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfpayload")))
if condition:
infoMsg = "Metasploit Framework 3 has been found "
@ -904,19 +905,19 @@ def __cleanupOptions():
conf.delay = float(conf.delay)
if conf.rFile:
conf.rFile = os.path.normpath(ntToPosixSlashes(conf.rFile))
conf.rFile = normalizePath(ntToPosixSlashes(conf.rFile))
if conf.wFile:
conf.wFile = os.path.normpath(ntToPosixSlashes(conf.wFile))
conf.wFile = normalizePath(ntToPosixSlashes(conf.wFile))
if conf.dFile:
conf.dFile = os.path.normpath(ntToPosixSlashes(conf.dFile))
conf.dFile = normalizePath(ntToPosixSlashes(conf.dFile))
if conf.msfPath:
conf.msfPath = os.path.normpath(ntToPosixSlashes(conf.msfPath))
conf.msfPath = normalizePath(ntToPosixSlashes(conf.msfPath))
if conf.tmpPath:
conf.tmpPath = os.path.normpath(ntToPosixSlashes(conf.tmpPath))
conf.tmpPath = normalizePath(ntToPosixSlashes(conf.tmpPath))
if conf.googleDork or conf.list:
conf.multipleTargets = True

View File

@ -72,10 +72,10 @@ class Metasploit:
self.localIP = getLocalIP()
self.remoteIP = getRemoteIP()
self.__msfCli = os.path.normpath(os.path.join(conf.msfPath, "msfcli"))
self.__msfConsole = os.path.normpath(os.path.join(conf.msfPath, "msfconsole"))
self.__msfEncode = os.path.normpath(os.path.join(conf.msfPath, "msfencode"))
self.__msfPayload = os.path.normpath(os.path.join(conf.msfPath, "msfpayload"))
self.__msfCli = normalizePath(os.path.join(conf.msfPath, "msfcli"))
self.__msfConsole = normalizePath(os.path.join(conf.msfPath, "msfconsole"))
self.__msfEncode = normalizePath(os.path.join(conf.msfPath, "msfencode"))
self.__msfPayload = normalizePath(os.path.join(conf.msfPath, "msfpayload"))
self.__msfPayloadsList = {
"windows": {

View File

@ -29,6 +29,7 @@ from lib.core.agent import agent
from lib.core.common import formatDBMSfp
from lib.core.common import formatFingerprint
from lib.core.common import getHtmlErrorFp
from lib.core.common import normalizePath
from lib.core.common import ntToPosixSlashes
from lib.core.common import randomInt
from lib.core.common import randomStr
@ -497,7 +498,7 @@ class MySQLMap(Fingerprint, Enumeration, Filesystem, Miscellaneous, Takeover):
# Reference: http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_basedir
self.__basedir = inject.getValue("SELECT @@basedir")
self.__basedir = os.path.normpath(ntToPosixSlashes(self.__basedir))
self.__basedir = normalizePath(ntToPosixSlashes(self.__basedir))
if re.search("^[\w]\:[\/\\\\]+", self.__basedir, re.I):
kb.os = "Windows"
@ -518,7 +519,7 @@ class MySQLMap(Fingerprint, Enumeration, Filesystem, Miscellaneous, Takeover):
# NOTE: specifying the relative path as './udf.dll'
# saves in @@datadir on both MySQL 4.1 and MySQL 5.0
self.__datadir = "."
self.__datadir = os.path.normpath(ntToPosixSlashes(self.__datadir))
self.__datadir = normalizePath(ntToPosixSlashes(self.__datadir))
if re.search("[\w]\:\/", self.__datadir, re.I):
kb.os = "Windows"

View File

@ -25,6 +25,7 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
import re
from lib.core.common import normalizePath
from lib.core.common import ntToPosixSlashes
from lib.core.common import posixToNtSlashes
from lib.core.common import readInput
@ -68,7 +69,7 @@ class Miscellaneous:
kb.os = "Windows"
conf.tmpPath = ntToPosixSlashes(conf.tmpPath)
conf.tmpPath = os.path.normpath(conf.tmpPath)
conf.tmpPath = normalizePath(conf.tmpPath)
setRemoteTempPath()