Added a decorator in which the "timer start" for the timeout can be implemented

This commit is contained in:
Shay Nehmad 2019-04-25 14:45:37 +03:00
parent 1a5ebf8dbd
commit 99bc61f9d9
4 changed files with 27 additions and 3 deletions

View File

@ -51,7 +51,6 @@ class MonkeyDrops(object):
LOG.debug("Dropper is running with config:\n%s", pprint.pformat(self._config)) LOG.debug("Dropper is running with config:\n%s", pprint.pformat(self._config))
def start(self): def start(self):
if self._config['destination_path'] is None: if self._config['destination_path'] is None:
LOG.error("No destination path specified") LOG.error("No destination path specified")
return False return False

View File

@ -98,6 +98,7 @@ def main():
except OSError: except OSError:
pass pass
LOG_CONFIG['handlers']['file']['filename'] = log_path LOG_CONFIG['handlers']['file']['filename'] = log_path
# noinspection PyUnresolvedReferences
LOG_CONFIG['root']['handlers'].append('file') LOG_CONFIG['root']['handlers'].append('file')
else: else:
del LOG_CONFIG['handlers']['file'] del LOG_CONFIG['handlers']['file']

View File

@ -2,11 +2,12 @@ import json
from datetime import datetime from datetime import datetime
import dateutil.parser import dateutil.parser
from flask import request
import flask_restful import flask_restful
from flask import request
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.config import ConfigService
from monkey_island.cc.services.monkey_timeout import start_timer_decorator
from monkey_island.cc.services.node import NodeService from monkey_island.cc.services.node import NodeService
__author__ = 'Barak' __author__ = 'Barak'
@ -17,6 +18,7 @@ __author__ = 'Barak'
class Monkey(flask_restful.Resource): class Monkey(flask_restful.Resource):
# Used by monkey. can't secure. # Used by monkey. can't secure.
@start_timer_decorator
def get(self, guid=None, **kw): def get(self, guid=None, **kw):
NodeService.update_dead_monkeys() # refresh monkeys status NodeService.update_dead_monkeys() # refresh monkeys status
if not guid: if not guid:
@ -88,7 +90,7 @@ class Monkey(flask_restful.Resource):
parent_to_add = (exploit_telem[0].get('monkey_guid'), exploit_telem[0].get('data').get('exploiter')) parent_to_add = (exploit_telem[0].get('monkey_guid'), exploit_telem[0].get('data').get('exploiter'))
else: else:
parent_to_add = (parent, None) parent_to_add = (parent, None)
elif (not parent or parent == monkey_json.get('guid')) and 'ip_addresses' in monkey_json: elif (not parent or parent == monkey_json.get('guid')) and 'ip_addresses' in monkey_json:
exploit_telem = [x for x in exploit_telem = [x for x in
mongo.db.telemetry.find({'telem_type': {'$eq': 'exploit'}, 'data.result': {'$eq': True}, mongo.db.telemetry.find({'telem_type': {'$eq': 'exploit'}, 'data.result': {'$eq': True},
'data.machine.ip_addr': {'$in': monkey_json['ip_addresses']}})] 'data.machine.ip_addr': {'$in': monkey_json['ip_addresses']}})]

View File

@ -0,0 +1,22 @@
import functools
import pprint
def start_timer_decorator(func):
@functools.wraps(func)
def wrapper_decorator(*args, **kwargs):
print("ib4get - start the timer, folks. \nargs:")
pprint.pprint(args)
print("kwargs: ")
pprint.pprint(kwargs)
value = func(*args, **kwargs)
print("after party woohoo")
try:
print("Starting timer on " + kwargs['guid'])
except KeyError as e:
print("NO GUID AVAILABLE")
return value
return wrapper_decorator