Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3 logging improvements #475

Merged
merged 2 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
30 changes: 17 additions & 13 deletions monkey/monkey_island/cc/ui/src/components/pages/MapPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,30 @@ class MapPageComponent extends AuthComponent {
this.authFetch('/api/netmap')
.then(res => res.json())
.then(res => {
res.edges.forEach(edge => {
edge.color = {'color': edgeGroupToColor(edge.group)};
});
this.setState({graph: res});
this.props.onStatusChange();
if (res.hasOwnProperty("edges")) {
res.edges.forEach(edge => {
edge.color = {'color': edgeGroupToColor(edge.group)};
});
this.setState({graph: res});
this.props.onStatusChange();
}
});
};

updateTelemetryFromServer = () => {
this.authFetch('/api/telemetry-feed?timestamp='+this.state.telemetryLastTimestamp)
.then(res => res.json())
.then(res => {
let newTelem = this.state.telemetry.concat(res['telemetries']);

this.setState(
{
telemetry: newTelem,
telemetryLastTimestamp: res['timestamp']
});
this.props.onStatusChange();
if ('telemetries' in res) {
let newTelem = this.state.telemetry.concat(res['telemetries']);

this.setState(
{
telemetry: newTelem,
telemetryLastTimestamp: res['timestamp']
});
this.props.onStatusChange();
}
});
};

Expand Down