Commit Graph

3354 Commits

Author SHA1 Message Date
Mike Salvatore 5c1902ca73 agent: Add file_extension_filter to dir_utils 2021-06-22 13:17:11 -04:00
Mike Salvatore cf2cdc4ab8 agent: Add filter_files() function to dir_utils 2021-06-22 13:16:53 -04:00
Mike Salvatore bfc86041ab agent: Switch get_all_files_in_directory from str to Path
Path and PurePath objects provide a lot of syntactic sugar to file
handling that makes the code clearer and more concise.
2021-06-22 12:58:03 -04:00
Mike Salvatore e2dfd6a5e3 agent: Simplify get_all_files_in_directory() with list comprehension 2021-06-22 12:15:03 -04:00
Shreya efef40edf9 tests: Fix ransomware tests and move tests for get_all_files_in_directory from ransomware/test_utils.py to utils/test_dir_utils.py 2021-06-22 20:07:38 +05:30
Shreya a2ebe3386f agent: Rename utils/file_utils.py to utils/dir_utils.py 2021-06-22 20:02:59 +05:30
Shreya 5f714e0d98 agent: Move get_all_files_in_directory() from ransomware/utils.py to utils/file_utils.py 2021-06-22 19:45:50 +05:30
Shreya c6da73ad79 agent: ransomware: Incorporate changes into stub 2021-06-22 19:42:50 +05:30
Shreya 48967a2e5b tests: Modify unit tests for ransomware utils to test for a file like file.jpg.zip 2021-06-22 19:30:44 +05:30
Shreya 8abb9d95ce agent: ransomware: Move VALID_FILE_EXTENSIONS_FOR_ENCRYPTION to separate file 2021-06-22 19:30:44 +05:30
Shreya f8c1886977 tests: Add unit tests for ransomware utils - get_files_to_encrypt(), get_all_files_in_directory() 2021-06-22 19:30:44 +05:30
Shreya 3192355f5a agent: ransomware: Return list instead of filter object when getting files in directory 2021-06-22 19:30:44 +05:30
Shreya 5b64ea5151 agent: ransomware: Iterate through files in directory and get list of files to encrypt 2021-06-22 19:30:44 +05:30
Mike Salvatore ccc3557021
Merge pull request #1255 from guardicore/ransomware_stub
Adds ransomware stub
2021-06-22 09:59:14 -04:00
VakarisZ 947a03c9a1 Refactor ransomware configuration option from flattened to a dict that encompasses any ransomware options 2021-06-22 16:42:09 +03:00
VakarisZ 63901bcd26 Refactor ransomware payload __init__.py into ransomware_payload.py with a stubbed ransomware payload class 2021-06-22 16:37:44 +03:00
VakarisZ d7f4035884 Adds ransomware entrypoint in monkey and logs values provided in ransomware configuration options 2021-06-22 10:39:02 +03:00
VakarisZ 00edb17b86 Adds ransomware page to the configuration UI 2021-06-22 10:35:21 +03:00
VakarisZ 9ef4ce8bac Fixes formatting and naming for ransomware configuration options 2021-06-22 09:47:11 +03:00
VakarisZ 1ede7ebaec Adds ransomware configuration options to monkey configuration 2021-06-22 09:14:29 +03:00
Mike Salvatore 02ed22bab7 island: Remove FILE_SHARE_WRITE from windows permissions
Granting FILE_SHARE_WRITE on mongo_key.bin is unnecessary. Since
mongo_key.bin is the only file that is created using
_get_file_descriptor_for_new_secure_file_windows() at the moment, we
won't grant FILE_SHARE_WRITE.
2021-06-21 14:00:30 -04:00
Mike Salvatore 2d18a68787 island: Fix return type hint for _get_null_value_for_win32()
The _get_null_value_for_win32() function does not return None, it
returns a PyHANDLE object. For the moment, I'm unable to determine the
correct way to import PyHANDLE so that it can be specified in the type
hint. Since type hints aren't actually enforced, it's not worth the
effort to fully solve this at the present time, so the type hint has
just been removed.
2021-06-21 10:40:09 -04:00
Mike Salvatore 51aa0d1564 island: Refactor get_file_descriptor_for_new_secure_file as contextmgr
get_file_descriptor_for_new_secure_file() has been refactored as a
contextmanager. Additionally, it has been renamed to
open_new_securely_permissioned_file(). The function can now be used
similarly to open().

Example:

with open_new_securely_permissioned_file(file_path, "wb") as f:
    f.write(data)
