String vs byte stream mixup bugs fixed

This commit is contained in:
VakarisZ 2019-09-20 18:07:17 +03:00
parent 9bcaf8b512
commit ea40620373
15 changed files with 7021 additions and 5577 deletions

View File

@ -160,12 +160,9 @@ class SingleIpRange(NetworkRange):
# The most common use case is to enter ip/range into "Scan IP/subnet list" # The most common use case is to enter ip/range into "Scan IP/subnet list"
domain_name = '' domain_name = ''
# Make sure to have unicode string
user_input = string.decode('utf-8', 'ignore')
# Try casting user's input as IP # Try casting user's input as IP
try: try:
ip = ipaddress.ip_address(user_input).exploded ip = ipaddress.ip_address(string).exploded
except ValueError: except ValueError:
# Exception means that it's a domain name # Exception means that it's a domain name
try: try:

View File

@ -1,4 +1,4 @@
from .infection_monkey.main import main from infection_monkey.main import main
if "__main__" == __name__: if "__main__" == __name__:
main() main()

View File

@ -4,11 +4,11 @@ import os
import subprocess import subprocess
import sys import sys
import time import time
from six.moves import xrange
import infection_monkey.tunnel as tunnel import infection_monkey.tunnel as tunnel
from infection_monkey.utils.monkey_dir import create_monkey_dir, get_monkey_dir_path, remove_monkey_dir from infection_monkey.utils.monkey_dir import create_monkey_dir, get_monkey_dir_path, remove_monkey_dir
from infection_monkey.utils.monkey_log_path import get_monkey_log_path from infection_monkey.utils.monkey_log_path import get_monkey_log_path
from infection_monkey.utils.environment import is_windows_os
from infection_monkey.config import WormConfiguration from infection_monkey.config import WormConfiguration
from infection_monkey.control import ControlClient from infection_monkey.control import ControlClient
from infection_monkey.model import DELAY_DELETE_CMD from infection_monkey.model import DELAY_DELETE_CMD
@ -105,7 +105,7 @@ class InfectionMonkey(object):
ControlClient.wakeup(parent=self._parent) ControlClient.wakeup(parent=self._parent)
ControlClient.load_control_config() ControlClient.load_control_config()
if utils.is_windows_os(): if is_windows_os():
T1106Telem(ScanStatus.USED, UsageEnum.SINGLETON_WINAPI).send() T1106Telem(ScanStatus.USED, UsageEnum.SINGLETON_WINAPI).send()
if not WormConfiguration.alive: if not WormConfiguration.alive:
@ -258,7 +258,7 @@ class InfectionMonkey(object):
try: try:
status = None status = None
if "win32" == sys.platform: if "win32" == sys.platform:
from _subprocess import SW_HIDE, STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE from subprocess import SW_HIDE, STARTF_USESHOWWINDOW, CREATE_NEW_CONSOLE
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = CREATE_NEW_CONSOLE | STARTF_USESHOWWINDOW startupinfo.dwFlags = CREATE_NEW_CONSOLE | STARTF_USESHOWWINDOW
startupinfo.wShowWindow = SW_HIDE startupinfo.wShowWindow = SW_HIDE

View File

@ -19,7 +19,7 @@ class VirtualFile(BytesIO):
if name in VirtualFile._vfs: if name in VirtualFile._vfs:
super(VirtualFile, self).__init__(self._vfs[name]) super(VirtualFile, self).__init__(self._vfs[name])
else: else:
super(VirtualFile, self).__init__('') super(VirtualFile, self).__init__()
def flush(self): def flush(self):
super(VirtualFile, self).flush() super(VirtualFile, self).flush()

View File

@ -1,4 +1,3 @@
import os
import sys import sys
import socket import socket
import struct import struct
@ -13,6 +12,7 @@ import requests
from requests import ConnectionError from requests import ConnectionError
from common.network.network_range import CidrRange from common.network.network_range import CidrRange
from infection_monkey.utils.environment import is_windows_os
# Timeout for monkey connections # Timeout for monkey connections
@ -39,11 +39,11 @@ def get_host_subnets():
if 'broadcast' in network: if 'broadcast' in network:
network.pop('broadcast') network.pop('broadcast')
for attr in network: for attr in network:
network[attr] = network[attr].encode('utf-8').strip() network[attr] = network[attr]
return ipv4_nets return ipv4_nets
if sys.platform == "win32": if is_windows_os():
def local_ips(): def local_ips():
local_hostname = socket.gethostname() local_hostname = socket.gethostname()
@ -159,7 +159,7 @@ def get_interfaces_ranges():
return res return res
if sys.platform == "win32": if is_windows_os():
def get_ip_for_connection(target_ip): def get_ip_for_connection(target_ip):
return None return None
else: else:

View File

