When sessions connect/disconnect a status message will now be displayed

clients command was renamed to sessions
added an option to kill a session through the sessions command
This commit is contained in:
byt3bl33d3r 2015-09-22 22:09:07 +02:00
parent a994dc651d
commit 2f36d69f78
2 changed files with 37 additions and 9 deletions

View File

@ -357,11 +357,30 @@ class PupyCmd(cmd.Cmd):
""" List available modules with a brief description """ """ List available modules with a brief description """
for m,d in self.pupsrv.list_modules(): for m,d in self.pupsrv.list_modules():
self.stdout.write("{:<20} {}\n".format(m, color(d,'grey'))) self.stdout.write("{:<20} {}\n".format(m, color(d,'grey')))
def do_clients(self, arg): def do_sessions(self, arg):
""" List connected clients """ """ list/interact with established sessions """
client_list=self.pupsrv.get_clients_list() arg_parser = PupyArgumentParser(prog='sessions', description='List/interact with established sessions')
self.display(PupyCmd.table_format([x.desc for x in client_list], wl=["id", "user", "hostname", "platform", "release", "os_arch", "address"])) arg_parser.add_argument('-k', dest='kill', metavar='<id>', type=int, help='Kill the selected session')
#arg_parser.add_argument('-i', dest='interact', metavar='<id>', help='Interact with the supplied session ID')
arg_parser.add_argument('-l', dest='list', action='store_true', help='List all active sessions')
try:
modargs=arg_parser.parse_args(shlex.split(arg))
except PupyModuleExit:
return
if modargs.list or not arg:
client_list=self.pupsrv.get_clients_list()
self.display(PupyCmd.table_format([x.desc for x in client_list], wl=["id", "user", "hostname", "platform", "release", "os_arch", "address"]))
elif modargs.kill:
selected_client = self.pupsrv.get_clients(modargs.kill)
if selected_client:
try:
selected_client[0].conn.exit()
except Exception:
pass
def do_jobs(self, arg): def do_jobs(self, arg):
""" manage jobs """ """ manage jobs """
@ -408,7 +427,7 @@ class PupyCmd(cmd.Cmd):
self.display_error(traceback.format_exc()) self.display_error(traceback.format_exc())
def do_python(self,arg): def do_python(self,arg):
""" start interacting with the server local python interpreter (for debugging purposes). Auto-completion available. """ """ start the local python interpreter (for debugging purposes) """
orig_exit=builtins.exit orig_exit=builtins.exit
orig_quit=builtins.quit orig_quit=builtins.quit
def disabled_exit(*args, **kwargs): def disabled_exit(*args, **kwargs):
@ -504,7 +523,7 @@ class PupyCmd(cmd.Cmd):
error=pj.interactive_wait() error=pj.interactive_wait()
if error and not modjobs: if error and not modjobs:
pj.stop() pj.stop()
except KeyboardInterrupt: except KeyboardInterrupt:
self.display_warning("interrupting job ... (please wait)") self.display_warning("interrupting job ... (please wait)")
pj.interrupt() pj.interrupt()

View File

@ -24,6 +24,8 @@ import modules
import logging import logging
from .PupyErrors import PupyModuleExit, PupyModuleError from .PupyErrors import PupyModuleExit, PupyModuleError
from .PupyJob import PupyJob from .PupyJob import PupyJob
from .PupyCmd import color_real
try: try:
import ConfigParser as configparser import ConfigParser as configparser
except ImportError: except ImportError:
@ -127,12 +129,20 @@ class PupyServer(threading.Thread):
"pid" : l[7], "pid" : l[7],
"address" : conn._conn._config['connid'].split(':')[0], "address" : conn._conn._config['connid'].split(':')[0],
}, self)) }, self))
self.current_id+=1
addr = conn.modules['pupy'].get_connect_back_host()
server_ip, server_port = addr.rsplit(':', 1)
client_ip, client_port = conn._conn._config['connid'].split(':')
print color_real('[*]', 'blue'), "Session {} opened ({}:{} -> {}:{})".format(self.current_id, server_ip, server_port, client_ip, client_port)
self.current_id += 1
def remove_client(self, client): def remove_client(self, client):
with self.clients_lock: with self.clients_lock:
for i,c in enumerate(self.clients): for i,c in enumerate(self.clients):
if c.conn is client: if c.conn is client:
print color_real('[*]', 'blue'), 'Session {} closed'.format(self.clients[i].desc['id'])
del self.clients[i] del self.clients[i]
break break
@ -219,7 +229,6 @@ class PupyServer(threading.Thread):
self.jobs[self.jobs_id]=job self.jobs[self.jobs_id]=job
self.jobs_id+=1 self.jobs_id+=1
def get_job(self, job_id): def get_job(self, job_id):
try: try:
job_id=int(job_id) job_id=int(job_id)