Agent display improvements

master
chris 2018-05-16 17:47:36 -04:00
parent f674b2b64a
commit c7a3eb6b25
2 changed files with 54 additions and 4 deletions

View File

@ -52,11 +52,24 @@ import threading
import pickle
import netifaces
import random
from datetime import datetime
import subprocess
import fnmatch
import urllib, urllib2
import hashlib
import datetime
import uuid
import ipaddress
from datetime import datetime
###############################################################
#
# Global Variables
#
################################################################
globentropy=random.randint(1,datetime.today().day)
globDebug=False
###############################################################
#
# Validation methods
@ -143,6 +156,13 @@ def random_string(length=-1, charset=string.ascii_letters):
return random_string
def generate_random_script_var_name(origvariname,globDebug=False):
if globDebug:
return origvariname
else:
hash_object=hashlib.sha1(str(origvariname)+str(globentropy)).hexdigest()
return hash_object[:-datetime.today().day]
def randomize_capitalization(data):
"""
Randomize the capitalization of a string.
@ -679,6 +699,8 @@ def color(string, color=None):
attr.append('31')
elif color.lower() == "green":
attr.append('32')
elif color.lower() == "yellow":
attr.append('33')
elif color.lower() == "blue":
attr.append('34')
return '\x1b[%sm%s\x1b[0m' % (';'.join(attr), string)
@ -696,6 +718,20 @@ def color(string, color=None):
else:
return string
def lastseen(stamp, delay, jitter):
"""
Colorize the Last Seen field based on measured delays
"""
try:
delta = datetime.now() - datetime.strptime(stamp, "%Y-%m-%d %H:%M:%S")
if delta.seconds > delay * (jitter + 1) * 5:
return color(stamp, "red")
elif delta.seconds > delay * (jitter + 1):
return color(stamp, "yellow")
else:
return color(stamp, "green")
except Exception:
return stamp
def unique(seq, idfun=None):
"""

View File

@ -171,12 +171,14 @@ def display_agents(agents):
Take a dictionary of agents and build the display for the main menu.
"""
rowToggle = 0
if len(agents) > 0:
print ''
print helpers.color("[*] Active agents:\n")
print " Name Lang Internal IP Machine Name Username Process Delay Last Seen"
print " --------- ---- ----------- ------------ --------- ------- ----- --------------------"
print " Name La Internal IP Machine Name Username Process PID Delay Last Seen"
print " ---- -- ----------- ------------ -------- ------- --- ----- ---------"
for agent in agents:
@ -192,8 +194,20 @@ def display_agents(agents):
else:
agent['language'] = 'X'
print " %.16s%.6s%.16s%.16s%.20s%.20s%.9s%.20s" % ('{0: <16}'.format(agent['name']), '{0: <6}'.format(agent['language']), '{0: <16}'.format(agent['internal_ip']), '{0: <16}'.format(agent['hostname']), '{0: <20}'.format(agent['username']), '{0: <20}'.format(str(agent['process_name']) + "/" + str(agent['process_id'])), '{0: <9}'.format(str(agent['delay']) + "/" +str(agent['jitter'])), agent['lastseen_time'])
print " %.8s %.2s %.15s %.17s %.23s %.18s %.6s %.8s %.30s" % ('{0: <8}'.format(agent['name']),
'{0: <2}'.format(agent['language']),
'{0: <15}'.format(str(agent['internal_ip']).split(" ")[0]),
'{0: <17}'.format(agent['hostname']),
'{0: <23}'.format(agent['username']),
'{0: <18}'.format(agent['process_name']),
'{0: <6}'.format(str(agent['process_id'])),
'{0: <8}'.format(str(agent['delay']) + "/" +str(agent['jitter'])),
str(helpers.lastseen(agent['lastseen_time'], agent['delay'], agent['jitter'])))
# Skip rows for better readability
rowToggle = (rowToggle + 1) % 3
if rowToggle == 0:
print
print ''
else:
print helpers.color('[!] No agents currently registered')