forked from p15670423/monkey
Agent: Remove Windows 32-bit to 64-bit upgrade feature
This commit is contained in:
parent
d84e35f637
commit
8c304e809d
|
@ -46,7 +46,6 @@ from infection_monkey.utils.environment import is_windows_os
|
|||
from infection_monkey.utils.monkey_dir import get_monkey_dir_path, remove_monkey_dir
|
||||
from infection_monkey.utils.monkey_log_path import get_monkey_log_path
|
||||
from infection_monkey.utils.signal_handler import register_signal_handlers, reset_signal_handlers
|
||||
from infection_monkey.windows_upgrader import WindowsUpgrader
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -101,11 +100,6 @@ class InfectionMonkey:
|
|||
logger.info("The Monkey Island has instructed this agent to stop")
|
||||
return
|
||||
|
||||
if InfectionMonkey._is_upgrade_to_64_needed():
|
||||
self._upgrade_to_64()
|
||||
logger.info("32 bit Agent can't run on 64 bit system.")
|
||||
return
|
||||
|
||||
self._setup()
|
||||
self._master.start()
|
||||
|
||||
|
@ -147,16 +141,6 @@ class InfectionMonkey:
|
|||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _is_upgrade_to_64_needed():
|
||||
return WindowsUpgrader.should_upgrade()
|
||||
|
||||
def _upgrade_to_64(self):
|
||||
self._singleton.unlock()
|
||||
logger.info("32bit monkey running on 64bit Windows. Upgrading.")
|
||||
WindowsUpgrader.upgrade(self._opts)
|
||||
logger.info("Finished upgrading from 32bit to 64bit.")
|
||||
|
||||
def _setup(self):
|
||||
logger.debug("Starting the setup phase.")
|
||||
|
||||
|
@ -252,10 +236,6 @@ class InfectionMonkey:
|
|||
logger.info("Monkey cleanup started")
|
||||
self._wait_for_exploited_machine_connection()
|
||||
try:
|
||||
if self._is_upgrade_to_64_needed():
|
||||
logger.debug("Cleanup not needed for 32 bit agent on 64 bit system(it didn't run)")
|
||||
return
|
||||
|
||||
if self._master:
|
||||
self._master.cleanup()
|
||||
|
||||
|
|
|
@ -1,18 +1,5 @@
|
|||
import os
|
||||
import struct
|
||||
import sys
|
||||
|
||||
|
||||
def is_64bit_windows_os():
|
||||
"""
|
||||
Checks for 64 bit Windows OS using environment variables.
|
||||
"""
|
||||
return "PROGRAMFILES(X86)" in os.environ
|
||||
|
||||
|
||||
def is_64bit_python():
|
||||
return struct.calcsize("P") == 8
|
||||
|
||||
|
||||
def is_windows_os():
|
||||
return sys.platform.startswith("win")
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import infection_monkey.monkeyfs as monkeyfs
|
||||
from infection_monkey.config import WormConfiguration
|
||||
from infection_monkey.control import ControlClient
|
||||
from infection_monkey.utils.commands import (
|
||||
build_monkey_commandline_explicitly,
|
||||
get_monkey_commandline_windows,
|
||||
)
|
||||
from infection_monkey.utils.environment import is_64bit_python, is_64bit_windows_os, is_windows_os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if "win32" == sys.platform:
|
||||
from win32process import DETACHED_PROCESS
|
||||
else:
|
||||
DETACHED_PROCESS = 0
|
||||
|
||||
|
||||
class WindowsUpgrader(object):
|
||||
__UPGRADE_WAIT_TIME__ = 3
|
||||
|
||||
@staticmethod
|
||||
def should_upgrade():
|
||||
return is_windows_os() and is_64bit_windows_os() and not is_64bit_python()
|
||||
|
||||
@staticmethod
|
||||
def upgrade(opts):
|
||||
try:
|
||||
monkey_64_path = ControlClient.download_monkey_exe_by_os(True, False)
|
||||
with monkeyfs.open(monkey_64_path, "rb") as downloaded_monkey_file:
|
||||
with open(
|
||||
WormConfiguration.dropper_target_path_win_64, "wb"
|
||||
) as written_monkey_file:
|
||||
shutil.copyfileobj(downloaded_monkey_file, written_monkey_file)
|
||||
except (IOError, AttributeError) as e:
|
||||
logger.error("Failed to download the Monkey to the target path: %s." % e)
|
||||
return
|
||||
|
||||
monkey_options = build_monkey_commandline_explicitly(
|
||||
opts.parent, opts.tunnel, opts.server, opts.depth
|
||||
)
|
||||
|
||||
monkey_cmdline = get_monkey_commandline_windows(
|
||||
WormConfiguration.dropper_target_path_win_64, monkey_options
|
||||
)
|
||||
|
||||
monkey_process = subprocess.Popen(
|
||||
monkey_cmdline,
|
||||
stdin=None,
|
||||
stdout=None,
|
||||
stderr=None,
|
||||
close_fds=True,
|
||||
creationflags=DETACHED_PROCESS,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Executed 64bit monkey process (PID=%d) with command line: %s",
|
||||
monkey_process.pid,
|
||||
" ".join(monkey_cmdline),
|
||||
)
|
||||
|
||||
time.sleep(WindowsUpgrader.__UPGRADE_WAIT_TIME__)
|
||||
if monkey_process.poll() is not None:
|
||||
logger.error("Seems like monkey died too soon")
|
Loading…
Reference in New Issue