Skip to content

Commit

Permalink
Merge pull request #475 from VakarisZ/py3_logging_improvements
Browse files Browse the repository at this point in the history
Py3 logging improvements
  • Loading branch information
VakarisZ authored Nov 4, 2019
2 parents 1f5acbc + e5715f5 commit 7de03d8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion envs/monkey_zoo/blackbox/tests/basic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(self, name, island_client, config_parser, analyzers, timeout, log_h
self.log_handler = log_handler

def run(self):
LOGGER.info("Uploading configuration:\n{}".format(json.dumps(self.config_parser.config_json, indent=2)))
self.island_client.import_config(self.config_parser.config_raw)
self.print_test_starting_info()
try:
Expand Down
6 changes: 4 additions & 2 deletions monkey/infection_monkey/exploit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ def report_login_attempt(self, result, user, password='', lm_hash='', ntlm_hash=

def exploit_host(self):
self.pre_exploit()
result = self._exploit_host()
self.post_exploit()
try:
result = self._exploit_host()
finally:
self.post_exploit()
return result

def pre_exploit(self):
Expand Down
4 changes: 2 additions & 2 deletions monkey/infection_monkey/exploit/mssqlexec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from infection_monkey.exploit.tools.helpers import get_monkey_dest_path, build_monkey_commandline, get_monkey_depth
from infection_monkey.model import DROPPER_ARG
from infection_monkey.exploit.tools.payload_parsing import LimitedSizePayload
from infection_monkey.exploit.tools.exceptions import ExploitingVulnerableMachineError
from infection_monkey.exploit.tools.exceptions import ExploitingVulnerableMachineError, FailedExploitationError

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -185,7 +185,7 @@ def brute_force(self, host, port, users_passwords_pairs_list):

LOG.warning('No user/password combo was able to connect to host: {0}:{1}, '
'aborting brute force'.format(host, port))
raise RuntimeError("Bruteforce process failed on host: {0}".format(self.host.ip_addr))
raise FailedExploitationError("Bruteforce process failed on host: {0}".format(self.host.ip_addr))


class MSSQLLimitedSizePayload(LimitedSizePayload):
Expand Down
6 changes: 5 additions & 1 deletion monkey/infection_monkey/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from infection_monkey.windows_upgrader import WindowsUpgrader
from infection_monkey.post_breach.post_breach_handler import PostBreach
from infection_monkey.exploit.tools.helpers import get_interface_to_target
from infection_monkey.exploit.tools.exceptions import ExploitingVulnerableMachineError
from infection_monkey.exploit.tools.exceptions import ExploitingVulnerableMachineError, FailedExploitationError
from infection_monkey.telemetry.attack.t1106_telem import T1106Telem
from common.utils.attack_utils import ScanStatus, UsageEnum

Expand Down Expand Up @@ -192,7 +192,9 @@ def start(self):
self._exploiters = sorted(self._exploiters, key=lambda exploiter_: exploiter_.EXPLOIT_TYPE.value)
host_exploited = False
for exploiter in [exploiter(machine) for exploiter in self._exploiters]:

if self.try_exploiting(machine, exploiter):

host_exploited = True
VictimHostTelem('T1210', ScanStatus.USED, machine=machine).send()
break
Expand Down Expand Up @@ -311,6 +313,8 @@ def try_exploiting(self, machine, exploiter):
machine, exploiter.__class__.__name__, exc)
self.successfully_exploited(machine, exploiter)
return True
except FailedExploitationError as e:
LOG.info("Failed exploiting %r with exploiter %s, %s", machine, exploiter.__class__.__name__, e)
except Exception as exc:
LOG.exception("Exception while attacking %s using %s: %s",
machine, exploiter.__class__.__name__, exc)
Expand Down

0 comments on commit 7de03d8

Please sign in to comment.