Skip to content

Commit

Permalink
Patch for an Issue #1280
Browse files Browse the repository at this point in the history
  • Loading branch information
stamparm committed Jun 29, 2015
1 parent 8b63ee9 commit 7b95a2d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
31 changes: 23 additions & 8 deletions lib/core/option.py
Expand Up @@ -766,8 +766,14 @@ def _(key, value):

if conf.msfPath:
for path in (conf.msfPath, os.path.join(conf.msfPath, "bin")):
if all(os.path.exists(normalizePath(os.path.join(path, _))) for _ in ("", "msfcli", "msfconsole", "msfencode", "msfpayload")):
if all(os.path.exists(normalizePath(os.path.join(path, _))) for _ in ("", "msfcli", "msfconsole")):
msfEnvPathExists = True
if all(os.path.exists(normalizePath(os.path.join(path, _))) for _ in ("msfvenom",)):
kb.msfVenom = True
elif all(os.path.exists(normalizePath(os.path.join(path, _))) for _ in ("msfencode", "msfpayload")):
kb.msfVenom = False
else:
msfEnvPathExists = False
conf.msfPath = path
break

Expand Down Expand Up @@ -798,15 +804,23 @@ def _(key, value):
for envPath in envPaths:
envPath = envPath.replace(";", "")

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

if all(os.path.exists(normalizePath(os.path.join(envPath, _))) for _ in ("", "msfcli", "msfconsole")):
msfEnvPathExists = True
conf.msfPath = envPath
if all(os.path.exists(normalizePath(os.path.join(envPath, _))) for _ in ("msfvenom",)):
kb.msfVenom = True
elif all(os.path.exists(normalizePath(os.path.join(envPath, _))) for _ in ("msfencode", "msfpayload")):
kb.msfVenom = False
else:
msfEnvPathExists = False

break
if msfEnvPathExists:
infoMsg = "Metasploit Framework has been found "
infoMsg += "installed in the '%s' path" % envPath
logger.info(infoMsg)

conf.msfPath = envPath

break

if not msfEnvPathExists:
errMsg = "unable to locate Metasploit Framework installation. "
Expand Down Expand Up @@ -1794,6 +1808,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
kb.matchRatio = None
kb.maxConnectionsFlag = False
kb.mergeCookies = None
kb.msfVenom = False
kb.multiThreadMode = False
kb.negativeLogic = False
kb.nullConnection = None
Expand Down
28 changes: 22 additions & 6 deletions lib/takeover/metasploit.py
Expand Up @@ -24,6 +24,7 @@
from lib.core.common import randomStr
from lib.core.common import readInput
from lib.core.data import conf
from lib.core.data import kb
from lib.core.data import logger
from lib.core.data import paths
from lib.core.enums import DBMS
Expand Down Expand Up @@ -63,6 +64,7 @@ def _initVars(self):
self._msfCli = normalizePath(os.path.join(conf.msfPath, "msfcli"))
self._msfEncode = normalizePath(os.path.join(conf.msfPath, "msfencode"))
self._msfPayload = normalizePath(os.path.join(conf.msfPath, "msfpayload"))
self._msfVenom = normalizePath(os.path.join(conf.msfPath, "msfvenom"))

if IS_WIN:
_ = conf.msfPath
Expand All @@ -78,6 +80,7 @@ def _initVars(self):
self._msfCli = "%s & ruby %s" % (_, self._msfCli)
self._msfEncode = "ruby %s" % self._msfEncode
self._msfPayload = "%s & ruby %s" % (_, self._msfPayload)
self._msfVenom = "%s & ruby %s" % (_, self._msfVenom)

self._msfPayloadsList = {
"windows": {
Expand Down Expand Up @@ -361,7 +364,11 @@ def _forgeMsfCliCmdForSmbrelay(self):
self._cliCmd += " E"

def _forgeMsfPayloadCmd(self, exitfunc, format, outFile, extra=None):
self._payloadCmd = "%s %s" % (self._msfPayload, self.payloadConnStr)
if kb.msfVenom:
self._payloadCmd = "%s -p" % self._msfVenom
else:
self._payloadCmd = self._msfPayload
self._payloadCmd += " %s" % self.payloadConnStr
self._payloadCmd += " EXITFUNC=%s" % exitfunc
self._payloadCmd += " LPORT=%s" % self.portStr

Expand All @@ -373,13 +380,22 @@ def _forgeMsfPayloadCmd(self, exitfunc, format, outFile, extra=None):
if Backend.isOs(OS.LINUX) and conf.privEsc:
self._payloadCmd += " PrependChrootBreak=true PrependSetuid=true"

if extra == "BufferRegister=EAX":
self._payloadCmd += " R | %s -a x86 -e %s -o \"%s\" -t %s" % (self._msfEncode, self.encoderStr, outFile, format)
if kb.msfVenom:
if extra == "BufferRegister=EAX":
self._payloadCmd += " -a x86 -e %s -f %s > \"%s\"" % (self.encoderStr, format, outFile)

if extra is not None:
self._payloadCmd += " %s" % extra
if extra is not None:
self._payloadCmd += " %s" % extra
else:
self._payloadCmd += " -f exe > \"%s\"" % outFile
else:
self._payloadCmd += " X > \"%s\"" % outFile
if extra == "BufferRegister=EAX":
self._payloadCmd += " R | %s -a x86 -e %s -o \"%s\" -t %s" % (self._msfEncode, self.encoderStr, outFile, format)

if extra is not None:
self._payloadCmd += " %s" % extra
else:
self._payloadCmd += " X > \"%s\"" % outFile

def _runMsfCliSmbrelay(self):
self._forgeMsfCliCmdForSmbrelay()
Expand Down

0 comments on commit 7b95a2d

Please sign in to comment.