forked from p15670423/monkey
Agent, Island: Rename "alive" to "should_stop" in configuration
"Alive" indicates state, when in fact we need a value indicating if stop command was sent to this monkey. Monkey alive state is already tracked elsewhere, in the Monkey document
This commit is contained in:
parent
fae25939b5
commit
520e98032a
|
@ -81,7 +81,7 @@ class Configuration(object):
|
||||||
# monkey config
|
# monkey config
|
||||||
###########################
|
###########################
|
||||||
# sets whether or not the monkey is alive. if false will stop scanning and exploiting
|
# sets whether or not the monkey is alive. if false will stop scanning and exploiting
|
||||||
alive = True
|
should_stop = False
|
||||||
|
|
||||||
# depth of propagation
|
# depth of propagation
|
||||||
depth = 2
|
depth = 2
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
"inaccessible_subnets": [],
|
"inaccessible_subnets": [],
|
||||||
"blocked_ips": [],
|
"blocked_ips": [],
|
||||||
"current_server": "192.0.2.0:5000",
|
"current_server": "192.0.2.0:5000",
|
||||||
"alive": true,
|
"should_stop": false,
|
||||||
"collect_system_info": true,
|
"collect_system_info": true,
|
||||||
"should_use_mimikatz": true,
|
"should_use_mimikatz": true,
|
||||||
"depth": 2,
|
"depth": 2,
|
||||||
|
|
|
@ -8,6 +8,6 @@ class Config(EmbeddedDocument):
|
||||||
See https://mongoengine-odm.readthedocs.io/apireference.html#mongoengine.FieldDoesNotExist
|
See https://mongoengine-odm.readthedocs.io/apireference.html#mongoengine.FieldDoesNotExist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
alive = BooleanField()
|
should_stop = BooleanField()
|
||||||
meta = {"strict": False}
|
meta = {"strict": False}
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -19,11 +19,10 @@ INTERNAL = {
|
||||||
"title": "Monkey",
|
"title": "Monkey",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"alive": {
|
"should_stop": {
|
||||||
"title": "Alive",
|
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": True,
|
"default": False,
|
||||||
"description": "Is the monkey alive",
|
"description": "Was stop command issued for this monkey",
|
||||||
},
|
},
|
||||||
"aws_keys": {
|
"aws_keys": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|
|
@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def set_stop_all(time: float):
|
def set_stop_all(time: float):
|
||||||
for monkey in Monkey.objects():
|
for monkey in Monkey.objects():
|
||||||
monkey.config.alive = False
|
monkey.config.should_stop = True
|
||||||
monkey.save()
|
monkey.save()
|
||||||
agent_controls = AgentControls.objects.first()
|
agent_controls = AgentControls.objects.first()
|
||||||
agent_controls.last_stop_all = time
|
agent_controls.last_stop_all = time
|
||||||
|
@ -25,11 +25,11 @@ def set_stop_all(time: float):
|
||||||
|
|
||||||
def should_agent_die(guid: int) -> bool:
|
def should_agent_die(guid: int) -> bool:
|
||||||
monkey = Monkey.objects(guid=str(guid)).first()
|
monkey = Monkey.objects(guid=str(guid)).first()
|
||||||
return _is_monkey_marked_dead(monkey) or _is_monkey_killed_manually(monkey)
|
return _should_agent_stop(monkey) or _is_monkey_killed_manually(monkey)
|
||||||
|
|
||||||
|
|
||||||
def _is_monkey_marked_dead(monkey: Monkey) -> bool:
|
def _should_agent_stop(monkey: Monkey) -> bool:
|
||||||
return not monkey.config.alive
|
return monkey.config.should_stop
|
||||||
|
|
||||||
|
|
||||||
def _is_monkey_killed_manually(monkey: Monkey) -> bool:
|
def _is_monkey_killed_manually(monkey: Monkey) -> bool:
|
||||||
|
|
|
@ -249,7 +249,7 @@ class NodeService:
|
||||||
|
|
||||||
# Cancel the force kill once monkey died
|
# Cancel the force kill once monkey died
|
||||||
if is_dead:
|
if is_dead:
|
||||||
props_to_set["config.alive"] = True
|
props_to_set["config.should_stop"] = False
|
||||||
|
|
||||||
mongo.db.monkey.update({"guid": monkey["guid"]}, {"$set": props_to_set}, upsert=False)
|
mongo.db.monkey.update({"guid": monkey["guid"]}, {"$set": props_to_set}, upsert=False)
|
||||||
|
|
||||||
|
|
|
@ -10,21 +10,21 @@ from monkey_island.cc.services.infection_lifecycle import should_agent_die
|
||||||
@pytest.mark.usefixtures("uses_database")
|
@pytest.mark.usefixtures("uses_database")
|
||||||
def test_should_agent_die_by_config(monkeypatch):
|
def test_should_agent_die_by_config(monkeypatch):
|
||||||
monkey = Monkey(guid=str(uuid.uuid4()))
|
monkey = Monkey(guid=str(uuid.uuid4()))
|
||||||
monkey.config = Config(alive=False)
|
monkey.config = Config(should_stop=True)
|
||||||
monkey.save()
|
monkey.save()
|
||||||
assert should_agent_die(monkey.guid)
|
assert should_agent_die(monkey.guid)
|
||||||
|
|
||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
"monkey_island.cc.services.infection_lifecycle._is_monkey_killed_manually", lambda _: False
|
"monkey_island.cc.services.infection_lifecycle._is_monkey_killed_manually", lambda _: False
|
||||||
)
|
)
|
||||||
monkey.config.alive = True
|
monkey.config.should_stop = True
|
||||||
monkey.save()
|
monkey.save()
|
||||||
assert not should_agent_die(monkey.guid)
|
assert not should_agent_die(monkey.guid)
|
||||||
|
|
||||||
|
|
||||||
def create_monkey(launch_time):
|
def create_monkey(launch_time):
|
||||||
monkey = Monkey(guid=str(uuid.uuid4()))
|
monkey = Monkey(guid=str(uuid.uuid4()))
|
||||||
monkey.config = Config(alive=True)
|
monkey.config = Config(should_stop=False)
|
||||||
monkey.launch_time = launch_time
|
monkey.launch_time = launch_time
|
||||||
monkey.save()
|
monkey.save()
|
||||||
return monkey
|
return monkey
|
||||||
|
|
Loading…
Reference in New Issue