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

Skip to content

Commit d291464

Browse files
committed
code refactoring regarding path normalization
1 parent dbd52c5 commit d291464

4 files changed

Lines changed: 25 additions & 22 deletions

File tree

lib/core/option.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from ConfigParser import ConfigParser
3636

3737
from lib.core.common import getFileType
38+
from lib.core.common import normalizePath
3839
from lib.core.common import ntToPosixSlashes
3940
from lib.core.common import parseTargetUrl
4041
from lib.core.common import paths
@@ -427,11 +428,11 @@ def __setMetasploit():
427428
raise sqlmapMissingPrivileges, errMsg
428429

429430
if conf.msfPath:
430-
condition = os.path.exists(os.path.normpath(conf.msfPath))
431-
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfcli")))
432-
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfconsole")))
433-
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfencode")))
434-
condition &= os.path.exists(os.path.normpath(os.path.join(conf.msfPath, "msfpayload")))
431+
condition = os.path.exists(normalizePath(conf.msfPath))
432+
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfcli")))
433+
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfconsole")))
434+
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfencode")))
435+
condition &= os.path.exists(normalizePath(os.path.join(conf.msfPath, "msfpayload")))
435436

436437
if condition:
437438
debugMsg = "provided Metasploit Framework 3 path "
@@ -466,11 +467,11 @@ def __setMetasploit():
466467

467468
for envPath in envPaths:
468469
envPath = envPath.replace(";", "")
469-
condition = os.path.exists(os.path.normpath(envPath))
470-
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfcli")))
471-
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfconsole")))
472-
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfencode")))
473-
condition &= os.path.exists(os.path.normpath(os.path.join(envPath, "msfpayload")))
470+
condition = os.path.exists(normalizePath(envPath))
471+
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfcli")))
472+
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfconsole")))
473+
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfencode")))
474+
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfpayload")))
474475

475476
if condition:
476477
infoMsg = "Metasploit Framework 3 has been found "
@@ -904,19 +905,19 @@ def __cleanupOptions():
904905
conf.delay = float(conf.delay)
905906

906907
if conf.rFile:
907-
conf.rFile = os.path.normpath(ntToPosixSlashes(conf.rFile))
908+
conf.rFile = normalizePath(ntToPosixSlashes(conf.rFile))
908909

909910
if conf.wFile:
910-
conf.wFile = os.path.normpath(ntToPosixSlashes(conf.wFile))
911+
conf.wFile = normalizePath(ntToPosixSlashes(conf.wFile))
911912

912913
if conf.dFile:
913-
conf.dFile = os.path.normpath(ntToPosixSlashes(conf.dFile))
914+
conf.dFile = normalizePath(ntToPosixSlashes(conf.dFile))
914915

915916
if conf.msfPath:
916-
conf.msfPath = os.path.normpath(ntToPosixSlashes(conf.msfPath))
917+
conf.msfPath = normalizePath(ntToPosixSlashes(conf.msfPath))
917918

918919
if conf.tmpPath:
919-
conf.tmpPath = os.path.normpath(ntToPosixSlashes(conf.tmpPath))
920+
conf.tmpPath = normalizePath(ntToPosixSlashes(conf.tmpPath))
920921

921922
if conf.googleDork or conf.list:
922923
conf.multipleTargets = True

lib/takeover/metasploit.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def __initVars(self):
7272
self.localIP = getLocalIP()
7373
self.remoteIP = getRemoteIP()
7474

75-
self.__msfCli = os.path.normpath(os.path.join(conf.msfPath, "msfcli"))
76-
self.__msfConsole = os.path.normpath(os.path.join(conf.msfPath, "msfconsole"))
77-
self.__msfEncode = os.path.normpath(os.path.join(conf.msfPath, "msfencode"))
78-
self.__msfPayload = os.path.normpath(os.path.join(conf.msfPath, "msfpayload"))
75+
self.__msfCli = normalizePath(os.path.join(conf.msfPath, "msfcli"))
76+
self.__msfConsole = normalizePath(os.path.join(conf.msfPath, "msfconsole"))
77+
self.__msfEncode = normalizePath(os.path.join(conf.msfPath, "msfencode"))
78+
self.__msfPayload = normalizePath(os.path.join(conf.msfPath, "msfpayload"))
7979

8080
self.__msfPayloadsList = {
8181
"windows": {

plugins/dbms/mysql.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lib.core.common import formatDBMSfp
3030
from lib.core.common import formatFingerprint
3131
from lib.core.common import getHtmlErrorFp
32+
from lib.core.common import normalizePath
3233
from lib.core.common import ntToPosixSlashes
3334
from lib.core.common import randomInt
3435
from lib.core.common import randomStr
@@ -497,7 +498,7 @@ def udfSetRemotePath(self):
497498

498499
# Reference: http://dev.mysql.com/doc/refman/5.1/en/server-options.html#option_mysqld_basedir
499500
self.__basedir = inject.getValue("SELECT @@basedir")
500-
self.__basedir = os.path.normpath(ntToPosixSlashes(self.__basedir))
501+
self.__basedir = normalizePath(ntToPosixSlashes(self.__basedir))
501502

502503
if re.search("^[\w]\:[\/\\\\]+", self.__basedir, re.I):
503504
kb.os = "Windows"
@@ -518,7 +519,7 @@ def udfSetRemotePath(self):
518519
# NOTE: specifying the relative path as './udf.dll'
519520
# saves in @@datadir on both MySQL 4.1 and MySQL 5.0
520521
self.__datadir = "."
521-
self.__datadir = os.path.normpath(ntToPosixSlashes(self.__datadir))
522+
self.__datadir = normalizePath(ntToPosixSlashes(self.__datadir))
522523

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

plugins/generic/misc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import os
2626
import re
2727

28+
from lib.core.common import normalizePath
2829
from lib.core.common import ntToPosixSlashes
2930
from lib.core.common import posixToNtSlashes
3031
from lib.core.common import readInput
@@ -68,7 +69,7 @@ def getRemoteTempPath(self):
6869
kb.os = "Windows"
6970

7071
conf.tmpPath = ntToPosixSlashes(conf.tmpPath)
71-
conf.tmpPath = os.path.normpath(conf.tmpPath)
72+
conf.tmpPath = normalizePath(conf.tmpPath)
7273

7374
setRemoteTempPath()
7475

0 commit comments

Comments
 (0)