Skip to content

Conversation

VakarisZ
Copy link
Contributor

@VakarisZ VakarisZ commented Jul 2, 2021

What does this PR do?

Fixes a bug where windows environmental variables don't get expanded in encryption and readme features.

Traceback example of the bug:

2021-07-02 14:38:13,187 [3928:4432:INFO] ransomware_payload.run_payload.46: Running ransomware payload
2021-07-02 14:38:13,187 [3928:4432:INFO] ransomware_payload._find_files.53: Collecting files in $OneDrive
2021-07-02 14:38:13,187 [3928:4432:ERROR] monkey.run_ransomware.483: An unexpected error occurred while running the ransomware payload: [WinError 3] The system cannot find the path specified: '$OneDrive'

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the CHANGELOG.md updated to reflect the changes?
  • Was the documentation framework updated to reflect the changes?

Testing Checklist

  • Added relevant unit tests?
  • Have you successfully tested your changes locally? Elaborate:

    Tested by running with %temp% and $temp paths

  • If applicable, add screenshots or log transcripts of the feature working

@codecov
Copy link

codecov bot commented Jul 2, 2021

Codecov Report

Merging #1292 (53faf5a) into develop (f698c88) will increase coverage by 0.04%.
The diff coverage is 86.66%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1292      +/-   ##
===========================================
+ Coverage    30.68%   30.72%   +0.04%     
===========================================
  Files          449      450       +1     
  Lines        13470    13475       +5     
===========================================
+ Hits          4133     4140       +7     
+ Misses        9337     9335       -2     
Impacted Files Coverage Δ
monkey/monkey_island/cc/server_utils/file_utils.py 58.46% <ø> (-1.24%) ⬇️
monkey/monkey_island/cc/setup/config_setup.py 0.00% <0.00%> (ø)
monkey/common/utils/file_utils.py 100.00% <100.00%> (ø)
.../infection_monkey/ransomware/ransomware_payload.py 95.52% <100.00%> (+0.06%) ⬆️
monkey/monkey_island/cc/server_utils/consts.py 92.59% <100.00%> (ø)
...ey/monkey_island/cc/setup/island_config_options.py 100.00% <100.00%> (ø)
...unit_tests/infection_monkey/ransomware/conftest.py 100.00% <100.00%> (ø)
monkey/tests/conftest.py 100.00% <0.00%> (+18.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f698c88...53faf5a. Read the comment docs.

@@ -55,7 +56,7 @@ def _find_files(self) -> List[Path]:
return []

return select_production_safe_target_files(
Path(self._target_dir), self._valid_file_extensions_for_encryption
Path(os.path.expandvars(self._target_dir)), self._valid_file_extensions_for_encryption
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use expand_path() from monkey_island/cc/server_utils/file_utils.py It also expands "~" to "$HOME". We should probably add a validator to the Linux target directory input to allow paths that begin with "~".

from common.common_consts.telem_categories import TelemCategoryEnum
from infection_monkey.telemetry.base_telem import BaseTelem
from infection_monkey.telemetry.batchable_telem_mixin import BatchableTelemMixin
from infection_monkey.telemetry.i_batchable_telem import IBatchableTelem


class FileEncryptionTelem(BatchableTelemMixin, IBatchableTelem, BaseTelem):
def __init__(self, filepath: Path, success: bool, error: str):
def __init__(self, filepath: str, success: bool, error: str):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? All of the added calls to os.path.expandvars() are wrapped in Path()

Copy link
Collaborator

@mssalvatore mssalvatore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It needs unit tests 🙂 You can use "patched_home_env()" and take a look at test_island_config_options.py for examples.

In general, if we fix a bug, we should write a test to make sure the bug doesn't creep back in later.

@mssalvatore mssalvatore merged commit 8dd1aa2 into develop Jul 6, 2021
@shreyamalviya shreyamalviya deleted the ransomware_dir_fix branch August 2, 2021 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants