Skip to content

Commit

Permalink
Merge pull request #349 from guardicore/bugfix/348-monkey-dir
Browse files Browse the repository at this point in the history
[CR] Use tempfile to create monkey directory
  • Loading branch information
danielguardicore committed Jun 12, 2019
2 parents 4d184d5 + 922a129 commit 302d4af
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
5 changes: 2 additions & 3 deletions monkey/infection_monkey/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ def as_dict(self):

keep_tunnel_open_time = 60

# Monkey files directories
monkey_dir_linux = '/tmp/monkey_dir'
monkey_dir_windows = r'C:\Windows\Temp\monkey_dir'
# Monkey files directory name
monkey_dir_name = 'monkey_dir'

###########################
# scanners config
Expand Down
4 changes: 1 addition & 3 deletions monkey/infection_monkey/example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
"dropper_target_path_win_64": "C:\\Windows\\temp\\monkey64.exe",
"dropper_target_path_linux": "/tmp/monkey",

monkey_dir_linux = '/tmp/monkey_dir',
monkey_dir_windows = r'C:\Windows\Temp\monkey_dir',

"monkey_dir_name": "monkey_dir",

"kill_file_path_linux": "/var/run/monkey.not",
"kill_file_path_windows": "%windir%\\monkey.not",
Expand Down
15 changes: 8 additions & 7 deletions monkey/infection_monkey/exploit/mssqlexec.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import os
import logging
import os
import textwrap
from time import sleep

import pymssql
import textwrap

from infection_monkey.exploit import HostExploiter, tools
from common.utils.exploit_enum import ExploitType
from infection_monkey.exploit import HostExploiter, tools
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.model import DROPPER_ARG
from infection_monkey.utils import get_monkey_dir_path

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -52,10 +53,10 @@ def exploit_host(self):
LOG.info("Started http server on %s", 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.
commands = ["xp_cmdshell \"mkdir %s\"" % WormConfiguration.monkey_dir_windows]
commands = ["xp_cmdshell \"mkdir %s\"" % get_monkey_dir_path()]
MSSQLExploiter.execute_command(cursor, commands)

# Form download command in a file
Expand Down
15 changes: 6 additions & 9 deletions monkey/infection_monkey/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import sys
import shutil
import struct
import datetime
import sys
import tempfile

from infection_monkey.config import WormConfiguration


Expand All @@ -17,10 +18,9 @@ def get_dropper_log_path():


def is_64bit_windows_os():
'''
"""
Checks for 64 bit Windows OS using environment variables.
:return:
'''
"""
return 'PROGRAMFILES(X86)' in os.environ


Expand Down Expand Up @@ -54,7 +54,4 @@ def remove_monkey_dir():


def get_monkey_dir_path():
if is_windows_os():
return WormConfiguration.monkey_dir_windows
else:
return WormConfiguration.monkey_dir_linux
return os.path.join(tempfile.gettempdir(), WormConfiguration.monkey_dir_name)
14 changes: 4 additions & 10 deletions monkey/monkey_island/cc/services/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,11 @@
"default": 60,
"description": "Time to keep tunnel open before going down after last exploit (in seconds)"
},
"monkey_dir_windows": {
"title": "Monkey's windows directory",
"monkey_dir_name": {
"title": "Monkey's directory name",
"type": "string",
"default": r"C:\Windows\temp\monkey_dir",
"description": "Directory containing all monkey files on windows"
},
"monkey_dir_linux": {
"title": "Monkey's linux directory",
"type": "string",
"default": "/tmp/monkey_dir",
"description": "Directory containing all monkey files on linux"
"default": r"monkey_dir",
"description": "Directory name for the directory which will contain all of the monkey files"
},
}
},
Expand Down

0 comments on commit 302d4af

Please sign in to comment.