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 """DC Ip | DC Hostname | Domain Name |
"""
- for m in DCs:
- print """{ip} | {hostname} | {domain} | """.format(ip=m.GetIp(), hostname=m.GetHostName(), domain=m.GetDomainName())
+ print """
DC Ip | DC Hostname | Domain Name | In-Path Count |
"""
+ for m, path_count in sorted(DCs.iteritems(), key=lambda (k,v): (v,k), reverse=True):
+ print """{ip} | {hostname} | {domain} | {path_count} |
""".format(ip=m.GetIp(), hostname=m.GetHostName(), domain=m.GetDomainName(), path_count=path_count)
+ print """
"""
+
+ 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 """Ip | Hostname | Domain Name | In-Path Count |
"""
+ for m, path_count in sorted(all_machines.iteritems(), key=lambda (k,v): (v,k), reverse=True):
+ print """{ip} | {hostname} | {domain} | {path_count} |
""".format(ip=m.GetIp(), hostname=m.GetHostName(), domain=m.GetDomainName(), path_count=path_count)
print """
"""
print "
"