forked from p15670423/monkey
Island: add "was monkey killed by user" endpoint
Using this endpoint monkey can check if kill command was issues and if it should die
This commit is contained in:
parent
6dfa34a133
commit
31cdd29edb
|
@ -10,9 +10,13 @@ from monkey_island.cc.services.infection_lifecycle import set_stop_all
|
||||||
class StopAllAgents(flask_restful.Resource):
|
class StopAllAgents(flask_restful.Resource):
|
||||||
@jwt_required
|
@jwt_required
|
||||||
def post(self):
|
def post(self):
|
||||||
|
with AGENT_KILLING_SEMAPHORE:
|
||||||
data = json.loads(request.data)
|
data = json.loads(request.data)
|
||||||
if data["kill_time"]:
|
if data["kill_time"]:
|
||||||
set_stop_all(data["kill_time"])
|
set_stop_all(data["kill_time"])
|
||||||
return make_response({}, 200)
|
return make_response({}, 200)
|
||||||
else:
|
else:
|
||||||
return make_response({}, 400)
|
return make_response({}, 400)
|
||||||
|
|
||||||
|
def get(self, monkey_guid):
|
||||||
|
return {"stop_agent": was_monkey_killed(monkey_guid)}
|
||||||
|
|
|
@ -23,16 +23,8 @@ def set_stop_all(time: float):
|
||||||
agent_controls.save()
|
agent_controls.save()
|
||||||
|
|
||||||
|
|
||||||
def should_agent_die(guid: int) -> bool:
|
def was_monkey_killed(guid: int) -> bool:
|
||||||
monkey = Monkey.objects(guid=str(guid)).first()
|
monkey = Monkey.objects(guid=guid).first()
|
||||||
return _is_monkey_marked_dead(monkey) or _is_monkey_killed_manually(monkey)
|
|
||||||
|
|
||||||
|
|
||||||
def _is_monkey_marked_dead(monkey: Monkey) -> bool:
|
|
||||||
return monkey.config.alive
|
|
||||||
|
|
||||||
|
|
||||||
def _is_monkey_killed_manually(monkey: Monkey) -> bool:
|
|
||||||
if monkey.has_parent():
|
if monkey.has_parent():
|
||||||
launch_timestamp = monkey.get_parent().launch_time
|
launch_timestamp = monkey.get_parent().launch_time
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue