forked from p34709852/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
|
||||
###########################
|
||||
# sets whether or not the monkey is alive. if false will stop scanning and exploiting
|
||||
alive = True
|
||||
should_stop = False
|
||||
|
||||
# depth of propagation
|
||||
depth = 2
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"inaccessible_subnets": [],
|
||||
"blocked_ips": [],
|
||||
"current_server": "192.0.2.0:5000",
|
||||
"alive": true,
|
||||
"should_stop": false,
|
||||
"collect_system_info": true,
|
||||
"should_use_mimikatz": true,
|
||||
"depth": 2,
|
||||
|
|
|
@ -8,6 +8,6 @@ class Config(EmbeddedDocument):
|
|||
See https://mongoengine-odm.readthedocs.io/apireference.html#mongoengine.FieldDoesNotExist
|
||||
"""
|
||||
|
||||
alive = BooleanField()
|
||||
should_stop = BooleanField()
|
||||
meta = {"strict": False}
|
||||
pass
|
||||
|
|
|
@ -19,11 +19,10 @@ INTERNAL = {
|
|||
"title": "Monkey",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"alive": {
|
||||
"title": "Alive",
|
||||
"should_stop": {
|
||||
"type": "boolean",
|
||||
"default": True,
|
||||
"description": "Is the monkey alive",
|
||||
"default": False,
|
||||
"description": "Was stop command issued for this monkey",
|
||||
},
|
||||
"aws_keys": {
|
||||
"type": "object",
|
||||
|
|
|
@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
def set_stop_all(time: float):
|
||||
for monkey in Monkey.objects():
|
||||
monkey.config.alive = False
|
||||
monkey.config.should_stop = True
|
||||
monkey.save()
|
||||
agent_controls = AgentControls.objects.first()
|
||||
agent_controls.last_stop_all = time
|
||||
|
@ -25,11 +25,11 @@ def set_stop_all(time: float):
|
|||
|
||||
def should_agent_die(guid: int) -> bool:
|
||||
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:
|
||||
return not monkey.config.alive
|
||||
def _should_agent_stop(monkey: Monkey) -> bool:
|
||||
return monkey.config.should_stop
|
||||
|
||||
|
||||
def _is_monkey_killed_manually(monkey: Monkey) -> bool:
|
||||
|
|
|
@ -249,7 +249,7 @@ class NodeService:
|
|||
|
||||
# Cancel the force kill once monkey died
|
||||
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)
|
||||
|
||||
|
|
|
@ -10,21 +10,21 @@ from monkey_island.cc.services.infection_lifecycle import should_agent_die
|
|||
@pytest.mark.usefixtures("uses_database")
|
||||
def test_should_agent_die_by_config(monkeypatch):
|
||||
monkey = Monkey(guid=str(uuid.uuid4()))
|
||||
monkey.config = Config(alive=False)
|
||||
monkey.config = Config(should_stop=True)
|
||||
monkey.save()
|
||||
assert should_agent_die(monkey.guid)
|
||||
|
||||
monkeypatch.setattr(
|
||||
"monkey_island.cc.services.infection_lifecycle._is_monkey_killed_manually", lambda _: False
|
||||
)
|
||||
monkey.config.alive = True
|
||||
monkey.config.should_stop = True
|
||||
monkey.save()
|
||||
assert not should_agent_die(monkey.guid)
|
||||
|
||||
|
||||
def create_monkey(launch_time):
|
||||
monkey = Monkey(guid=str(uuid.uuid4()))
|
||||
monkey.config = Config(alive=True)
|
||||
monkey.config = Config(should_stop=False)
|
||||
monkey.launch_time = launch_time
|
||||
monkey.save()
|
||||
return monkey
|
||||
|
|
Loading…
Reference in New Issue