2021-06-21 10:40:08 -04:00
Mike Salvatore b39440e871 island: Return a fd instead of PyHandle during windows file creation
Fixes #1252
2021-06-21 09:20:58 -04:00
shreyamalviya ec2fb182de tests: Modify test_file_utils.py to check for inheritance when creating secure file/dir on Windows 2021-06-21 14:02:40 +05:30
VakarisZ 84868b29ef Adds ransomware section to island's configuration schema 2021-06-21 10:56:44 +03:00
shreyamalviya 0ded39bb62 island: Add inheritance when setting Windows file or dir permissions
Add container and object inheritance to the ACE's security descriptor
when setting Windows permissions
2021-06-18 20:11:33 +05:30
VakarisZ cfdf1183f5 Fix invalid handle for mongo key file error by using the filename instead 2021-06-18 12:30:46 +03:00
Ilija Lazoroski b586bc5624 Added troubleshooting section to infection monkey readme and monkey_island readme. 2021-06-16 06:57:40 -04:00
Ilija Lazoroski ef3cbe51cf Added altpgraph to the Pipfile. 2021-06-15 14:53:30 -04:00
Mike Salvatore 44bdfa5508 island: Rename create_secure_file tests
create_secure_file() was previously renamed to
get_file_descriptor_for_new_secure_file().
2021-06-15 13:14:31 -04:00
Mike Salvatore 327ff7a626 island: Remove isfile() check from get_file_descriptor_for_new_secure_file()
get_file_descriptor_for_new_secure_file() should return a file
descriptor. If the file already exists, this function would return
nothing, potentially causing issues with whatever relies on this
function's output.
2021-06-15 13:12:18 -04:00
Shreya 80bfd90074 island: Specify mode to open new secure file in, in encryptor.py 2021-06-15 19:29:49 +05:30
Shreya 64ac1fe706 island: Add type hinting in file_utils.py 2021-06-15 19:24:55 +05:30
Shreya 22c3c5a11b tests: Fix secure file creation tests as per latest changes 2021-06-15 19:24:50 +05:30
Shreya 37889d0b87 island: Extract code to `_get_null_value_for_win32()` in file_utils.py 2021-06-15 19:10:28 +05:30
Shreya b648452b5f island: Fix comment and statement formatting in file_utils.py 2021-06-15 19:10:28 +05:30
Shreya 14371f3fba island: Return file descriptor when creating secure file 2021-06-15 19:10:28 +05:30
Mike Salvatore 6b4a0906c0 island: use constants for permissions mode in test_file_utils.py 2021-06-15 09:31:22 -04:00
Mike Salvatore 8b2c3ef8a3 island: Remove execute bit from "secure" file creation 2021-06-15 09:29:18 -04:00
Shreya e90bf52674 island: Use `Path().touch()` instead of `os.open()` when securely creating a file on Linux 2021-06-15 15:51:02 +05:30
shreyamalviya e01165403a island, tests: Run isort and black on previously changed files 2021-06-15 12:51:10 +05:30
shreyamalviya 5abcadc69a tests: Move tests from test_utils.py to test_file_utils.py 2021-06-15 12:47:34 +05:30
shreyamalviya b5f092a85c island: Move code from cc/environment/utils.py to cc/server_utils/file_utils.py 2021-06-15 12:46:18 +05:30
shreyamalviya 91873343dd tests: Add comment to `test_create_secure_directory__perm_windows()` explaining when it fails 2021-06-15 12:26:58 +05:30
shreyamalviya d7565fc515 island: Use stat.S_IRWXU in place of 0o700 in cc/environment/utils.py 2021-06-15 12:23:13 +05:30
shreyamalviya 5ea046eda5 island: Format cc/environment/utils.py with black 2021-06-15 00:06:40 +05:30
shreyamalviya 443b66e9d9 tests: Remove accidental code in `_get_acl_and_sid_from_path()` in test_utils.py 2021-06-14 23:50:08 +05:30
shreyamalviya 1170b176d3 island: Fix Windows' secure file creation by using a different file flag 2021-06-14 23:41:56 +05:30
shreyamalviya 7ddb986f15 tests: Fix file creation unit tests in test_utils.py 2021-06-14 23:24:52 +05:30
shreyamalviya 1467a53e60 island: Use win32file.CloseHandle() to close file descriptor on Windows 2021-06-14 23:24:09 +05:30
shreyamalviya 37eda4e7ad island: Fix secure file creation on Windows 2021-06-14 23:15:17 +05:30
Shreya c0d9489100 tests: Extract duplicate code in Windows tests in test_utils 2021-06-14 17:59:57 +05:30
Shreya 6d360ef865 tests: Fix assertion in `test_create_secure_directory__perm_linux()` 2021-06-14 17:51:55 +05:30
Shreya 248d57789f tests: Add unit tests for securly creating a file 2021-06-14 17:50:40 +05:30
Shreya 5fe0c80377 island: Can't use `with` with `os.open()`, use `os.close()` to close file descriptor 2021-06-14 17:07:47 +05:30
Shreya 8b932e1946 island: Add os.O_EXCL flag so that an error is thrown if trying to create a file that exists 2021-06-14 16:49:24 +05:30
Shreya 8dd4bb5e17 island: Use 'x' instead of '_' when creating a secure file 2021-06-14 16:26:00 +05:30
Shreya 26ae50f90f island: Create mongo key file securely before using it 2021-06-14 13:21:45 +05:30
Shreya ff85360639 island: Add functions to create a file securely on Linux and Windows 2021-06-14 13:21:45 +05:30
Shreya 5d7d86aedc island: Modify log message when creating secure directory on Windows 2021-06-14 13:21:46 +05:30
VakarisZ feeba1ea60
Merge pull request #1204 from guardicore/config_encrypt
Config encrypt
2021-06-11 17:09:07 +03:00
Mike Salvatore 57f35f9045 island: Fix typo in ConfigurationImport error logging 2021-06-11 09:28:29 -04:00
VakarisZ 8a673cc76c Added the logging for errors encountered in configuration decryption workflow 2021-06-11 16:25:47 +03:00
VakarisZ fbe9b4f4d7 Typos and small bugfixes for configuration export/import UI. 2021-06-11 16:06:04 +03:00
VakarisZ 5c7bab7a0d Refactored json parsing out of encryption/decryption functionality. 2021-06-11 16:05:32 +03:00
VakarisZ 3450b80a82 Refactored cyphertext to ciphertext for consistency 2021-06-11 11:43:15 +03:00
VakarisZ 5cf002d81a Refactored unit tests and added a unit test for a function which checks whether or not config is encrypted. 2021-06-11 11:40:07 +03:00
VakarisZ a36fc81755 Refactored configuration import and added a check to decide if configuration is encrypted or not. This solved a bug where invalid json was treated as credential error. 2021-06-11 11:40:07 +03:00
Mike Salvatore e2326fd71f
Merge pull request #1221 from guardicore/remove-ssl-perms-checks
Remove ssl perms checks
2021-06-10 13:08:12 -04:00
shreyamalviya f04f307f78 Add unit test for Linux directory permissions (removed accidentally previously) 2021-06-10 17:23:32 +05:30
Mike Salvatore 6a1a1721bd island: Loosen permissions on ssl cert in create_certificate.sh 2021-06-10 07:38:29 -04:00
Shreya Malviya 5d8db4b112
Update log message in monkey/monkey_island/cc/environment/utils.py
Co-authored-by: Mike Salvatore <mike.s.salvatore@gmail.com>
2021-06-10 17:03:01 +05:30
shreyamalviya 92a71451fb Remove unused import in test_utils.py 2021-06-10 17:01:57 +05:30
shreyamalviya 7643102ccd Rename function to not use abbreviations 2021-06-10 16:56:50 +05:30
Mike Salvatore 937dbac4d0 island: Remove SSL permissions checks
These checks prevent the docker container from working properly, as the
default SSL cert must have at least 444 permissions.
2021-06-10 06:57:45 -04:00
shreyamalviya 74111f80e9 Remove `create_parents_dir` parameter when creating directories
Can't create parents on Windows using pywin32.
Removed it completely so that behavior is consistent across OSes.
2021-06-10 15:25:16 +05:30
shreyamalviya 1fa2ffe8f7 Fix Windows directory creation 2021-06-10 15:25:16 +05:30
shreyamalviya 54f5524760 Fix race condition during Windows directory creation 2021-06-10 15:25:12 +05:30
VakarisZ 36e0309409 Fixed a race condition for linux secure directory creation, by setting dir permissions on creation. 2021-06-10 11:44:50 +03:00
Mike Salvatore 2fc726dc78 island: Add missing "f" to format string 2021-06-09 15:11:52 -04:00
Mike Salvatore 1c5daf168c Merge branch 'custom-certificate' into develop 2021-06-09 15:10:14 -04:00
Mike Salvatore 6aa76497ec island: Use config file in ~/.monkey_island if it exists 2021-06-09 14:48:59 -04:00
Mike Salvatore 9131f86215 island: remove misleading comment
We don't check admin permissions at all, and admin is included in
"everyone else".
2021-06-09 14:20:58 -04:00
Mike Salvatore 67d4f18d65 tests: Refactor create_empty_file() -> create_empty_tmp_file() 2021-06-09 14:14:44 -04:00
Mike Salvatore cf5b1378f2 island: Consolidate duplicate code in test_island_config_options_validator 2021-06-09 14:06:54 -04:00
Mike Salvatore 7fe10af1b2 island: Pass int, not str to has_expected_permissions() 2021-06-09 13:55:48 -04:00
shreyamalviya 5aaa844289 Add missing constant in config_setup.py 2021-06-09 22:00:44 +05:30
shreyamalviya 91a7c42a85 Format test_island_config_options_validator.py with black 2021-06-09 21:56:44 +05:30
shreyamalviya 8a321f0290 Add Windows tests for island_config_options_validator.py 2021-06-09 21:52:07 +05:30
Mike Salvatore b98ebc8a69 island: Remove tmpdir cleanup code from test_utils.py
Pytest automatically cleans up tmpdir fixtures older than 3 runs. See
https://docs.pytest.org/en/6.2.x/tmpdir.html#the-default-base-temporary-directory

Windows10 and Linux will automatically clean their temp directories.
2021-06-09 10:36:37 -04:00
Mike Salvatore 00b37ca6a5 island: Test windows permissions set by create_secure_directory() 2021-06-09 10:32:42 -04:00
shreyamalviya 91aad66e16 Modify log message when checking file permissions
Removed code to display it in octal since it makes no sense on Windows.
Added `oct()` around linux permissions when expected_permissions is
being defined.
2021-06-09 19:51:20 +05:30
shreyamalviya 424aceb116 Use constants instead of permission masks 2021-06-09 19:38:45 +05:30
shreyamalviya 84b0664423 Modify comment in monkey_island/cc/server_utils/file_utils.py 2021-06-09 19:37:58 +05:30
Mike Salvatore 945e1adf58 island: Split has_expected_permissions() into os-specific functions 2021-06-09 09:47:23 -04:00
shreyamalviya dc8e2b018d Fix/ignore flake8 and fix isort warnings 2021-06-09 07:39:56 -04:00
shreyamalviya cd2f627cc1 Add tests for Windows file permissions checking 2021-06-09 07:39:56 -04:00
shreyamalviya fcd758e24f Fix Windows file permissions checking 2021-06-09 07:39:56 -04:00
Shreya 438a63b0f4 Fix Windows file permission checking 2021-06-09 07:39:56 -04:00
Shreya f1d85dbc44 Change default cert permissions in bat script for creating default cert 2021-06-09 07:39:56 -04:00
Shreya 011ab2a393 Modify `has_expected_permissions()` to check files on Windows 2021-06-09 07:39:56 -04:00
Shreya 10e7b19669 Fix consts.py (mix up during rebase) 2021-06-09 07:39:56 -04:00
shreyamalviya ef17b7f9c8 Add unit tests for windows directory permission setting 2021-06-09 16:31:27 +05:30
Mike Salvatore 3841dd7f7b island: Set tighter permissions on certs in create_certificate.sh 2021-06-08 07:17:59 -04:00
Mike Salvatore 4b119ab4ce island: Skip some island_config_options_validator tests on Windows 2021-06-08 06:35:15 -04:00
Mike Salvatore 63fb396bbb island: Add unit tests for island_config_options_validator 2021-06-07 19:55:33 -04:00
Mike Salvatore b80dd59352 tests: move create_empty_file() to conftest.py 2021-06-07 19:44:06 -04:00
Mike Salvatore 78af0d86aa island: Move IslandConfigOptions validation to separate module 2021-06-07 19:28:03 -04:00
Mike Salvatore c19dc9dcad island: Add config validation to IslandConfigOptions 2021-06-07 14:41:05 -04:00
Mike Salvatore a45848ce0c island: Move file_has_expected_permissions() to file_utils.py
Rename to `has_expected_permissions()` as
`file_has_expected_permissions()` is now reduntant.

