forked from p15670423/monkey
Merge pull request #1970 from guardicore/906-remove-config-arg
Agent: Remove --config argument
This commit is contained in:
commit
6221a43fef
|
@ -73,6 +73,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Island log download button from "Telemetries"(previously called "Logs") page. #1640
|
- Island log download button from "Telemetries"(previously called "Logs") page. #1640
|
||||||
- "/api/client-monkey" endpoint. #1889
|
- "/api/client-monkey" endpoint. #1889
|
||||||
- "+dev" from version numbers. #1553
|
- "+dev" from version numbers. #1553
|
||||||
|
- agent's "--config" argument. #906
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- A bug in network map page that caused delay of telemetry log loading. #1545
|
- A bug in network map page that caused delay of telemetry log loading. #1545
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import uuid
|
import uuid
|
||||||
from abc import ABCMeta
|
from abc import ABCMeta
|
||||||
|
|
||||||
GUID = str(uuid.getnode())
|
GUID = str(uuid.getnode())
|
||||||
|
|
||||||
EXTERNAL_CONFIG_FILE = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "monkey.bin")
|
|
||||||
|
|
||||||
SENSITIVE_FIELDS = [
|
SENSITIVE_FIELDS = [
|
||||||
"exploit_password_list",
|
"exploit_password_list",
|
||||||
"exploit_user_list",
|
"exploit_user_list",
|
||||||
|
|
|
@ -46,8 +46,7 @@ class MonkeyDrops(object):
|
||||||
arg_parser.add_argument("-d", "--depth", type=int)
|
arg_parser.add_argument("-d", "--depth", type=int)
|
||||||
arg_parser.add_argument("-l", "--location")
|
arg_parser.add_argument("-l", "--location")
|
||||||
arg_parser.add_argument("-vp", "--vulnerable-port")
|
arg_parser.add_argument("-vp", "--vulnerable-port")
|
||||||
self.monkey_args = args[1:]
|
self.opts = arg_parser.parse_args(args)
|
||||||
self.opts, _ = arg_parser.parse_known_args(args)
|
|
||||||
|
|
||||||
self._config = {
|
self._config = {
|
||||||
"source_path": os.path.abspath(sys.argv[0]),
|
"source_path": os.path.abspath(sys.argv[0]),
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import os
|
import os
|
||||||
|
@ -12,7 +11,7 @@ from pprint import pformat
|
||||||
# noinspection PyUnresolvedReferences
|
# noinspection PyUnresolvedReferences
|
||||||
import infection_monkey.post_breach # noqa: F401
|
import infection_monkey.post_breach # noqa: F401
|
||||||
from common.version import get_version
|
from common.version import get_version
|
||||||
from infection_monkey.config import EXTERNAL_CONFIG_FILE, WormConfiguration
|
from infection_monkey.config import WormConfiguration
|
||||||
from infection_monkey.dropper import MonkeyDrops
|
from infection_monkey.dropper import MonkeyDrops
|
||||||
from infection_monkey.model import DROPPER_ARG, MONKEY_ARG
|
from infection_monkey.model import DROPPER_ARG, MONKEY_ARG
|
||||||
from infection_monkey.monkey import InfectionMonkey
|
from infection_monkey.monkey import InfectionMonkey
|
||||||
|
@ -45,44 +44,27 @@ LOG_CONFIG = {
|
||||||
def main():
|
def main():
|
||||||
global logger
|
global logger
|
||||||
|
|
||||||
if 2 > len(sys.argv):
|
|
||||||
return True
|
|
||||||
freeze_support() # required for multiprocessing + pyinstaller on windows
|
freeze_support() # required for multiprocessing + pyinstaller on windows
|
||||||
monkey_mode = sys.argv[1]
|
|
||||||
|
|
||||||
if not (monkey_mode in [MONKEY_ARG, DROPPER_ARG]):
|
|
||||||
return True
|
|
||||||
|
|
||||||
config_file = EXTERNAL_CONFIG_FILE
|
|
||||||
|
|
||||||
arg_parser = argparse.ArgumentParser()
|
arg_parser = argparse.ArgumentParser()
|
||||||
arg_parser.add_argument("-c", "--config")
|
arg_parser.add_argument(
|
||||||
opts, monkey_args = arg_parser.parse_known_args(sys.argv[2:])
|
"mode",
|
||||||
if opts.config:
|
choices=[MONKEY_ARG, DROPPER_ARG],
|
||||||
config_file = opts.config
|
help=f"'{MONKEY_ARG}' mode will run the agent in the current session/terminal."
|
||||||
if os.path.isfile(config_file):
|
f"'{DROPPER_ARG}' will detach the agent from the current session "
|
||||||
# using print because config can also change log locations
|
f"and will start it on a separate process.",
|
||||||
print("Loading config from %s." % config_file)
|
)
|
||||||
try:
|
mode_args, mode_specific_args = arg_parser.parse_known_args()
|
||||||
with open(config_file) as config_fo:
|
mode = mode_args.mode
|
||||||
json_dict = json.load(config_fo)
|
|
||||||
WormConfiguration.from_kv(json_dict)
|
|
||||||
except ValueError as e:
|
|
||||||
print("Error loading config: %s, using default" % (e,))
|
|
||||||
else:
|
|
||||||
print(
|
|
||||||
"Config file wasn't supplied and default path: %s wasn't found, using internal "
|
|
||||||
"default" % (config_file,)
|
|
||||||
)
|
|
||||||
|
|
||||||
formatted_config = pformat(WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict()))
|
formatted_config = pformat(WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict()))
|
||||||
print(f"Loaded Configuration:\n{formatted_config}")
|
print(f"Loaded Configuration:\n{formatted_config}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if MONKEY_ARG == monkey_mode:
|
if MONKEY_ARG == mode:
|
||||||
log_path = get_agent_log_path()
|
log_path = get_agent_log_path()
|
||||||
monkey_cls = InfectionMonkey
|
monkey_cls = InfectionMonkey
|
||||||
elif DROPPER_ARG == monkey_mode:
|
elif DROPPER_ARG == mode:
|
||||||
log_path = get_dropper_log_path()
|
log_path = get_dropper_log_path()
|
||||||
monkey_cls = MonkeyDrops
|
monkey_cls = MonkeyDrops
|
||||||
else:
|
else:
|
||||||
|
@ -118,7 +100,7 @@ def main():
|
||||||
logger.info(f"version: {get_version()}")
|
logger.info(f"version: {get_version()}")
|
||||||
logger.info(f"writing log file to {log_path}")
|
logger.info(f"writing log file to {log_path}")
|
||||||
|
|
||||||
monkey = monkey_cls(monkey_args)
|
monkey = monkey_cls(mode_specific_args)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
monkey.start()
|
monkey.start()
|
||||||
|
|
|
@ -102,7 +102,7 @@ class InfectionMonkey:
|
||||||
arg_parser.add_argument("-t", "--tunnel")
|
arg_parser.add_argument("-t", "--tunnel")
|
||||||
arg_parser.add_argument("-s", "--server")
|
arg_parser.add_argument("-s", "--server")
|
||||||
arg_parser.add_argument("-d", "--depth", type=int)
|
arg_parser.add_argument("-d", "--depth", type=int)
|
||||||
opts, _ = arg_parser.parse_known_args(args)
|
opts = arg_parser.parse_args(args)
|
||||||
InfectionMonkey._log_arguments(opts)
|
InfectionMonkey._log_arguments(opts)
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
|
|
Loading…
Reference in New Issue