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

Feature/support subnet in config #94

Merged
merged 14 commits into from
Apr 12, 2018

Conversation

itaymmguardicore
Copy link
Contributor

@itaymmguardicore itaymmguardicore commented Feb 20, 2018

Feature

Closes #92 - Support configuring subnets for scanning.
Closes #100 - Renamed range file

  • Have you added an explanation of what your changes do and why you'd like to include them?

  • Have you successfully tested your changes locally?

  • Example screenshot/log transcript of the feature working
    2018-02-20 16:13:21,108 [19636:DEBUG] network_scanner.get_victim_machines.52: Scanning for potential victims in the network <FixedRange 192.168.1.34/30,192.168.2.50-192.168.2.54>

Changes

  • fixed_range now supports subnets in formats: CIDR and ip ranges
  • Documentation of the config value updated

@itaymmguardicore itaymmguardicore self-assigned this Feb 20, 2018
@itaymmguardicore itaymmguardicore added monkey Feature Issue that describes a new feature to be implemented. labels Feb 20, 2018
Copy link
Contributor

@danielguardicore danielguardicore left a comment

Choose a reason for hiding this comment

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

Few notes:

I think I want the common code as a separate PR. Reason is if we're doing this there's more code that can easily be lifted out (network/info, can also pull config for a server side validation of config!) and I really don't like what it does to the .spec file.

Didn't we also want to avoid naming the file range.py?

Otherwise, mostly LGTM.

self._shuffle = shuffle

def get_range(self):
return [x for x in self._get_range() if (x & 0xFF != 0)] # remove broadcast ips
Copy link
Contributor

Choose a reason for hiding this comment

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

That's broadcast only if we're in a class C subnet. If we're in any other network, this is the wrong lookup.
If we're working with a CidrRange, we should use the ipaddress module to know if this is a broadcast, otherwise we can't know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm removing this and adding a filter to CidrRange.

@@ -0,0 +1,113 @@
import random
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't we want to change the name of the file anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

class CidrRange(NetworkRange):
def __init__(self, cidr_range, shuffle=True):
super(CidrRange, self).__init__(shuffle=shuffle)
self._cidr_range = cidr_range.strip()
Copy link
Contributor

Choose a reason for hiding this comment

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

We already stripped the string in get_range_object or are you assuming someone might explicitly instance CidrRange?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Someone might explicitly instance CidrRange

import struct
from abc import ABCMeta, abstractmethod

import ipaddress
Copy link
Contributor

Choose a reason for hiding this comment

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

For some reason, ipaddress does not show up in https://github.com/guardicore/monkey/blob/feature/support-subnet-in-config/infection_monkey/requirements.txt

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

yield self._number_to_ip(x)

@abstractmethod
def is_in_range(self, ip_address):
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently this is unused, any particular reason we want this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will be in use in detect-cross-segment-traffic

ip_interface = ipaddress.ip_interface(u"%s/24" % address_str)
addrs = [str(addr) for addr in ip_interface.network.hosts() if addr != host_address]
res.extend(addrs)
res.append(CidrRange(cidr_range="%s/24" % (address_str, )))
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason we want to keep the class C limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was there previously. Logic says more than that is too much.
Your call whether to remove the limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather remove these limits soon, or make it configurable. But that depends on what we think is realistic. @ofriz ?

Copy link

Choose a reason for hiding this comment

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

let's remove this limitation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fixed

@itaymmguardicore itaymmguardicore merged commit 768d144 into develop Apr 12, 2018
@itaymmguardicore itaymmguardicore deleted the feature/support-subnet-in-config branch April 12, 2018 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Issue that describes a new feature to be implemented.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename "range" file to something that's not a python keyword Support subnet in config
3 participants