Add unit tests
2021-06-07 14:12:48 -04:00
Mike Salvatore 36314f09ae island: Use certificate provided in config, not environment variables 2021-06-07 13:24:31 -04:00
Mike Salvatore 4e1b4fbf6b island: Replace calls to os.{expandpath,expandusers} with expand_path() 2021-06-07 13:21:16 -04:00
Mike Salvatore bf0fe10ea9 island: Add unit tests for expand_path() 2021-06-07 13:18:04 -04:00
Mike Salvatore 8744011297 island: move set_home_env() to conftest.py so it can be reused 2021-06-07 13:17:22 -04:00
Mike Salvatore 0519153aaf island: Move _expand_path() to file_utils.py so it can be reused 2021-06-07 13:04:38 -04:00
Mike Salvatore e4866b1286 island: Change _expand_path() from a static to regular function
_expand_path() is a utility function used by IslandConfigOptions. It
doesn't need to be part of the class. It can potentially be reused by
other modules that require the same functionality.
2021-06-07 12:57:42 -04:00
Mike Salvatore f0a109a145 island: Add tests for ssl_certificate_key_file 2021-06-07 12:53:32 -04:00
Mike Salvatore 4231f316db island: Add tests for ssl_certificate_file 2021-06-07 12:41:11 -04:00
Mike Salvatore f2a2efc2a7 island: Remove redundant "test_island_config_options" from tests
The file is named "test_island_config_options.py". Including
"island_config_options" in every test/function name is reduntant.
2021-06-07 12:30:03 -04:00
Mike Salvatore ea0d6f0141 island: Add a generalized testing function to test_island_config_options 2021-06-07 12:20:32 -04:00
Shreya 4f601ca5dc Pass file paths to setup_certificate() instead of IslandConfigOptions 2021-06-07 20:12:29 +05:30
Shreya 42a9a79800 Modify server_config.json ssl cert fields 2021-06-07 20:12:29 +05:30
Shreya 2b73ec75c8 Move monkey_island/cc/setup/certificate/certificate_setup.py to monkey/monkey_island/cc/setup/certificate_setup.py 2021-06-07 20:12:29 +05:30
Shreya 227039f30c Add `_expand_path()` to wrap `os.path.expandvars()\' and `os.path.expanduser()\' 2021-06-07 20:12:27 +05:30
Mike Salvatore a815850c9e Merge branch 'default-data-dir-bug' into develop 2021-06-07 06:41:38 -04:00
Mike Salvatore 2b1af17433
island: Add typehint to create_default_server_config_file()
Co-authored-by: Shreya Malviya <shreya.malviya@gmail.com>
2021-06-07 06:39:05 -04:00
VakarisZ abaeafcb6b Split one unit test test_encrypt_decrypt_config__malformed into two, one for too short configuration, another one for corrupted file. 2021-06-07 11:43:44 +03:00
VakarisZ 04a35a1e36 Improved wording in configuration export related logs and UI 2021-06-07 11:41:28 +03:00
VakarisZ 1125b0fe4b Added pyAesEncrypt to the Pipfile 2021-06-07 11:31:46 +03:00
VakarisZ e918ae1d2c Renamed a unit test to be more specific: test_decrypt_config__no_password -> test_encrypt_decrypt_config__decrypt_no_password 2021-06-07 11:30:49 +03:00
VakarisZ c487a278fe Fixed a type-hint for a config decryption method 2021-06-07 11:30:10 +03:00
Shreya 5ba8effe1a Use octal representation for permissions 2021-06-07 13:26:14 +05:30
Shreya 4ad49d19c7 Rename "required" permissions to "expected" permissions 2021-06-07 13:22:44 +05:30
Shreya 53a126482f Extract file checking activities 2021-06-07 13:22:38 +05:30
Mike Salvatore b0ac07553a island: Assert isdir() in test_monkey_island_abs_path() 2021-06-06 19:01:16 -04:00
Shreya d740173f79 Post-rebase fixes 2021-06-04 13:20:01 +05:30
Shreya 88ae762618 Expand cert and key path in IslandConfigOptions 2021-06-04 12:23:04 +05:30
Shreya a2bd59c377 Move `has_sufficient_permissions` to a separate file in utils/ 2021-06-04 12:23:03 +05:30
Shreya 6f1154f911 Add log message for which certificate is being used 2021-06-04 12:23:03 +05:30
Shreya c1463b4a18 Implement `has_sufficient_permissions` function for checking certificate files 2021-06-04 12:23:03 +05:30
Shreya c9a53833e2 Add support for custom certificate (partially) 2021-06-04 12:23:03 +05:30
Mike Salvatore 0cd9709b82 island: Remove server_config.json.develop
Since Monkey Island no longer writes to server_config.json in the source
code directory, and each package will overwrite server_config.json with
its own server config (until we separate the deployment from the config
in issue #1205), we no longer need server_config.json.develop and we
don't need to worry about accidentally committing credentials to git.
2021-06-03 20:38:13 -04:00
Mike Salvatore e57e28a97f island: Consolidate tests for consts.py 2021-06-03 20:25:07 -04:00
Mike Salvatore 5ecc02d553 island: Use the data_dir specified in the default server config 2021-06-03 20:25:05 -04:00
Mike Salvatore 19e47583e9 island: Use `os.getcwd()` for MONKEY_ISLAND_ABS_PATH on Windows
See issue #1207 for more details.
2021-06-03 15:51:36 -04:00
Mike Salvatore 03b543f7f6 island: Move setup/island_config_options.py -> cc/setup/ 2021-06-03 12:20:55 -04:00
Mike Salvatore 623d551c6c island: Move setup/config_setup.py -> cc/setup/config_setup.py 2021-06-03 11:12:39 -04:00
Mike Salvatore ac407bf48a island: Remove unused mongo_url from BootloaderHttpServer constructor 2021-06-03 11:09:07 -04:00
Mike Salvatore 4f97be59c3 island: Rename _initialize_global_resources -> _initialize_globals 2021-06-03 11:06:04 -04:00
Mike Salvatore 92293e601c island: Add unit test for MONKEY_ISLAND_ABS_PATH
If the consts.py is moved, MONKEY_ISLAND_ABS_PATH may be incorrect. This
unit test guards against the introduction of a bug if consts.py is
moved.
2021-06-03 11:04:16 -04:00
Mike Salvatore c40af5073b island: Rename start_island() -> main() 2021-06-03 11:01:03 -04:00
Mike Salvatore 3917663c5c island: Rename startup.py -> main.py 2021-06-03 11:00:12 -04:00
Mike Salvatore 44a3456c62 island: Remove the responsibility of choosing a log file from MongoDbProcess 2021-06-03 10:57:23 -04:00
Mike Salvatore 5f25debfd2 island: Decouple mongo_setup from IslandConfigOptions 2021-06-03 10:57:23 -04:00
Mike Salvatore edbb2c39f3 island: Trap OSError and JSONDecodeError when reading config 2021-06-03 10:57:23 -04:00
Mike Salvatore 4a1653ed5f island: Do not start bootloader server if --setup-only is passed 2021-06-03 10:57:23 -04:00
Mike Salvatore 19e8042ee4 island: Construct mongo run command in MongoDbProcess constructor 2021-06-03 10:57:23 -04:00
Mike Salvatore cc1865dc5b island: Log a warning if MongoDbProcess.stop() is erroniously called 2021-06-03 10:57:23 -04:00
Mike Salvatore e80ac4c943 island; Build log file path in MongoDbProcess constructor 2021-06-03 10:57:23 -04:00
Mike Salvatore 12b11ce260 island: Rename _build_mongo_launch_cmd -> _build_mongo_run_cmd 2021-06-03 10:57:23 -04:00
Mike Salvatore 3b958f5a61 island: Inline method _start_mongodb_process() in MongoDbProcess 2021-06-03 10:57:23 -04:00
Mike Salvatore 1e21446bb8 island: Rename logging_dir_path -> _logging_dir in MongoDbProcess 2021-06-03 10:57:23 -04:00
Mike Salvatore a3bd432538 island: Remove directory creation logic from MongoDbProcess 2021-06-03 10:57:23 -04:00
Mike Salvatore 7d85ce0611 island: Store MongoDB logs in mondogb.log instead of mongo_log.txt
".log" is the standard extension for log files.
2021-06-03 10:57:23 -04:00
Mike Salvatore 559af47928 island: Clean up MongoDB subprocess when Monkey Island shuts down 2021-06-03 10:57:23 -04:00
Mike Salvatore d1a2501a5b island: Add connect_to_mongo() function 2021-06-03 10:57:23 -04:00
Mike Salvatore dc40713683 island: Rename launch_mongodb() -> start() 2021-06-03 10:57:23 -04:00
Mike Salvatore d35099fa9b island: Rename MongoDbRunner -> MongoDbProcess 2021-06-03 10:57:23 -04:00
Mike Salvatore 28a34a4ec9 island: Use MONKEY_ISLAND_ABS_PATH to locate STIX attack data 2021-06-03 10:57:23 -04:00
Mike Salvatore a8570987a6 island: Find MONKEY_ISLAND_ABS_PATH by __file__ instead of os.getcwd()
We can't be sure what $PWD is when Monkey Island is started.
2021-06-03 10:57:23 -04:00
Mike Salvatore 184594f509 island: Refactor setup/start logic separate concerns
Most configuration/setup logic is removed from monkey_island.py. The
only responsibility of startup.py is now to setup a default
failsafe logger and call run_monkey_island().

setup_island() has been renamed to run_monkey_island(), since that's
what it does. Some of the logic used to setup/configure/initialize
monkey island has been wrapped in different functions with specific
responsibilities.

setup_mongodb() has been renamed to start_mongodb(), since that's what
it does.
2021-06-03 10:57:23 -04:00
Mike Salvatore 5e78666f91 island: Add function to setup default failsafe logger 2021-06-03 10:57:23 -04:00
Mike Salvatore 583115c419 island: Reset logger handlers after each test
The root logger does not get reset for each test that is run. Add an
autouse fixture that resets the logger handlers after each test run so
that handlers do not accumulate in the root logger.
2021-06-03 10:57:23 -04:00
Mike Salvatore 14b68580f8 island: Configure loggin in python code instead of JSON 2021-06-03 10:57:23 -04:00
VakarisZ cc00b85edc Refactored monkey island startup files to the old structure which was compatible with our build scripts. 2021-06-03 10:56:46 -04:00
VakarisZ 2f9c6bf035 Improved readability in configuration_import.py by removing unused variables and extracting methods. 2021-06-03 17:02:14 +03:00
VakarisZ c25ea0edf8 Fixed bugs in config import backend (related to json parsing and stringifying) and front end (unsafe import warning overlay) 2021-06-03 17:02:14 +03:00
VakarisZ b407094a2f Reworded the text of UnsafeOptionsConfirmationModal to specify that it's about configuration and renamed it to UnsafeConfigOptionsConfirmationModal 2021-06-03 17:02:14 +03:00
VakarisZ fc1f12c24d Implemented safety check on import. 2021-06-03 17:02:12 +03:00
VakarisZ 500f270aa9 Fixed, improved and tested configuration import and export. 2021-06-03 17:01:59 +03:00
VakarisZ 8b86e40259 Improved configuration export and fixed the bug of modal not closing on export. 2021-06-03 17:01:59 +03:00
VakarisZ 624fda10cb Renamed configuration import resource endpoint(url) and resource itself. 2021-06-03 17:01:59 +03:00
VakarisZ 51273c4a9d Removed unused exception 2021-06-03 17:01:58 +03:00
VakarisZ 9fcfaac781 Improved exceptions thrown in configuration decryption and unit tests. 2021-06-03 17:01:56 +03:00
VakarisZ 321dd2c55e Improved configuration export related code by making it cleaner/more trivial 2021-06-03 17:01:27 +03:00
Shreya 295cacaffc Add unit tests for config_encryption.py 2021-06-03 17:01:27 +03:00
VakarisZ a94047d778 Fixed configuration encryption/decryption to use b64 encoding 2021-06-03 17:01:27 +03:00
Shreya 7153b91c10 Use buffer size directly from pyAesCrypt 2021-06-03 17:01:27 +03:00
Shreya b9fb4c6902 Add exception handling for config decryption 2021-06-03 17:01:27 +03:00
Shreya d67e84a6a7 Make sure (1) config is updated before exporting; (2) plaintext config is exported correctly 2021-06-03 17:01:27 +03:00
Shreya f4b5d341cf Finish up hooking frontend and backend for export config 2021-06-03 17:01:27 +03:00
VakarisZ 46408e6d32 Implemented export byte saving to file 2021-06-03 17:01:27 +03:00
Shreya 308ae3e169 Link config encryption backend logic with frontend (partially) 2021-06-03 17:01:27 +03:00
Shreya 495eb4c6a3 Modify config encryption logic: don't save the file in the backend, just encrypt it and send it back to the frontend 2021-06-03 17:01:26 +03:00
Shreya 338404799e Add initial implementation of encrypting config and saving it on export 2021-06-03 17:01:26 +03:00
VakarisZ 7954dbe1e7 Fixed and improved the wording in configuration export and import modals. 2021-06-03 17:01:26 +03:00
VakarisZ 5ab0137f27 Improved a mock endpoint for testing import configuration modal 2021-06-03 17:01:26 +03:00
VakarisZ ff7760f202 Altered ConfigurePage.js to use import modal 2021-06-03 17:01:26 +03:00
VakarisZ 556d0828ef Added import config modal. 2021-06-03 17:01:26 +03:00
VakarisZ 691dfee4f8 Added an upload status icon (checkmark if successful, red x if error) 2021-06-03 17:01:26 +03:00
VakarisZ 34024794c8 Implemented the skeleton of import config modal 2021-06-03 17:01:26 +03:00
VakarisZ 6e2da3c4a5 Sketched out the infrastructure of configuration import modal window 2021-06-03 17:01:26 +03:00
VakarisZ e6bb48100e
Merge pull request #1190 from guardicore/vulture-skip-unit-tests
Configure Vulture to skip tests/unit_tests/
2021-06-03 09:35:22 +03:00
Shreya 55ed8d28d0 Rearranged unused code in Vulture whitelist according to categories 2021-06-02 13:05:21 +05:30
Mike Salvatore 09e7deb936 island: Use os.path.join when creating test config contents dict 2021-06-01 03:59:07 -04:00
Mike Salvatore 2cd665ff11 island: Refactor duplicate code in IslandConfigOptions data_dir tests 2021-06-01 03:46:28 -04:00
Mike Salvatore c761dba030 island: Expand environment variables in data_dir 2021-06-01 03:35:33 -04:00
Mike Salvatore 0ab20d558b island: Add unit test to verify '~' expanded in data_dir 2021-06-01 03:33:34 -04:00
Shreya Malviya f3fccb3e06
Merge pull request #1188 from guardicore/mongodb_connection_setup_refactoring
Mongodb connection setup refactoring
2021-05-28 16:07:28 +05:30
VakarisZ eae63bd3c6 Deleted empty test file, removed irrelevant comments and moved import to the top in monkey_island.py 2021-05-28 13:26:13 +03:00
Shreya Malviya a0487f480b
Update export config modal message for plaintext export 2021-05-28 14:56:44 +05:30
VakarisZ d0f5893e41 Finished up the configuration export modal and it's styling. 2021-05-28 10:57:31 +03:00
VakarisZ 3240e1138e Sketched out export config modal infrastructure 2021-05-27 16:25:00 +03:00
VakarisZ dbade5951c Removed unused unit test - test_mongo_setup.py. This is mongo setup tests db dir creation, which is already tested in test_utils.py 2021-05-27 16:02:01 +03:00
VakarisZ f2c8de9eb6 Improved unit test readability and fixed bugs related to refactoring of mongodb parameters in environment config 2021-05-27 15:57:57 +03:00
VakarisZ 2e600fd5b2 Decoupled mongo setup from environment config 2021-05-27 15:57:12 +03:00
VakarisZ 289f3df7e4 Implemented mongodb process launch from the island 2021-05-27 15:54:07 +03:00
VakarisZ 26e57153da Fixed typos and renamed windows permission setting function in windows_permissions.py to be more specific. 2021-05-27 14:09:21 +03:00
Shreya 4b733ba383 Fix unit tests (test_utils.py) 2021-05-27 15:40:47 +05:30
VakarisZ 7240d60342 Typos and small bugfixes in mongo_process_runner.py 2021-05-27 11:08:09 +03:00
VakarisZ cb14a4ea9b Refactored secure directory creation into a separate method. Data dir creation and db dir creation now use that method. Added unit tests for secure directory creation. 2021-05-27 11:08:09 +03:00
VakarisZ 5aeab3a56c Refactored mongo executable path to be calculated in consts, since this is a trivial calculation. 2021-05-27 11:08:07 +03:00
VakarisZ f7674b0635 Aggregated duplicate runtime os checking functions into one. 2021-05-27 11:05:54 +03:00
Shreya f5f8f572f6 Remove unneeded function arguments in test_mongo_process_runner.py 2021-05-27 11:05:54 +03:00
Shreya 1610860bd0 Rename test_process_runner.py to test_mongo_process_runner.py to better reflect the file it's testing 2021-05-27 11:05:54 +03:00
Shreya 0be8e56858 Add fixture for fake db dir in test_process_runner.py 2021-05-27 11:05:54 +03:00
Shreya 58745a0eb4 Use fixtures in test_process_runner.py 2021-05-27 11:05:54 +03:00
VakarisZ a5d72c8b94 Fixed an import statement in monkey_island/main.py 2021-05-27 11:05:43 +03:00
VakarisZ 36b3e987da Added expand user call to transform data dir input into a proper path 2021-05-27 11:05:43 +03:00
VakarisZ 559b61b581 Removed code related to running mongodb and db folder creation 2021-05-27 11:05:43 +03:00
VakarisZ 73f23ad383 Removed run.sh and updated mongodb related documentation: removed db folder creation and run.sh execution on linux 2021-05-27 11:05:43 +03:00
VakarisZ 5ec64ef189 Added unit test for db dir creation. 2021-05-27 11:05:43 +03:00
VakarisZ 2483691b8b Implemented mongodb process launch from the island 2021-05-27 11:05:41 +03:00
VakarisZ a31067a752 Added a common method to determine the runtime OS 2021-05-27 11:03:51 +03:00
Shreya 02ead23d04 Remove unused unit test fixtures 2021-05-26 19:27:08 +05:30
Shreya 31d65301d4 Remove unused file (monkey_island/config_file_parser.py) and its test file (tests/unit_tests/monkey_island/test_config_file_parser.py) 2021-05-26 19:16:46 +05:30
Shreya baee74b761 Add exception messages during data directory creation 2021-05-26 15:22:52 +05:30
Shreya a89a62cb5c Remove unneeded "noqa" statements 2021-05-26 12:55:23 +05:30
VakarisZ 17e994c8d8 Fixed UT's for models by mocking an environment singleton with needed mongodb parameters 2021-05-25 11:12:58 +03:00
VakarisZ 5b7329b3d1 Fixed stack-overflow that has been happening due to gevent unpatched imports 2021-05-25 10:21:27 +03:00
VakarisZ 057a579d62 Rolled back the changes that made default server config on model packages import 2021-05-25 09:49:34 +03:00
VakarisZ 9337c68ae0 Removed the infrastructure from starting main.py - it can no longer be the entrypoint to the application 2021-05-24 18:08:26 +03:00
VakarisZ 3a800d9a44 Fixed a bug where models were getting imported without mongodb connection and failing 2021-05-24 18:07:24 +03:00
VakarisZ d273e85858 Fixed bugs in argument parser passing default server config path even though server path is not specified. Island thinks that server config path was specified. 2021-05-24 17:09:14 +03:00
VakarisZ 2b257f0012 Fixed bugs merge bugs where structures are being accessed in an outdated ways 2021-05-24 16:44:43 +03:00
VakarisZ 0a7cf1d5ee Improved readability in the arg_parser.py by extracting defaults to the argparser flag section 2021-05-24 16:42:30 +03:00
VakarisZ 7d1c5dd908 Merged develop into data-dir-on-island-init 2021-05-24 16:00:21 +03:00
VakarisZ 0248a6e281 Refactored IslandConfigOptions tests to be test per option, rather than based on code workflow branches 2021-05-24 14:25:22 +03:00
VakarisZ d52e80a3f3 Improved the readability IslandConfigOptions test 2021-05-24 14:03:49 +03:00