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

Skip to content

Commit 6bc0b34

Browse files
committed
Some more refactoring
1 parent e948e4d commit 6bc0b34

1 file changed

Lines changed: 10 additions & 25 deletions

File tree

lib/core/option.py

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -570,15 +570,15 @@ def __setDBMSAuthentication():
570570
debugMsg = "setting the DBMS authentication credentials"
571571
logger.debug(debugMsg)
572572

573-
dCredRegExp = re.search("^(.+?):(.*?)$", conf.dCred)
573+
match = re.search("^(.+?):(.*?)$", conf.dCred)
574574

575-
if not dCredRegExp:
575+
if not match:
576576
errMsg = "DBMS authentication credentials value must be in format "
577577
errMsg += "username:password"
578578
raise sqlmapSyntaxException, errMsg
579579

580-
conf.dbmsUsername = dCredRegExp.group(1)
581-
conf.dbmsPassword = dCredRegExp.group(2)
580+
conf.dbmsUsername = match.group(1)
581+
conf.dbmsPassword = match.group(2)
582582

583583
def __setMetasploit():
584584
if not conf.osPwn and not conf.osSmb and not conf.osBof:
@@ -609,20 +609,15 @@ def __setMetasploit():
609609
raise sqlmapMissingPrivileges, errMsg
610610

611611
if conf.msfPath:
612-
condition = False
612+
found = False
613613

614614
for path in (conf.msfPath, os.path.join(conf.msfPath, 'bin')):
615-
condition = os.path.exists(normalizePath(path))
616-
condition &= os.path.exists(normalizePath(os.path.join(path, "msfcli")))
617-
condition &= os.path.exists(normalizePath(os.path.join(path, "msfconsole")))
618-
condition &= os.path.exists(normalizePath(os.path.join(path, "msfencode")))
619-
condition &= os.path.exists(normalizePath(os.path.join(path, "msfpayload")))
620-
621-
if condition:
615+
if all(os.path.exists(normalizePath(os.path.join(path, _))) for _ in ("", "msfcli", "msfconsole", "msfencode", "msfpayload")):
616+
found = True
622617
conf.msfPath = path
623618
break
624619

625-
if condition:
620+
if found:
626621
debugMsg = "provided Metasploit Framework path "
627622
debugMsg += "'%s' is valid" % conf.msfPath
628623
logger.debug(debugMsg)
@@ -646,22 +641,12 @@ def __setMetasploit():
646641
warnMsg += "installation into the environment paths"
647642
logger.warn(warnMsg)
648643

649-
envPaths = os.environ["PATH"]
650-
651-
if IS_WIN:
652-
envPaths = envPaths.split(";")
653-
else:
654-
envPaths = envPaths.split(":")
644+
envPaths = os.environ.get("PATH", "").split(";" if IS_WIN else ":")
655645

656646
for envPath in envPaths:
657647
envPath = envPath.replace(";", "")
658-
condition = os.path.exists(normalizePath(envPath))
659-
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfcli")))
660-
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfconsole")))
661-
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfencode")))
662-
condition &= os.path.exists(normalizePath(os.path.join(envPath, "msfpayload")))
663648

664-
if condition:
649+
if all(os.path.exists(normalizePath(os.path.join(envPath, _))) for _ in ("", "msfcli", "msfconsole", "msfencode", "msfpayload")):
665650
infoMsg = "Metasploit Framework has been found "
666651
infoMsg += "installed in the '%s' path" % envPath
667652
logger.info(infoMsg)

0 commit comments

Comments
 (0)