Skip to content

Using Docker, Monkey Island is unable to read configuration from a previous instance #1032

Closed

Description

@Sodki

Describe the bug

Using Docker, Monkey Island is unable to read configuration from a previous instance.

To Reproduce

Steps to reproduce the behavior:

  1. Follow the instructions to run a Monkey Island instance with Docker: https://www.guardicore.com/infectionmonkey/wt/docker.html
  2. Access Monkey Island web interface
  3. Go to configuration
  4. Change something (or not) and save the new settings
  5. Kill the running container of Monkey Island
  6. Start Monkey Island again
  7. To go the configuration
  8. It will show up empty and there's an error in the logs:
2021-03-12 21:42:27,188 - app.py:1892 - log_exception() - ERROR - Exception on /api/configuration/island [GET]
Traceback (most recent call last):
  File "/monkey/lib/python3.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/monkey/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/monkey/lib/python3.7/site-packages/flask_restful/__init__.py", line 468, in wrapper
    resp = resource(*args, **kwargs)
  File "/monkey/lib/python3.7/site-packages/flask/views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "/monkey/lib/python3.7/site-packages/flask_restful/__init__.py", line 583, in dispatch_request
    resp = meth(*args, **kwargs)
  File "/monkey/monkey_island/cc/resources/auth/auth.py", line 62, in wrapper
    return fn(*args, **kwargs)
  File "/monkey/monkey_island/cc/resources/island_configuration.py", line 14, in get
    configuration=ConfigService.get_config(False, True, True))
  File "/monkey/monkey_island/cc/services/config.py", line 48, in get_config
    ConfigService.decrypt_config(config)
  File "/monkey/monkey_island/cc/services/config.py", line 271, in decrypt_config
    ConfigService._encrypt_or_decrypt_config(config, True)
  File "/monkey/monkey_island/cc/services/config.py", line 313, in _encrypt_or_decrypt_config
    config_arr[i] = encryptor.dec(config_arr[i]) if is_decrypt else encryptor.enc(config_arr[i])
  File "/monkey/monkey_island/cc/encryptor.py", line 50, in dec
    return self._unpad(cipher.decrypt(enc_message[AES.block_size:]).decode())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xee in position 0: invalid continuation byte

Expected behavior

Monkey Island configuration should show up with the previous changes

Machine version (please complete the following information):

  • OS: Linux

Is Monkey Island stateful? Do I need to keep something between sessions?

Thank you

Activity

  1. added
    BugAn error, flaw, misbehavior or failure in the Monkey or Monkey Island.
    on Mar 12, 2021
  2. mssalvatore commented on Mar 23, 2021

    @mssalvatore
    Collaborator

    @Sodki Can you be specific about the exact commands you're using to reproduce the issue?

  3. Sodki commented on Mar 23, 2021

    @Sodki
    Author

    Here's a shorter version of the instructions above:

    1. Run MongoDB: docker run --network=host mongo
    2. On another terminal window, run Monkey Island: docker run --network=host guardicore/monkey-island:1.9.0
    3. Access https://localhost:5000/configure, press the Submit button
    4. Kill the Monkey Island container by pressing Ctrl-C on the terminal running it
    5. Run Monkey Island again: docker run --network=host guardicore/monkey-island:1.9.0
    6. Access https://localhost:5000/configure, it's now broken

    If I had to guess, it seems that Monkey Island is generating a token and uses that to store values on the database. On the second run, it fails because the new token doesn't match what's on the database. This is pure speculation, but fits the symptoms.

  4. mssalvatore commented on Mar 23, 2021

    @mssalvatore
    Collaborator

    @Sodki Your speculation is correct.

    When the monkey container starts, it generates a new secret key for storing sensitive information in mongodb. When you start a new container from the guardicore/monkey-island:1.9.0 image, it generates a new key. Since encrypted data is stored in mongodb with a different key, decryption fails and you get this error.

    Possible short-term solutions for you are:

    1. Run docker container list --all you should see a list that looks something like

      $> docker container list --all
      CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS                       PORTS               NAMES
      5a1809ba1077        guardicore/monkey-island:1.9.0   "bash -c 'source bin…"   2 minutes ago       Exited (137) 3 seconds ago                      silly_wu
      5d56ae1903f3        mongo                            "docker-entrypoint.s…"   3 minutes ago       Up 3 minutes                                     recursing_fermi
      

      You can see that the monkey island container (not image) has been given the name "silly_wu". Yours will have a different name. You can run docker container start -a silly_wu to restart the existing container, which will contain the correct key material.

    2. Restart the mongo container. This will remove the old db entirely.

    Possible longer-term solutions for the project are one or more of:

    1. Give a more useful error when the key can't be used to decrypt the contents of mongodb
    2. Store the key in a persistent, configurable place (docker volume?). See bc14136.
    3. Provide a docker-compose file so that it's easier for users to start/stop the entire Infection Monkey application.
  5. added a commit that references this issue on Jun 7, 2021
    6c04124
  6. mssalvatore commented on Jun 7, 2021

    @mssalvatore
    Collaborator

    A solution for this issue has been added to the documentation in commit 6c04124.

    A new issue, #1211, has been created to improve the error message for the user.

  7. added a commit that references this issue on Jun 9, 2021
    c2282f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAn error, flaw, misbehavior or failure in the Monkey or Monkey Island.Complexity: MediumImpact: Medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions