guardicore / monkey

Infection Monkey - An open-source adversary emulation platform
https://www.guardicore.com/infectionmonkey/
GNU General Public License v3.0
6.67k stars 785 forks source link

AWS remote run crashes if monkey is already running #1614

Closed VakarisZ closed 1 year ago

VakarisZ commented 2 years ago

Describe the bug

To Reproduce

Steps to reproduce the behavior:

  1. Run monkey on remote AWS machine
  2. Run monkey there again, when it's already running
  3. Get white screen, island output:
    2021-11-16 15:18:16,382 - app.py:1455 - log_exception() - ERROR - Exception on /api/remote-monkey [POST]
    Traceback (most recent call last):
    File "/tmp/.mount_Infectn0XuRq/opt/python3.7/lib/python3.7/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
    File "/tmp/.mount_Infectn0XuRq/opt/python3.7/lib/python3.7/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
    File "/tmp/.mount_Infectn0XuRq/opt/python3.7/lib/python3.7/site-packages/flask_restful/__init__.py", line 467, in wrapper
    resp = resource(*args, **kwargs)
    File "/tmp/.mount_Infectn0XuRq/opt/python3.7/lib/python3.7/site-packages/flask/views.py", line 83, in view
    return self.dispatch_request(*args, **kwargs)
    File "/tmp/.mount_Infectn0XuRq/opt/python3.7/lib/python3.7/site-packages/flask_restful/__init__.py", line 582, in dispatch_request
    resp = meth(*args, **kwargs)
    File "/tmp/.mount_Infectn0XuRq/usr/src/monkey_island/cc/resources/auth/auth.py", line 63, in wrapper
    return fn(*args, **kwargs)
    File "/tmp/.mount_Infectn0XuRq/usr/src/monkey_island/cc/resources/remote_run.py", line 56, in post
    result = self.run_aws_monkeys(body)
    File "/tmp/.mount_Infectn0XuRq/usr/src/monkey_island/cc/resources/remote_run.py", line 29, in run_aws_monkeys
    return RemoteRunAwsService.run_aws_monkeys(instances, island_ip)
    File "/tmp/.mount_Infectn0XuRq/usr/src/monkey_island/cc/services/remote_run_aws.py", line 53, in run_aws_monkeys
    lambda _, result: result.is_success,
    File "/tmp/.mount_Infectn0XuRq/usr/src/common/cmd/cmd_runner.py", line 54, in run_multiple_commands
    command_result_pairs = CmdRunner.wait_commands(list(command_instance_dict.keys()))
    File "/tmp/.mount_Infectn0XuRq/usr/src/common/cmd/cmd_runner.py", line 99, in wait_commands
    str(command[1]),
    TypeError: 'Cmd' object is not subscriptable
    2021-11-16 15:18:16,384 - pywsgi.py:1226 -      write() - INFO - 88.222.20.171 - - [2021-11-16 15:18:16] "POST /api/remote-monkey HTTP/1.1" 500 163 6.524820

Expected behavior

Get the same pop-up as you would get on the "run on island" option.

Screenshots

If applicable, add screenshots to help explain your problem.

Machine version (please complete the following information):

Tasks

ilija-lazoroski commented 1 year ago

This issue is outdated. We have changed the way we run agents on AWS instances. I have run an agent and I got that the singleton is locked which means that an agent is already running.

The running of agents is done on different threads so the issue above is fixed. Check this code on who we do it.

Agent log while another agent is running: 2022-11-24T16.55.38.800Z-ip-172-31-24-149.log

image image
ilija-lazoroski commented 1 year ago

Resolved in https://github.com/guardicore/monkey/issues/1928.