guardicore / monkey

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

Mongodb sharing #993

Open VakarisZ opened 3 years ago

VakarisZ commented 3 years ago

Is your feature request related to a problem? Please describe. As the team is growing, we should find a way to share mongodb's. Current problem is the encryption, which doesn't seem to work between machines (to reproduce go to config page):

2021-02-24 17:02:14,278 - app.py:1892 - log_exception() - ERROR - Exception on /api/configuration/island [GET]
Traceback (most recent call last):
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\flask_restful\__init__.py", line 468, in wrapper
    resp = resource(*args, **kwargs)
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\flask\views.py", line 89, in view
    return self.dispatch_request(*args, **kwargs)
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\flask_restful\__init__.py", line 583, in dispatch_request
    resp = meth(*args, **kwargs)
  File "C:\Users\Vakaris\Desktop\infection_monkey\monkey\monkey_island\cc\resources\auth\auth.py", line 63, in wrapper
    return fn(*args, **kwargs)
  File "C:\Users\Vakaris\Desktop\infection_monkey\monkey\monkey_island\cc\resources\island_configuration.py", line 14, in get
    configuration=ConfigService.get_config(False, True, True))
  File "C:\Users\Vakaris\Desktop\infection_monkey\monkey\monkey_island\cc\services\config.py", line 56, in get_config
    ConfigService.decrypt_config(config)
  File "C:\Users\Vakaris\Desktop\infection_monkey\monkey\monkey_island\cc\services\config.py", line 281, in decrypt_config
    ConfigService._encrypt_or_decrypt_config(config, True)
  File "C:\Users\Vakaris\Desktop\infection_monkey\monkey\monkey_island\cc\services\config.py", line 326, in _encrypt_or_decrypt_config
    encryptor.dec(config_arr) if is_decrypt else encryptor.enc(config_arr)
  File "C:\Users\Vakaris\Desktop\infection_monkey\monkey\monkey_island\cc\server_utils\encryptor.py", line 51, in dec
    cipher = AES.new(self._cipher_key, AES.MODE_CBC, cipher_iv)
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\Crypto\Cipher\AES.py", line 232, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\Crypto\Cipher\__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "C:\Users\Vakaris\AppData\Roaming\Python\Python37\site-packages\Crypto\Cipher\_mode_cbc.py", line 288, in _create_cbc_cipher
    factory.block_size)
ValueError: Incorrect IV length (it must be 16 bytes long)

Describe the solution you'd like I'd like to be able to import/export databases between different island instances.

acepace commented 3 years ago

The correct way is mongodump and mongorestore, rather than anything custom...

VakarisZ commented 3 years ago

How will mongodump and mongorestore solve the error provided?