From f4b5d341cfa960809185176e614114022892cf68 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 1 Jun 2021 12:14:57 +0530 Subject: [PATCH] Finish up hooking frontend and backend for export config --- .../cc/resources/configuration_export.py | 4 +++- .../cc/services/utils/config_encryption.py | 1 + .../configuration-components/ExportConfigModal.tsx | 14 ++++++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/resources/configuration_export.py b/monkey/monkey_island/cc/resources/configuration_export.py index 2b759cf76..b3de58f92 100644 --- a/monkey/monkey_island/cc/resources/configuration_export.py +++ b/monkey/monkey_island/cc/resources/configuration_export.py @@ -11,7 +11,7 @@ from monkey_island.cc.services.utils.config_encryption import encrypt_config class ConfigurationExport(flask_restful.Resource): @jwt_required def get(self): - return {"encrypted_config": self.config_to_return} + return {"to_export": self.config_to_return, "is_plaintext": self.is_plaintext} @jwt_required def post(self): @@ -21,8 +21,10 @@ class ConfigurationExport(flask_restful.Resource): plaintext_config = ConfigService.get_config() self.config_to_return = plaintext_config + self.is_plaintext = True if should_encrypt: password = data["password"] self.config_to_return = encrypt_config(plaintext_config, password) + self.is_plaintext = False return self.get() diff --git a/monkey/monkey_island/cc/services/utils/config_encryption.py b/monkey/monkey_island/cc/services/utils/config_encryption.py index 379e91c74..ada10aab2 100644 --- a/monkey/monkey_island/cc/services/utils/config_encryption.py +++ b/monkey/monkey_island/cc/services/utils/config_encryption.py @@ -15,6 +15,7 @@ def encrypt_config(config: Dict, password: str) -> str: pyAesCrypt.encryptStream( plaintext_config_stream, ciphertext_config_stream, password, BUFFER_SIZE ) + ciphertext_config_bytes = str(ciphertext_config_stream.getvalue()) return ciphertext_config_bytes diff --git a/monkey/monkey_island/cc/ui/src/components/configuration-components/ExportConfigModal.tsx b/monkey/monkey_island/cc/ui/src/components/configuration-components/ExportConfigModal.tsx index b2adbc694..c12208170 100644 --- a/monkey/monkey_island/cc/ui/src/components/configuration-components/ExportConfigModal.tsx +++ b/monkey/monkey_island/cc/ui/src/components/configuration-components/ExportConfigModal.tsx @@ -35,11 +35,17 @@ const ConfigExportModal = (props: Props) => { } ) .then(res => res.json()) - .then(res => { - console.log(res); - const configAsBinary = new Blob([res['encrypted_config']]); - + .then(res => { + let configToExport = res['to_export']; + if (res['is_plaintext'] === true) { + const configAsBinary = new Blob([configToExport], {type: 'text/plain;charset=utf-8'}); FileSaver.saveAs(configAsBinary, 'monkey.conf'); + } + else { + const configAsBinary = new Blob([configToExport.slice(2, -1)]); + FileSaver.saveAs(configAsBinary, 'monkey.conf'); + + } }) }