@ -161,7 +161,7 @@ def check_tcp_ports(ip, ports, timeout=DEFAULT_TIMEOUT, get_banner=False):
if get_banner and (len(connected_ports_sockets) != 0): if get_banner and (len(connected_ports_sockets) != 0):
readable_sockets, _, _ = select.select([s[1] for s in connected_ports_sockets], [], [], 0) readable_sockets, _, _ = select.select([s[1] for s in connected_ports_sockets], [], [], 0)
# read first BANNER_READ bytes # read first BANNER_READ bytes
banners = [sock.recv(BANNER_READ) if sock in readable_sockets else "" banners = [sock.recv(BANNER_READ).decode() if sock in readable_sockets else ""
for port, sock in connected_ports_sockets] for port, sock in connected_ports_sockets]
pass pass
# try to cleanup # try to cleanup

View File

@ -2,14 +2,15 @@ import os
import logging import logging
import sys import sys
sys.coinit_flags = 0 # needed for proper destruction of the wmi python module
import infection_monkey.config import infection_monkey.config
from infection_monkey.system_info.mimikatz_collector import MimikatzCollector from infection_monkey.system_info.mimikatz_collector import MimikatzCollector
from infection_monkey.system_info import InfoCollector from infection_monkey.system_info import InfoCollector
from infection_monkey.system_info.wmi_consts import WMI_CLASSES from infection_monkey.system_info.wmi_consts import WMI_CLASSES
from common.utils.wmi_utils import WMIUtils from common.utils.wmi_utils import WMIUtils
sys.coinit_flags = 0 # needed for proper destruction of the wmi python module
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
LOG.info('started windows info collector') LOG.info('started windows info collector')

View File

@ -40,7 +40,7 @@ class WindowsSystemSingleton(_SystemSingleton):
handle = ctypes.windll.kernel32.CreateMutexA(None, handle = ctypes.windll.kernel32.CreateMutexA(None,
ctypes.c_bool(True), ctypes.c_bool(True),
ctypes.c_char_p(self._mutex_name)) ctypes.c_char_p(self._mutex_name.encode()))
last_error = ctypes.windll.kernel32.GetLastError() last_error = ctypes.windll.kernel32.GetLastError()
if not handle: if not handle:

View File

@ -33,7 +33,7 @@ class BaseTelem(object, metaclass=abc.ABCMeta):
pass pass
@abc.abstractmethod @abc.abstractmethod
def get_data(self): def get_data(self) -> dict:
""" """
:return: Data of telemetry (should be dict) :return: Data of telemetry (should be dict)
""" """

View File

@ -1,4 +1,4 @@
from .monkey_island.cc.main import main from monkey_island.cc.main import main
if "__main__" == __name__: if "__main__" == __name__:
main() main()

View File

@ -35,7 +35,7 @@ class Encryptor:
return message + (self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE)) * chr( return message + (self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE)) * chr(
self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE)) self._BLOCK_SIZE - (len(message) % self._BLOCK_SIZE))
def _unpad(self, message): def _unpad(self, message: str):
return message[0:-ord(message[len(message) - 1])] return message[0:-ord(message[len(message) - 1])]
def enc(self, message): def enc(self, message):
@ -47,7 +47,7 @@ class Encryptor:
enc_message = base64.b64decode(enc_message) enc_message = base64.b64decode(enc_message)
cipher_iv = enc_message[0:AES.block_size] cipher_iv = enc_message[0:AES.block_size]
cipher = AES.new(self._cipher_key, AES.MODE_CBC, cipher_iv) cipher = AES.new(self._cipher_key, AES.MODE_CBC, cipher_iv)
return self._unpad(cipher.decrypt(enc_message[AES.block_size:])) return self._unpad(cipher.decrypt(enc_message[AES.block_size:]).decode())
encryptor = Encryptor() encryptor = Encryptor()

View File

