forked from p34709852/monkey
Agent: Use operating systems consts
This commit is contained in:
parent
1fc0eae480
commit
4c1c8044cd
|
@ -105,10 +105,10 @@ class HadoopExploiter(WebRCE):
|
||||||
def _build_command(self, path, http_path):
|
def _build_command(self, path, http_path):
|
||||||
# Build command to execute
|
# Build command to execute
|
||||||
monkey_cmd = build_monkey_commandline(self.host, self.current_depth + 1)
|
monkey_cmd = build_monkey_commandline(self.host, self.current_depth + 1)
|
||||||
if "linux" in self.host.os["type"]:
|
if self.host.is_windows():
|
||||||
base_command = HADOOP_LINUX_COMMAND
|
|
||||||
else:
|
|
||||||
base_command = HADOOP_WINDOWS_COMMAND
|
base_command = HADOOP_WINDOWS_COMMAND
|
||||||
|
else:
|
||||||
|
base_command = HADOOP_LINUX_COMMAND
|
||||||
|
|
||||||
return base_command % {
|
return base_command % {
|
||||||
"monkey_path": path,
|
"monkey_path": path,
|
||||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
||||||
import time
|
import time
|
||||||
from pathlib import PurePath
|
from pathlib import PurePath
|
||||||
|
|
||||||
|
from common import OperatingSystems
|
||||||
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT
|
from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT
|
||||||
from common.utils import Timer
|
from common.utils import Timer
|
||||||
from infection_monkey.exploit.log4shell_utils import (
|
from infection_monkey.exploit.log4shell_utils import (
|
||||||
|
@ -115,10 +116,10 @@ class Log4ShellExploiter(WebRCE):
|
||||||
def _build_command(self, path: PurePath, http_path) -> str:
|
def _build_command(self, path: PurePath, http_path) -> str:
|
||||||
# Build command to execute
|
# Build command to execute
|
||||||
monkey_cmd = build_monkey_commandline(self.host, self.current_depth + 1, location=path)
|
monkey_cmd = build_monkey_commandline(self.host, self.current_depth + 1, location=path)
|
||||||
if "linux" in self.host.os["type"]:
|
if self.host.is_windows():
|
||||||
base_command = LOG4SHELL_LINUX_COMMAND
|
|
||||||
else:
|
|
||||||
base_command = LOG4SHELL_WINDOWS_COMMAND
|
base_command = LOG4SHELL_WINDOWS_COMMAND
|
||||||
|
else:
|
||||||
|
base_command = LOG4SHELL_LINUX_COMMAND
|
||||||
|
|
||||||
return base_command % {
|
return base_command % {
|
||||||
"monkey_path": path,
|
"monkey_path": path,
|
||||||
|
@ -128,7 +129,7 @@ class Log4ShellExploiter(WebRCE):
|
||||||
}
|
}
|
||||||
|
|
||||||
def _build_java_class(self, exploit_command: str) -> bytes:
|
def _build_java_class(self, exploit_command: str) -> bytes:
|
||||||
if "linux" in self.host.os["type"]:
|
if OperatingSystems.LINUX in self.host.os["type"]:
|
||||||
return build_exploit_bytecode(exploit_command, LINUX_EXPLOIT_TEMPLATE_PATH)
|
return build_exploit_bytecode(exploit_command, LINUX_EXPLOIT_TEMPLATE_PATH)
|
||||||
else:
|
else:
|
||||||
return build_exploit_bytecode(exploit_command, WINDOWS_EXPLOIT_TEMPLATE_PATH)
|
return build_exploit_bytecode(exploit_command, WINDOWS_EXPLOIT_TEMPLATE_PATH)
|
||||||
|
|
|
@ -15,7 +15,7 @@ AGENT_BINARY_PATH_WIN64 = PureWindowsPath(r"C:\Windows\temp\monkey64.exe")
|
||||||
|
|
||||||
|
|
||||||
def get_agent_dst_path(host: VictimHost) -> PurePath:
|
def get_agent_dst_path(host: VictimHost) -> PurePath:
|
||||||
if host.os["type"] == "windows":
|
if host.is_windows():
|
||||||
path = PureWindowsPath(AGENT_BINARY_PATH_WIN64)
|
path = PureWindowsPath(AGENT_BINARY_PATH_WIN64)
|
||||||
else:
|
else:
|
||||||
path = PurePosixPath(AGENT_BINARY_PATH_LINUX)
|
path = PurePosixPath(AGENT_BINARY_PATH_LINUX)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from abc import abstractmethod
|
||||||
from posixpath import join
|
from posixpath import join
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
|
from common import OperatingSystems
|
||||||
from common.utils.attack_utils import BITS_UPLOAD_STRING, ScanStatus
|
from common.utils.attack_utils import BITS_UPLOAD_STRING, ScanStatus
|
||||||
from infection_monkey.exploit.HostExploiter import HostExploiter
|
from infection_monkey.exploit.HostExploiter import HostExploiter
|
||||||
from infection_monkey.exploit.tools.http_tools import HTTPTools
|
from infection_monkey.exploit.tools.http_tools import HTTPTools
|
||||||
|
@ -162,10 +163,10 @@ class WebRCE(HostExploiter):
|
||||||
|
|
||||||
def get_command(self, path, http_path, commands):
|
def get_command(self, path, http_path, commands):
|
||||||
try:
|
try:
|
||||||
if "linux" in self.host.os["type"]:
|
if self.host.is_windows():
|
||||||
command = commands["linux"]
|
|
||||||
else:
|
|
||||||
command = commands["windows"]
|
command = commands["windows"]
|
||||||
|
else:
|
||||||
|
command = commands["linux"]
|
||||||
# Format command
|
# Format command
|
||||||
command = command % {"monkey_path": path, "http_path": http_path}
|
command = command % {"monkey_path": path, "http_path": http_path}
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -326,7 +327,7 @@ class WebRCE(HostExploiter):
|
||||||
:return: response, False if failed and True if permission change is not needed
|
:return: response, False if failed and True if permission change is not needed
|
||||||
"""
|
"""
|
||||||
logger.info("Changing monkey's permissions")
|
logger.info("Changing monkey's permissions")
|
||||||
if "windows" in self.host.os["type"]:
|
if self.host.is_windows():
|
||||||
logger.info("Permission change not required for windows")
|
logger.info("Permission change not required for windows")
|
||||||
return True
|
return True
|
||||||
if not command:
|
if not command:
|
||||||
|
@ -411,13 +412,14 @@ class WebRCE(HostExploiter):
|
||||||
:return: Default monkey's destination path for corresponding host or False if failed.
|
:return: Default monkey's destination path for corresponding host or False if failed.
|
||||||
"""
|
"""
|
||||||
if not self.host.os.get("type") or (
|
if not self.host.os.get("type") or (
|
||||||
self.host.os["type"] != "linux" and self.host.os["type"] != "windows"
|
self.host.os["type"] != OperatingSystems.LINUX
|
||||||
|
and self.host.os["type"] != OperatingSystems.LINUX
|
||||||
):
|
):
|
||||||
logger.error("Target's OS was either unidentified or not supported. Aborting")
|
logger.error("Target's OS was either unidentified or not supported. Aborting")
|
||||||
return False
|
return False
|
||||||
if self.host.os["type"] == "linux":
|
if self.host.os["type"] == OperatingSystems.LINUX:
|
||||||
return DROPPER_TARGET_PATH_LINUX
|
return DROPPER_TARGET_PATH_LINUX
|
||||||
if self.host.os["type"] == "windows":
|
if self.host.os["type"] == OperatingSystems.WINDOWS:
|
||||||
return DROPPER_TARGET_PATH_WIN64
|
return DROPPER_TARGET_PATH_WIN64
|
||||||
|
|
||||||
def get_target_url(self):
|
def get_target_url(self):
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from common import OperatingSystems
|
||||||
|
|
||||||
|
|
||||||
class VictimHost(object):
|
class VictimHost(object):
|
||||||
def __init__(self, ip_addr: str, domain_name: str = ""):
|
def __init__(self, ip_addr: str, domain_name: str = ""):
|
||||||
|
@ -14,6 +16,9 @@ class VictimHost(object):
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return self.__dict__
|
return self.__dict__
|
||||||
|
|
||||||
|
def is_windows(self) -> bool:
|
||||||
|
return OperatingSystems.WINDOWS in self.os["type"]
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(self.ip_addr)
|
return hash(self.ip_addr)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from common import OperatingSystems
|
||||||
from infection_monkey.i_puppet import PingScanData
|
from infection_monkey.i_puppet import PingScanData
|
||||||
from infection_monkey.utils.environment import is_windows_os
|
from infection_monkey.utils.environment import is_windows_os
|
||||||
|
|
||||||
|
@ -79,9 +80,9 @@ def _process_ping_command_output(ping_command_output: str) -> PingScanData:
|
||||||
|
|
||||||
operating_system = None
|
operating_system = None
|
||||||
if ttl <= LINUX_TTL:
|
if ttl <= LINUX_TTL:
|
||||||
operating_system = "linux"
|
operating_system = OperatingSystems.LINUX
|
||||||
else: # as far we we know, could also be OSX/BSD, but lets handle that when it comes up.
|
else: # as far we we know, could also be OSX/BSD, but lets handle that when it comes up.
|
||||||
operating_system = "windows"
|
operating_system = OperatingSystems.WINDOWS
|
||||||
|
|
||||||
return PingScanData(True, operating_system)
|
return PingScanData(True, operating_system)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ from typing import Dict
|
||||||
|
|
||||||
from odict import odict
|
from odict import odict
|
||||||
|
|
||||||
|
from common import OperatingSystems
|
||||||
from infection_monkey.i_puppet import (
|
from infection_monkey.i_puppet import (
|
||||||
FingerprintData,
|
FingerprintData,
|
||||||
IFingerprinter,
|
IFingerprinter,
|
||||||
|
@ -193,9 +194,9 @@ class SMBFingerprinter(IFingerprinter):
|
||||||
logger.debug(f'os_version: "{os_version}", service_client: "{service_client}"')
|
logger.debug(f'os_version: "{os_version}", service_client: "{service_client}"')
|
||||||
|
|
||||||
if os_version.lower() != "unix":
|
if os_version.lower() != "unix":
|
||||||
os_type = "windows"
|
os_type = OperatingSystems.WINDOWS
|
||||||
else:
|
else:
|
||||||
os_type = "linux"
|
os_type = OperatingSystems.LINUX
|
||||||
|
|
||||||
smb_service["name"] = service_client
|
smb_service["name"] = service_client
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import re
|
import re
|
||||||
from typing import Dict, Optional, Tuple
|
from typing import Dict, Optional, Tuple
|
||||||
|
|
||||||
|
from common import OperatingSystems
|
||||||
from infection_monkey.i_puppet import FingerprintData, IFingerprinter, PingScanData, PortScanData
|
from infection_monkey.i_puppet import FingerprintData, IFingerprinter, PingScanData, PortScanData
|
||||||
|
|
||||||
SSH_REGEX = r"SSH-\d\.\d-OpenSSH"
|
SSH_REGEX = r"SSH-\d\.\d-OpenSSH"
|
||||||
|
@ -40,6 +41,6 @@ class SSHFingerprinter(IFingerprinter):
|
||||||
for dist in LINUX_DIST_SSH:
|
for dist in LINUX_DIST_SSH:
|
||||||
if banner.lower().find(dist) != -1:
|
if banner.lower().find(dist) != -1:
|
||||||
os_version = banner.split(" ").pop().strip()
|
os_version = banner.split(" ").pop().strip()
|
||||||
os = "linux"
|
os = OperatingSystems.LINUX
|
||||||
|
|
||||||
return os, os_version
|
return os, os_version
|
||||||
|
|
Loading…
Reference in New Issue