MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / createMsfShellcode

Method createMsfShellcode

lib/takeover/metasploit.py:583–619  ·  view source on GitHub ↗
(self, exitfunc, format, extra, encode)

Source from the content-addressed store, hash-verified

581 pass
582
583 def createMsfShellcode(self, exitfunc, format, extra, encode):
584 infoMsg = "creating Metasploit Framework multi-stage shellcode "
585 logger.info(infoMsg)
586
587 self._randStr = randomStr(lowercase=True)
588 self._shellcodeFilePath = os.path.join(conf.outputPath, "tmpm%s" % self._randStr)
589
590 Metasploit._initVars(self)
591 self._prepareIngredients(encode=encode)
592 self._forgeMsfPayloadCmd(exitfunc, format, self._shellcodeFilePath, extra)
593
594 logger.debug("executing local command: %s" % self._payloadCmd)
595 process = execute(self._payloadCmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
596
597 dataToStdout("\r[%s] [INFO] creation in progress " % time.strftime("%X"))
598 pollProcess(process)
599 payloadStderr = process.communicate()[1]
600
601 match = re.search(b"(Total size:|Length:|succeeded with size|Final size of exe file:) ([\\d]+)", payloadStderr)
602
603 if match:
604 payloadSize = int(match.group(2))
605
606 if extra == "BufferRegister=EAX":
607 payloadSize = payloadSize // 2
608
609 debugMsg = "the shellcode size is %d bytes" % payloadSize
610 logger.debug(debugMsg)
611 else:
612 errMsg = "failed to create the shellcode ('%s')" % getText(payloadStderr).replace("\n", " ").replace("\r", "")
613 raise SqlmapFilePathException(errMsg)
614
615 self._shellcodeFP = open(self._shellcodeFilePath, "rb")
616 self.shellcodeString = getText(self._shellcodeFP.read())
617 self._shellcodeFP.close()
618
619 os.unlink(self._shellcodeFilePath)
620
621 def uploadShellcodeexec(self, web=False):
622 self.shellcodeexecLocal = os.path.join(paths.SQLMAP_EXTRAS_PATH, "shellcodeexec")

Callers 2

osPwnMethod · 0.80
osBofMethod · 0.80

Calls 14

_prepareIngredientsMethod · 0.95
_forgeMsfPayloadCmdMethod · 0.95
randomStrFunction · 0.90
dataToStdoutFunction · 0.90
pollProcessFunction · 0.90
getTextFunction · 0.90
infoMethod · 0.80
debugMethod · 0.80
_initVarsMethod · 0.45
searchMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected