Add known credentials to monkey documents

This commit is contained in:
Itay Mizeretz 2017-11-07 14:52:13 +02:00
parent e9b6b39a21
commit 8d9068fe40
3 changed files with 29 additions and 0 deletions

View File

@ -53,6 +53,7 @@ class Monkey(flask_restful.Resource):
def post(self, **kw): def post(self, **kw):
monkey_json = json.loads(request.data) monkey_json = json.loads(request.data)
monkey_json['creds'] = {}
if 'keepalive' in monkey_json: if 'keepalive' in monkey_json:
monkey_json['keepalive'] = dateutil.parser.parse(monkey_json['keepalive']) monkey_json['keepalive'] = dateutil.parser.parse(monkey_json['keepalive'])
else: else:
@ -119,6 +120,8 @@ class Monkey(flask_restful.Resource):
node_id = existing_node["_id"] node_id = existing_node["_id"]
for edge in mongo.db.edge.find({"to": node_id}): for edge in mongo.db.edge.find({"to": node_id}):
mongo.db.edge.update({"_id": edge["_id"]}, {"$set": {"to": new_monkey_id}}) mongo.db.edge.update({"_id": edge["_id"]}, {"$set": {"to": new_monkey_id}})
for user in existing_node['creds']:
NodeService.add_credentials_to_monkey(new_monkey_id, user, existing_node['creds'][user])
mongo.db.node.remove({"_id": node_id}) mongo.db.node.remove({"_id": node_id})
return {"id": new_monkey_id} return {"id": new_monkey_id}

View File

@ -115,6 +115,15 @@ class Telemetry(flask_restful.Resource):
if new_exploit['result']: if new_exploit['result']:
EdgeService.set_edge_exploited(edge) EdgeService.set_edge_exploited(edge)
for attempt in telemetry_json['data']['attempts']:
if attempt['result']:
attempt.pop('result')
user = attempt.pop('user')
for field in ['password', 'lm_hash', 'ntlm_hash']:
if len(attempt[field]) == 0:
attempt.pop(field)
NodeService.add_credentials_to_node(edge['to'], user, attempt)
@staticmethod @staticmethod
def process_scan_telemetry(telemetry_json): def process_scan_telemetry(telemetry_json):
edge = Telemetry.get_edge_by_scan_or_exploit_telemetry(telemetry_json) edge = Telemetry.get_edge_by_scan_or_exploit_telemetry(telemetry_json)
@ -151,6 +160,8 @@ class Telemetry(flask_restful.Resource):
creds = telemetry_json['data']['credentials'] creds = telemetry_json['data']['credentials']
for user in creds: for user in creds:
ConfigService.creds_add_username(user) ConfigService.creds_add_username(user)
NodeService.add_credentials_to_monkey(
NodeService.get_monkey_by_guid(telemetry_json['monkey_guid'])['_id'], user, creds[user])
if 'password' in creds[user]: if 'password' in creds[user]:
ConfigService.creds_add_password(creds[user]['password']) ConfigService.creds_add_password(creds[user]['password'])
if 'lm_hash' in creds[user]: if 'lm_hash' in creds[user]:

View File

@ -170,6 +170,7 @@ class NodeService:
{ {
"ip_addresses": [ip_address], "ip_addresses": [ip_address],
"exploited": False, "exploited": False,
"creds": {},
"os": "os":
{ {
"type": "unknown", "type": "unknown",
@ -277,3 +278,17 @@ class NodeService:
@staticmethod @staticmethod
def is_any_monkey_exists(): def is_any_monkey_exists():
return mongo.db.monkey.find_one({}) is not None return mongo.db.monkey.find_one({}) is not None
@staticmethod
def add_credentials_to_monkey(monkey_id, user, creds):
mongo.db.monkey.update(
{'_id': monkey_id},
{'$set': {'creds.' + user: creds}}
)
@staticmethod
def add_credentials_to_node(node_id, user, creds):
mongo.db.node.update(
{'_id': node_id},
{'$set': {'creds.' + user: creds}}
)