Repository navigation
Closed
Labels
BugAn error, flaw, misbehavior or failure in the Monkey or Monkey Island.An error, flaw, misbehavior or failure in the Monkey or Monkey Island.Complexity: MediumImpact: Medium
Description
Describe the bug
Using Docker, Monkey Island is unable to read configuration from a previous instance.
To Reproduce
Steps to reproduce the behavior:
- Follow the instructions to run a Monkey Island instance with Docker: https://www.guardicore.com/infectionmonkey/wt/docker.html
- Access Monkey Island web interface
- Go to configuration
- Change something (or not) and save the new settings
- Kill the running container of Monkey Island
- Start Monkey Island again
- To go the configuration
- 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
Reacted by Vakaris Žilius
Metadata
Metadata
Assignees
Labels
BugAn error, flaw, misbehavior or failure in the Monkey or Monkey Island.An error, flaw, misbehavior or failure in the Monkey or Monkey Island.Complexity: MediumImpact: Medium
Activity
mssalvatore commentedon Mar 23, 2021
@Sodki Can you be specific about the exact commands you're using to reproduce the issue?
Sodki commentedon Mar 23, 2021
Here's a shorter version of the instructions above:
docker run --network=host mongodocker run --network=host guardicore/monkey-island:1.9.0https://localhost:5000/configure, press the Submit buttondocker run --network=host guardicore/monkey-island:1.9.0https://localhost:5000/configure, it's now brokenIf 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.
mssalvatore commentedon Mar 23, 2021
@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.0image, 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:
Run
docker container list --allyou should see a list that looks something likeYou 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_wuto restart the existing container, which will contain the correct key material.Restart the mongo container. This will remove the old db entirely.
Possible longer-term solutions for the project are one or more of:
docs: Add `--volume` workaround to docker troubleshooting
mssalvatore commentedon Jun 7, 2021
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.
docs: Add `--volume` workaround to docker troubleshooting