Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2004 scan target configuration #2133

Merged
merged 12 commits into from
Aug 1, 2022
Merged

Conversation

VakarisZ
Copy link
Contributor

What does this PR do?

Fixes network target configuration part of #2004

Add any further explanations here.

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?
  • Have you checked that you haven't introduced any duplicate code?

Testing Checklist

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

    Tested by running the added unit tests

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

@codecov
Copy link

codecov bot commented Jul 27, 2022

Codecov Report

Merging #2133 (22b3874) into develop (85211c3) will increase coverage by 0.24%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #2133      +/-   ##
===========================================
+ Coverage    56.64%   56.89%   +0.24%     
===========================================
  Files          486      489       +3     
  Lines        13226    13278      +52     
===========================================
+ Hits          7492     7554      +62     
+ Misses        5734     5724      -10     
Impacted Files Coverage Δ
...on/agent_configuration/agent_sub_configurations.py 100.00% <ø> (ø)
...t_configuration/agent_sub_configuration_schemas.py 100.00% <100.00%> (ø)
.../common/agent_configuration/validators/__init__.py 100.00% <100.00%> (ø)
...common/agent_configuration/validators/filenames.py 100.00% <100.00%> (ø)
...common/agent_configuration/validators/ip_ranges.py 100.00% <100.00%> (ø)
.../monkey_island/in_memory_credentials_repository.py 87.50% <0.00%> (-4.17%) ⬇️
...onkey/monkey_island/cc/services/representations.py 89.28% <0.00%> (-3.03%) ⬇️
monkey/infection_monkey/exploit/zerologon.py 30.82% <0.00%> (ø)
monkey/infection_monkey/master/propagator.py 98.98% <0.00%> (+0.13%) ⬆️
...key_island/cc/resources/propagation_credentials.py 100.00% <0.00%> (+23.52%) ⬆️

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 85211c3...22b3874. Read the comment docs.

Copy link
Contributor

@shreyamalviya shreyamalviya left a comment

Choose a reason for hiding this comment

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

If we're not going to be using the IP range validators anywhere else, move them to be inside the schema class, as done with CustomPBAConfigurationSchema. Or move that validation out to a separate file. The former makes more sense to me but in any case, this needs to be consistent.

@VakarisZ
Copy link
Contributor Author

VakarisZ commented Jul 28, 2022

If we're not going to be using the IP range validators anywhere else, move them to be inside the schema class, as done with CustomPBAConfigurationSchema. Or move that validation out to a separate file. The former makes more sense to me but in any case, this needs to be consistent.

We can use them on any hostname, ip or ip range input. Moving them into schema would require some work and I'm not sure we even gain anything. I would rather move the windows filename validation away into validators. It makes the schema smaller, separates validation responsibility and once we need to upload more files we won't need to rework the schema

Comment on lines 34 to 37
if match and match.group() == hostname:
return
else:
raise ValidationError(f"Invalid hostname {hostname}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if match and match.group() == hostname:
return
else:
raise ValidationError(f"Invalid hostname {hostname}")
if not (match and match.group() == hostname):
raise ValidationError(f"Invalid hostname {hostname}")

monkey/common/agent_configuration/validators/ip_ranges.py Outdated Show resolved Hide resolved
Comment on lines 49 to 64
try:
ip_range = ip_range.replace(" ", "")
ips = ip_range.split("-")
validate_ip(ips[0])
validate_ip(ips[1])
if len(ips) != 2:
raise ValidationError(f"Invalid IP range {ip_range}")
except (AddressValueError, IndexError):
raise ValidationError(f"Invalid IP range {ip_range}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you do the length check first you don't need to handle IndexError.

Suggested change
try:
ip_range = ip_range.replace(" ", "")
ips = ip_range.split("-")
validate_ip(ips[0])
validate_ip(ips[1])
if len(ips) != 2:
raise ValidationError(f"Invalid IP range {ip_range}")
except (AddressValueError, IndexError):
raise ValidationError(f"Invalid IP range {ip_range}")
ip_range = ip_range.replace(" ", "")
ips = ip_range.split("-")
if len(ips) != 2:
raise ValidationError(f"Invalid IP range {ip_range}")
try:
validate_ip(ips[0])
validate_ip(ips[1])
except AddressValueError:
raise ValidationError(f"Invalid IP range {ip_range}")

@VakarisZ VakarisZ force-pushed the 2004-scan-target-configuration branch from c8e5d53 to a1760a8 Compare July 28, 2022 13:43
Copy link
Contributor

@shreyamalviya shreyamalviya left a comment

Choose a reason for hiding this comment

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

UTs missing for ScanTargetConfiguration in tests/unit_tests/common/configuration/test_agent_configuration.py and for common/agent_configuration/validators/filenames.py

monkey/common/agent_configuration/validators/filenames.py Outdated Show resolved Hide resolved
Comment on lines 15 to 21
def validate_windows_filename(windows_filename: str):
validate_windows_filename_not_reserved(windows_filename)
if not re.match(_valid_windows_filename_regex, windows_filename):
raise ValidationError(f"Invalid Windows filename {windows_filename}: illegal characters")


def validate_windows_filename_not_reserved(windows_filename: str):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def validate_windows_filename(windows_filename: str):
validate_windows_filename_not_reserved(windows_filename)
if not re.match(_valid_windows_filename_regex, windows_filename):
raise ValidationError(f"Invalid Windows filename {windows_filename}: illegal characters")
def validate_windows_filename_not_reserved(windows_filename: str):
def validate_windows_filename(windows_filename: str):
_validate_windows_filename_not_reserved(windows_filename)
if not re.match(_valid_windows_filename_regex, windows_filename):
raise ValidationError(f"Invalid Windows filename {windows_filename}: illegal characters")
def _validate_windows_filename_not_reserved(windows_filename: str):


def validate_windows_filename_not_reserved(windows_filename: str):
# filename shouldn't start with any of these and be followed by a period
if PureWindowsPath(windows_filename).is_reserved():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fantastic!

@VakarisZ VakarisZ merged commit fd1c10c into develop Aug 1, 2022
@VakarisZ VakarisZ deleted the 2004-scan-target-configuration branch August 1, 2022 14:05
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