@ -34,7 +34,7 @@ class LogService:
@staticmethod @staticmethod
def add_log(monkey_id, log_data, timestamp=datetime.now()): def add_log(monkey_id, log_data, timestamp=datetime.now()):
LogService.remove_logs_by_monkey_id(monkey_id) LogService.remove_logs_by_monkey_id(monkey_id)
file_id = database.gridfs.put(log_data) file_id = database.gridfs.put(log_data, encoding='utf-8')
return mongo.db.log.insert( return mongo.db.log.insert(
{ {
'monkey_id': monkey_id, 'monkey_id': monkey_id,

View File

@ -52,7 +52,7 @@ class NodeService:
exploit["origin"] = NodeService.get_monkey_label(NodeService.get_monkey_by_id(edge["from"])) exploit["origin"] = NodeService.get_monkey_label(NodeService.get_monkey_by_id(edge["from"]))
exploits.append(exploit) exploits.append(exploit)
exploits.sort(cmp=NodeService._cmp_exploits_by_timestamp) exploits.sort(key=NodeService._cmp_exploits_by_timestamp)
new_node["exploits"] = exploits new_node["exploits"] = exploits
new_node["accessible_from_nodes"] = accessible_from_nodes new_node["accessible_from_nodes"] = accessible_from_nodes

File diff suppressed because it is too large Load Diff

View File

@ -33,16 +33,16 @@
"babel-preset-stage-0": "^6.5.0", "babel-preset-stage-0": "^6.5.0",
"bower-webpack-plugin": "^0.1.9", "bower-webpack-plugin": "^0.1.9",
"chai": "^4.2.0", "chai": "^4.2.0",
"copyfiles": "^2.1.0", "copyfiles": "^2.1.1",
"css-loader": "^1.0.0", "css-loader": "^1.0.1",
"eslint": "^5.6.1", "eslint": "^5.16.0",
"eslint-loader": "^2.1.1", "eslint-loader": "^2.2.1",
"eslint-plugin-react": "^7.11.1", "eslint-plugin-react": "^7.14.3",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
"glob": "^7.1.3", "glob": "^7.1.4",
"html-loader": "^0.5.5", "html-loader": "^0.5.5",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
"karma": "^3.0.0", "karma": "^3.1.4",
"karma-chai": "^0.1.0", "karma-chai": "^0.1.0",
"karma-coverage": "^1.1.2", "karma-coverage": "^1.1.2",
"karma-mocha": "^1.0.0", "karma-mocha": "^1.0.0",
@ -56,55 +56,55 @@
"phantomjs-prebuilt": "^2.1.16", "phantomjs-prebuilt": "^2.1.16",
"react-addons-test-utils": "^15.6.2", "react-addons-test-utils": "^15.6.2",
"react-event-timeline": "^1.6.3", "react-event-timeline": "^1.6.3",
"react-hot-loader": "^4.3.11", "react-hot-loader": "^4.12.13",
"rimraf": "^2.6.2", "rimraf": "^2.7.1",
"style-loader": "^0.22.1", "style-loader": "^0.22.1",
"url-loader": "^1.1.2", "url-loader": "^1.1.2",
"webpack": "^4.20.2", "webpack": "^4.40.2",
"webpack-cli": "^3.1.2", "webpack-cli": "^3.3.9",
"webpack-dev-server": "^3.1.9" "webpack-dev-server": "^3.8.1"
}, },
"dependencies": { "dependencies": {
"@emotion/core": "^10.0.10", "@emotion/core": "^10.0.17",
"@kunukn/react-collapse": "^1.0.5", "@kunukn/react-collapse": "^1.2.7",
"bootstrap": "3.4.1", "bootstrap": "3.4.1",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"core-js": "^2.5.7", "core-js": "^2.6.9",
"d3": "^5.11.0", "d3": "^5.11.0",
"downloadjs": "^1.4.7", "downloadjs": "^1.4.7",
"fetch": "^1.1.0", "fetch": "^1.1.0",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"filepond": "^4.2.0", "filepond": "^4.7.1",
"js-file-download": "^0.4.4", "js-file-download": "^0.4.8",
"json-loader": "^0.5.7", "json-loader": "^0.5.7",
"jwt-decode": "^2.2.0", "jwt-decode": "^2.2.0",
"moment": "^2.22.2", "moment": "^2.24.0",
"node-sass": "^4.11.0", "node-sass": "^4.11.0",
"normalize.css": "^8.0.0", "normalize.css": "^8.0.0",
"npm": "^6.4.1", "npm": "^6.11.3",
"prop-types": "^15.6.2", "pluralize": "^7.0.0",
"rc-progress": "^2.2.6", "prop-types": "^15.7.2",
"react": "^16.5.2", "rc-progress": "^2.5.2",
"react": "^16.9.0",
"react-bootstrap": "^0.32.4", "react-bootstrap": "^0.32.4",
"react-copy-to-clipboard": "^5.0.1", "react-copy-to-clipboard": "^5.0.1",
"react-data-components": "^1.2.0", "react-data-components": "^1.2.0",
"react-desktop-notification": "^1.0.9", "react-desktop-notification": "^1.0.9",
"react-dimensions": "^1.3.0", "react-dimensions": "^1.3.0",
"react-dom": "^16.5.2", "react-dom": "^16.9.0",
"react-fa": "^5.0.0", "react-fa": "^5.0.0",
"react-filepond": "^7.0.1", "react-filepond": "^7.0.1",
"react-graph-vis": "^1.0.2", "react-graph-vis": "^1.0.2",
"react-json-tree": "^0.11.0", "react-json-tree": "^0.11.2",
"react-jsonschema-form": "^1.0.5", "react-jsonschema-form": "^1.8.0",
"react-redux": "^5.1.1", "react-redux": "^5.1.1",
"react-router-dom": "^4.3.1", "react-router-dom": "^4.3.1",
"react-spinners": "^0.5.4", "react-spinners": "^0.5.13",
"react-table": "^6.8.6", "react-table": "^6.10.3",
"react-toggle": "^4.0.1", "react-toggle": "^4.0.1",
"react-tooltip-lite": "^1.9.1", "react-tooltip-lite": "^1.10.0",
"redux": "^4.0.0", "redux": "^4.0.4",
"sass-loader": "^7.1.0", "sass-loader": "^7.3.1",
"sha3": "^2.0.0", "sha3": "^2.0.7"
"pluralize": "^7.0.0"
} }
} }