fix bug not running the edge generation functions due to caching

This commit is contained in:
Oran Nadler 2018-05-15 16:29:02 +03:00
parent 0fe5a20a6b
commit f6ebf0b51c
2 changed files with 36 additions and 14 deletions

View File

@ -2,7 +2,7 @@ import hashlib
import binascii import binascii
import copy import copy
import flask_restful import flask_restful
from pthreport import PassTheHashReport from pthreport import PassTheHashReport, Machine
from cc.auth import jwt_required from cc.auth import jwt_required
from cc.services.edge import EdgeService from cc.services.edge import EdgeService
@ -12,10 +12,13 @@ from cc.database import mongo
class PthMap(flask_restful.Resource): class PthMap(flask_restful.Resource):
@jwt_required() @jwt_required()
def get(self, **kw): def get(self, **kw):
graph = PassTheHashReport() pth = PassTheHashReport()
v = copy.deepcopy(pth.vertices)
e = copy.deepcopy(pth.edges)
return \ return \
{ {
"nodes": [{"id": x, "label": Machine(x).GetIp()} for x in graph.vertices], "nodes": [{"id": x, "label": Machine(x).GetIp()} for x in v],
"edges": [{"id": str(s) + str(t), "from": s, "to": t, "label": label} for s, t, label in graph.edges] "edges": [{"id": str(s) + str(t), "from": s, "to": t, "label": label} for s, t, label in e]
} }

View File

@ -542,14 +542,21 @@ class Machine(object):
return names return names
class PassTheHashReport(object): class PassTheHashReport(object):
#_instance = None
#def __new__(class_, *args, **kwargs):
# if not class_._instance:
# class_._instance = object.__new__(class_, *args, **kwargs)
#
# return class_._instance
def __init__(self): def __init__(self):
self.vertices = self.GetAllMachines() self.vertices = self.GetAllMachines()
self.edges = set()
self.machines = map(Machine, self.vertices) self.machines = map(Machine, self.vertices)
self.GenerateEdgesBySid() # Useful for non-cached domain users self.edges = set()
self.GenerateEdgesBySamHash() # This will add edges based only on password hash without caring about username self.edges |= self.GetEdgesBySid() # Useful for non-cached domain users
self.edges |= self.GetEdgesBySamHash() # This will add edges based only on password hash without caring about username
@cache @cache
def GetAllMachines(self): def GetAllMachines(self):
@ -587,7 +594,9 @@ class PassTheHashReport(object):
return ",\n".join(label) return ",\n".join(label)
@cache @cache
def GenerateEdgesBySid(self): def GetEdgesBySid(self):
edges = set()
for attacker in self.vertices: for attacker in self.vertices:
cached = self.GetCachedSids(Machine(attacker)) cached = self.GetCachedSids(Machine(attacker))
@ -599,10 +608,14 @@ class PassTheHashReport(object):
if len(cached & admins) > 0: if len(cached & admins) > 0:
label = self.ReprSidList(cached & admins, attacker, victim) label = self.ReprSidList(cached & admins, attacker, victim)
self.edges.add((attacker, victim, label)) edges.add((attacker, victim, label))
return edges
@cache @cache
def GenerateEdgesBySamHash(self): def GetEdgesBySamHash(self):
edges = set()
for attacker in self.vertices: for attacker in self.vertices:
cached_creds = set(Machine(attacker).GetCachedCreds().items()) cached_creds = set(Machine(attacker).GetCachedCreds().items())
@ -614,10 +627,14 @@ class PassTheHashReport(object):
if len(cached_creds & admin_creds) > 0: if len(cached_creds & admin_creds) > 0:
label = self.ReprSecretList(set(dict(cached_creds & admin_creds).values()), victim) label = self.ReprSecretList(set(dict(cached_creds & admin_creds).values()), victim)
self.edges.add((attacker, victim, label)) edges.add((attacker, victim, label))
return edges
@cache @cache
def GenerateEdgesByUsername(self): def GetEdgesByUsername(self):
edges = set()
for attacker in self.vertices: for attacker in self.vertices:
cached = Machine(attacker).GetCachedUsernames() cached = Machine(attacker).GetCachedUsernames()
@ -628,7 +645,9 @@ class PassTheHashReport(object):
admins = Machine(victim).GetAdminNames() admins = Machine(victim).GetAdminNames()
if len(cached & admins) > 0: if len(cached & admins) > 0:
self.edges.add((attacker, victim)) edges.add((attacker, victim))
return edges
@cache @cache
def Print(self): def Print(self):