forked from p15670423/monkey
Replaced six package usages with py3
This commit is contained in:
parent
c56dea39a9
commit
f60cdd116b
|
@ -4,7 +4,6 @@ import struct
|
||||||
from abc import ABCMeta, abstractmethod
|
from abc import ABCMeta, abstractmethod
|
||||||
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
from six import text_type
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__author__ = 'itamar'
|
__author__ = 'itamar'
|
||||||
|
@ -78,7 +77,7 @@ class CidrRange(NetworkRange):
|
||||||
def __init__(self, cidr_range, shuffle=True):
|
def __init__(self, cidr_range, shuffle=True):
|
||||||
super(CidrRange, self).__init__(shuffle=shuffle)
|
super(CidrRange, self).__init__(shuffle=shuffle)
|
||||||
self._cidr_range = cidr_range.strip()
|
self._cidr_range = cidr_range.strip()
|
||||||
self._ip_network = ipaddress.ip_network(text_type(self._cidr_range), strict=False)
|
self._ip_network = ipaddress.ip_network(str(self._cidr_range), strict=False)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<CidrRange %s>" % (self._cidr_range,)
|
return "<CidrRange %s>" % (self._cidr_range,)
|
||||||
|
|
|
@ -7,8 +7,6 @@ import struct
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from six.moves import range
|
|
||||||
|
|
||||||
from infection_monkey.pyinstaller_utils import get_binary_file_path
|
from infection_monkey.pyinstaller_utils import get_binary_file_path
|
||||||
from infection_monkey.utils.environment import is_64bit_python
|
from infection_monkey.utils.environment import is_64bit_python
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ import collections
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from jsonschema import Draft4Validator, validators
|
from jsonschema import Draft4Validator, validators
|
||||||
from six import string_types
|
|
||||||
import monkey_island.cc.services.post_breach_files
|
import monkey_island.cc.services.post_breach_files
|
||||||
|
|
||||||
from monkey_island.cc.database import mongo
|
from monkey_island.cc.database import mongo
|
||||||
|
@ -236,7 +235,7 @@ class ConfigService:
|
||||||
keys = [config_arr_as_array[2] for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS]
|
keys = [config_arr_as_array[2] for config_arr_as_array in ENCRYPTED_CONFIG_ARRAYS]
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if isinstance(flat_config[key], collections.Sequence) and not isinstance(flat_config[key], string_types):
|
if isinstance(flat_config[key], collections.Sequence) and not isinstance(flat_config[key], str):
|
||||||
# Check if we are decrypting ssh key pair
|
# Check if we are decrypting ssh key pair
|
||||||
if flat_config[key] and isinstance(flat_config[key][0], dict) and 'public_key' in flat_config[key][0]:
|
if flat_config[key] and isinstance(flat_config[key][0], dict) and 'public_key' in flat_config[key][0]:
|
||||||
flat_config[key] = [ConfigService.decrypt_ssh_key_pair(item) for item in flat_config[key]]
|
flat_config[key] = [ConfigService.decrypt_ssh_key_pair(item) for item in flat_config[key]]
|
||||||
|
@ -257,7 +256,7 @@ class ConfigService:
|
||||||
parent_config_arr = config_arr
|
parent_config_arr = config_arr
|
||||||
config_arr = config_arr[config_key_part]
|
config_arr = config_arr[config_key_part]
|
||||||
|
|
||||||
if isinstance(config_arr, collections.Sequence) and not isinstance(config_arr, string_types):
|
if isinstance(config_arr, collections.Sequence) and not isinstance(config_arr, str):
|
||||||
for i in range(len(config_arr)):
|
for i in range(len(config_arr)):
|
||||||
# Check if array of shh key pairs and then decrypt
|
# Check if array of shh key pairs and then decrypt
|
||||||
if isinstance(config_arr[i], dict) and 'public_key' in config_arr[i]:
|
if isinstance(config_arr[i], dict) and 'public_key' in config_arr[i]:
|
||||||
|
|
|
@ -5,7 +5,6 @@ import logging
|
||||||
import ipaddress
|
import ipaddress
|
||||||
from bson import json_util
|
from bson import json_util
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from six import text_type
|
|
||||||
|
|
||||||
from common.network.network_range import NetworkRange
|
from common.network.network_range import NetworkRange
|
||||||
from common.network.segmentation_utils import get_ip_in_src_and_not_in_dst
|
from common.network.segmentation_utils import get_ip_in_src_and_not_in_dst
|
||||||
|
@ -396,7 +395,7 @@ class ReportService:
|
||||||
|
|
||||||
return \
|
return \
|
||||||
[
|
[
|
||||||
ipaddress.ip_interface(text_type(network['addr'] + '/' + network['netmask'])).network
|
ipaddress.ip_interface(str(network['addr'] + '/' + network['netmask'])).network
|
||||||
for network in network_info['data']['network_info']['networks']
|
for network in network_info['data']['network_info']['networks']
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -409,7 +408,7 @@ class ReportService:
|
||||||
monkey_subnets = ReportService.get_monkey_subnets(monkey['guid'])
|
monkey_subnets = ReportService.get_monkey_subnets(monkey['guid'])
|
||||||
for subnet in monkey_subnets:
|
for subnet in monkey_subnets:
|
||||||
for ip in island_ips:
|
for ip in island_ips:
|
||||||
if ipaddress.ip_address(text_type(ip)) in subnet:
|
if ipaddress.ip_address(str(ip)) in subnet:
|
||||||
found_good_ip = True
|
found_good_ip = True
|
||||||
break
|
break
|
||||||
if found_good_ip:
|
if found_good_ip:
|
||||||
|
@ -438,7 +437,7 @@ class ReportService:
|
||||||
ip_in_src = None
|
ip_in_src = None
|
||||||
ip_in_dst = None
|
ip_in_dst = None
|
||||||
for ip_addr in monkey['ip_addresses']:
|
for ip_addr in monkey['ip_addresses']:
|
||||||
if source_subnet_range.is_in_range(text_type(ip_addr)):
|
if source_subnet_range.is_in_range(str(ip_addr)):
|
||||||
ip_in_src = ip_addr
|
ip_in_src = ip_addr
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -447,7 +446,7 @@ class ReportService:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for ip_addr in monkey['ip_addresses']:
|
for ip_addr in monkey['ip_addresses']:
|
||||||
if target_subnet_range.is_in_range(text_type(ip_addr)):
|
if target_subnet_range.is_in_range(str(ip_addr)):
|
||||||
ip_in_dst = ip_addr
|
ip_in_dst = ip_addr
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -483,7 +482,7 @@ class ReportService:
|
||||||
scans.rewind() # If we iterated over scans already we need to rewind.
|
scans.rewind() # If we iterated over scans already we need to rewind.
|
||||||
for scan in scans:
|
for scan in scans:
|
||||||
target_ip = scan['data']['machine']['ip_addr']
|
target_ip = scan['data']['machine']['ip_addr']
|
||||||
if target_subnet_range.is_in_range(text_type(target_ip)):
|
if target_subnet_range.is_in_range(str(target_ip)):
|
||||||
monkey = NodeService.get_monkey_by_guid(scan['monkey_guid'])
|
monkey = NodeService.get_monkey_by_guid(scan['monkey_guid'])
|
||||||
cross_segment_ip = get_ip_in_src_and_not_in_dst(monkey['ip_addresses'],
|
cross_segment_ip = get_ip_in_src_and_not_in_dst(monkey['ip_addresses'],
|
||||||
source_subnet_range,
|
source_subnet_range,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import itertools
|
import itertools
|
||||||
from six import text_type
|
|
||||||
|
|
||||||
from common.data.zero_trust_consts import STATUS_FAILED, EVENT_TYPE_MONKEY_NETWORK, STATUS_PASSED
|
from common.data.zero_trust_consts import STATUS_FAILED, EVENT_TYPE_MONKEY_NETWORK, STATUS_PASSED
|
||||||
from common.network.network_range import NetworkRange
|
from common.network.network_range import NetworkRange
|
||||||
|
@ -34,8 +33,7 @@ def test_segmentation_violation(current_monkey, target_ip):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def is_segmentation_violation(current_monkey, target_ip, source_subnet, target_subnet):
|
def is_segmentation_violation(current_monkey: Monkey, target_ip: str, source_subnet: str, target_subnet: str) -> bool:
|
||||||
# type: (Monkey, str, str, str) -> bool
|
|
||||||
"""
|
"""
|
||||||
Checks is a specific communication is a segmentation violation.
|
Checks is a specific communication is a segmentation violation.
|
||||||
:param current_monkey: The source monkey which originated the communication.
|
:param current_monkey: The source monkey which originated the communication.
|
||||||
|
@ -49,7 +47,7 @@ def is_segmentation_violation(current_monkey, target_ip, source_subnet, target_s
|
||||||
source_subnet_range = NetworkRange.get_range_obj(source_subnet)
|
source_subnet_range = NetworkRange.get_range_obj(source_subnet)
|
||||||
target_subnet_range = NetworkRange.get_range_obj(target_subnet)
|
target_subnet_range = NetworkRange.get_range_obj(target_subnet)
|
||||||
|
|
||||||
if target_subnet_range.is_in_range(text_type(target_ip)):
|
if target_subnet_range.is_in_range(str(target_ip)):
|
||||||
cross_segment_ip = get_ip_in_src_and_not_in_dst(
|
cross_segment_ip = get_ip_in_src_and_not_in_dst(
|
||||||
current_monkey.ip_addresses,
|
current_monkey.ip_addresses,
|
||||||
source_subnet_range,
|
source_subnet_range,
|
||||||
|
|
Loading…
Reference in New Issue