diff --git a/src/metasploit/msfconsole.py b/src/metasploit/msfconsole.py index b8e7294..33544f7 100644 --- a/src/metasploit/msfconsole.py +++ b/src/metasploit/msfconsole.py @@ -1,7 +1,7 @@ #!/usr/bin/env python from threading import Timer, Lock -from msfrpc import ShellSession +from .msfrpc import ShellSession __author__ = 'Nadeem Douba' __copyright__ = 'Copyright 2012, PyMetasploit Project' @@ -66,13 +66,13 @@ def _poller(self): if self.callback is not None: self.callback(d) else: - print d['data'] + print(d['data']) else: if d: if self.callback is not None: self.callback(dict(data=d, prompt=self.prompt)) else: - print d + print(d) Timer(0.5, self._poller).start() def execute(self, command): diff --git a/src/metasploit/msfrpc.py b/src/metasploit/msfrpc.py index c005b5e..ba10f31 100644 --- a/src/metasploit/msfrpc.py +++ b/src/metasploit/msfrpc.py @@ -1328,8 +1328,10 @@ def __init__(self, rpc, mtype, mname): self.modulename = mname self.rpc = rpc self._info = rpc.call(MsfRpcMethod.ModuleInfo, mtype, mname) + property_attributes = ["advanced", "evasion", "options", "required", "runoptions"] for k in self._info: - setattr(self, k, self._info.get(k)) + if k not in propery_attributes): + setattr(self, k, self._info.get(k)) self._moptions = rpc.call(MsfRpcMethod.ModuleOptions, mtype, mname) self._roptions = [] self._aoptions = [] @@ -1944,7 +1946,7 @@ def list(self): """ A list of active consoles. """ - return self.rpc.call(MsfRpcMethod.ConsoleList) + return self.rpc.call(MsfRpcMethod.ConsoleList)['consoles'] def console(self, cid=None): """ @@ -1953,7 +1955,7 @@ def console(self, cid=None): Optional Keyword Arguments: - cid : the console identifier. """ - s = self.list + s = [x['id'] for x in self.list['consoles']] if cid is None: return MsfConsole(self.rpc) if cid not in s: diff --git a/src/metasploit/msfrpcdHandler.py b/src/metasploit/msfrpcdHandler.py new file mode 100644 index 0000000..015dadf --- /dev/null +++ b/src/metasploit/msfrpcdHandler.py @@ -0,0 +1,28 @@ +# Handles the MetaSploit Framework Remote Procedure Call Daemon (MSFRPCD) for *nix machines + +import os, psutil, signal, time + +def msfrpcdStart(password): + if checkMsfrpcdRunning(): return "MetaSploit Framework Remote Procedure Call Daemon is already running." + else: + response = os.system("msfrpcd -P "+password+" -n -a 127.0.0.1") + time.sleep(10) + if checkMsfrpcdRunning(): return "MetaSploit Framework Remote Procedure Call Daemon running." + else: return "There was an issue: MetaSploit Framework Remote Procedure Call Daemon did not start." + +def checkMsfrpcdRunning(): + for socket in psutil.net_connections(): + if socket.laddr[1] == 55553: return socket.pid + +def msfrpcdRestart(password): + pid = checkMsfrpcdRunning() + if pid: + os.kill(socket.pid, signal.SIGKILL) + print "Old MSFRPCD process killed." + response = os.system("msfrpcd -P "+password+" -n -a 127.0.0.1") + time.sleep(10) + if checkMsfrpcdRunning(): return "MetaSploit Framework Remote Procedure Call Daemon running." + else: return "There was an issue: MetaSploit Framework Remote Procedure Call Daemon did not start." + +if __name__ == "__main__": + print msfrpcdStart('pass123') diff --git a/src/metasploit/utils.py b/src/metasploit/utils.py index d7cffa5..570b6cb 100644 --- a/src/metasploit/utils.py +++ b/src/metasploit/utils.py @@ -26,7 +26,7 @@ def parseargs(): p.add_option("-p", dest="port", help="Connect to the specified port instead of 55553", metavar="opt", default=55553) o, a = p.parse_args() if o.password is None: - print '[-] Error: a password must be specified (-P)\n' + print('[-] Error: a password must be specified (-P)\n') p.print_help() exit(-1) return o \ No newline at end of file diff --git a/src/scripts/pymsfconsole b/src/scripts/pymsfconsole index 0ae0c2a..8822f72 100755 --- a/src/scripts/pymsfconsole +++ b/src/scripts/pymsfconsole @@ -50,12 +50,11 @@ class MsfConsole(InteractiveConsole): def callback(self, d): stdout.write('\n%s' % d['data']) if not self.fl: - stdout.write('\n%s' % d['prompt']) + stdout.write('\n%s' % d['prompt'].replace("\x01\x02", "")) stdout.flush() else: self.fl = False - if __name__ == '__main__': o = parseargs() try: