From 1ee53972a8dfa70410d5537f2405a271ac1eef18 Mon Sep 17 00:00:00 2001 From: Oran Nadler Date: Wed, 7 Mar 2018 06:47:29 -0800 Subject: [PATCH] small fixeS --- monkey_island/cc/resources/pthmap.py | 52 ++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/monkey_island/cc/resources/pthmap.py b/monkey_island/cc/resources/pthmap.py index 3ad75d366..65a3c86a5 100644 --- a/monkey_island/cc/resources/pthmap.py +++ b/monkey_island/cc/resources/pthmap.py @@ -408,13 +408,7 @@ class PassTheHashMap(object): return None def GetVictimCountBySid(self, sid): - count = 0 - - for m in self.machines: - if sid in m.GetLocalAdmins(): - count += 1 - - return count + return len(self.GetVictimsBySid(sid)) def GetVictimCountByMachine(self, attacker): return len(self.GetVictimsByAttacker(attacker)) @@ -538,6 +532,32 @@ class PassTheHashMap(object): victims.add(vic) return victims + + def GetInPathCountByVictim(self, victim, already_processed=None): + if type(victim) != unicode: + victim = victim.monkey_guid + + if not already_processed: + already_processed = set([victim]) + + count = 0 + + for atck, vic, _ in self.edges: + if atck == vic: + continue + + if vic != victim: + continue + + if atck in already_processed: + continue + + count += 1 + + already_processed.add(atck) + count += self.GetInPathCountByVictim(atck, already_processed) + + return count def main(): pth = PassTheHashMap() @@ -586,12 +606,22 @@ def main(): print "

Domain Controllers

" print "

List of domain controllers (we count them as critical points, so they are listed here)

" - DCs = pth.GetAllDomainControllers() + DCs = dict(map(lambda m: (m, pth.GetInPathCountByVictim(m)), pth.GetAllDomainControllers())) print """""" - print """""" - for m in DCs: - print """""".format(ip=m.GetIp(), hostname=m.GetHostName(), domain=m.GetDomainName()) + print """""" + for m, path_count in sorted(DCs.iteritems(), key=lambda (k,v): (v,k), reverse=True): + print """""".format(ip=m.GetIp(), hostname=m.GetHostName(), domain=m.GetDomainName(), path_count=path_count) + print """
DC IpDC HostnameDomain Name
{ip}{hostname}{domain}
DC IpDC HostnameDomain NameIn-Path Count
{ip}{hostname}{domain}{path_count}
""" + + print "

Most Vulnerable Machines

" + print "

List all machines in the network sorted by the potincial to attack them

" + all_machines = dict(map(lambda m: (m, pth.GetInPathCountByVictim(m)), pth.machines)) + + print """""" + print """""" + for m, path_count in sorted(all_machines.iteritems(), key=lambda (k,v): (v,k), reverse=True): + print """""".format(ip=m.GetIp(), hostname=m.GetHostName(), domain=m.GetDomainName(), path_count=path_count) print """
IpHostnameDomain NameIn-Path Count
{ip}{hostname}{domain}{path_count}
""" print "
"