Commit Graph

3157 Commits

Author SHA1 Message Date
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