Now using tempfile to create monkey directory

Instead of predetermined tmp paths.
This commit is contained in:
Shay Nehmad 2019-06-12 17:08:33 +03:00
parent 16306f86bb
commit 922a129f2f
5 changed files with 22 additions and 33 deletions

View File

@ -157,9 +157,8 @@ class Configuration(object):
keep_tunnel_open_time = 60 keep_tunnel_open_time = 60
# Monkey files directories # Monkey files directory name
monkey_dir_linux = '/tmp/monkey_dir' monkey_dir_name = 'monkey_dir'
monkey_dir_windows = r'C:\Windows\Temp\monkey_dir'
########################### ###########################
# scanners config # scanners config

View File

@ -29,9 +29,7 @@
"dropper_target_path_win_64": "C:\\Windows\\temp\\monkey64.exe", "dropper_target_path_win_64": "C:\\Windows\\temp\\monkey64.exe",
"dropper_target_path_linux": "/tmp/monkey", "dropper_target_path_linux": "/tmp/monkey",
monkey_dir_linux = '/tmp/monkey_dir', "monkey_dir_name": "monkey_dir",
monkey_dir_windows = r'C:\Windows\Temp\monkey_dir',
"kill_file_path_linux": "/var/run/monkey.not", "kill_file_path_linux": "/var/run/monkey.not",
"kill_file_path_windows": "%windir%\\monkey.not", "kill_file_path_windows": "%windir%\\monkey.not",

View File

@ -1,15 +1,16 @@
import os
import logging import logging
from time import sleep import os
import pymssql
import textwrap import textwrap
from time import sleep
import pymssql
from infection_monkey.exploit import HostExploiter, tools
from common.utils.exploit_enum import ExploitType from common.utils.exploit_enum import ExploitType
from infection_monkey.exploit import HostExploiter, tools
from infection_monkey.exploit.tools import HTTPTools from infection_monkey.exploit.tools import HTTPTools
from infection_monkey.config import WormConfiguration
from infection_monkey.model import DROPPER_ARG
from infection_monkey.exploit.tools import get_monkey_dest_path from infection_monkey.exploit.tools import get_monkey_dest_path
from infection_monkey.model import DROPPER_ARG
from infection_monkey.utils import get_monkey_dir_path
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -52,10 +53,10 @@ class MSSQLExploiter(HostExploiter):
LOG.info("Started http server on %s", http_path) LOG.info("Started http server on %s", http_path)
dst_path = get_monkey_dest_path(http_path) dst_path = get_monkey_dest_path(http_path)
tmp_file_path = os.path.join(WormConfiguration.monkey_dir_windows, MSSQLExploiter.TMP_FILE_NAME) tmp_file_path = os.path.join(get_monkey_dir_path(), MSSQLExploiter.TMP_FILE_NAME)
# Create monkey dir. # Create monkey dir.
commands = ["xp_cmdshell \"mkdir %s\"" % WormConfiguration.monkey_dir_windows] commands = ["xp_cmdshell \"mkdir %s\"" % get_monkey_dir_path()]
MSSQLExploiter.execute_command(cursor, commands) MSSQLExploiter.execute_command(cursor, commands)
# Form download command in a file # Form download command in a file

View File

@ -1,8 +1,9 @@
import os import os
import sys
import shutil import shutil
import struct import struct
import datetime import sys
import tempfile
from infection_monkey.config import WormConfiguration from infection_monkey.config import WormConfiguration
@ -17,10 +18,9 @@ def get_dropper_log_path():
def is_64bit_windows_os(): def is_64bit_windows_os():
''' """
Checks for 64 bit Windows OS using environment variables. Checks for 64 bit Windows OS using environment variables.
:return: """
'''
return 'PROGRAMFILES(X86)' in os.environ return 'PROGRAMFILES(X86)' in os.environ
@ -54,7 +54,4 @@ def remove_monkey_dir():
def get_monkey_dir_path(): def get_monkey_dir_path():
if is_windows_os(): return os.path.join(tempfile.gettempdir(), WormConfiguration.monkey_dir_name)
return WormConfiguration.monkey_dir_windows
else:
return WormConfiguration.monkey_dir_linux

View File

@ -499,17 +499,11 @@ SCHEMA = {
"default": 60, "default": 60,
"description": "Time to keep tunnel open before going down after last exploit (in seconds)" "description": "Time to keep tunnel open before going down after last exploit (in seconds)"
}, },
"monkey_dir_windows": { "monkey_dir_name": {
"title": "Monkey's windows directory", "title": "Monkey's directory name",
"type": "string", "type": "string",
"default": r"C:\Windows\temp\monkey_dir", "default": r"monkey_dir",
"description": "Directory containing all monkey files on windows" "description": "Directory name for the directory which will contain all of the monkey files"
},
"monkey_dir_linux": {
"title": "Monkey's linux directory",
"type": "string",
"default": "/tmp/monkey_dir",
"description": "Directory containing all monkey files on linux"
}, },
} }
}, },