PEP8 changes

This commit is contained in:
acepace 2016-08-20 17:58:59 +03:00
parent 14052bb444
commit 8c4288d100
12 changed files with 106 additions and 93 deletions

View File

@ -19,7 +19,8 @@ LOG = None
LOG_CONFIG = {'version': 1, LOG_CONFIG = {'version': 1,
'disable_existing_loggers': False, 'disable_existing_loggers': False,
'formatters': {'standard': {'format': '%(asctime)s [%(process)d:%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s'}, 'formatters': {'standard': {
'format': '%(asctime)s [%(process)d:%(levelname)s] %(module)s.%(funcName)s.%(lineno)d: %(message)s'},
}, },
'handlers': {'console': {'class': 'logging.StreamHandler', 'handlers': {'console': {'class': 'logging.StreamHandler',
'level': 'DEBUG', 'level': 'DEBUG',
@ -42,7 +43,7 @@ def main():
monkey_mode = sys.argv[1] monkey_mode = sys.argv[1]
if not monkey_mode in [MONKEY_ARG, DROPPER_ARG]: if not (monkey_mode in [MONKEY_ARG, DROPPER_ARG]):
return True return True
config_file = EXTERNAL_CONFIG_FILE config_file = EXTERNAL_CONFIG_FILE
@ -74,10 +75,12 @@ def main():
try: try:
if MONKEY_ARG == monkey_mode: if MONKEY_ARG == monkey_mode:
log_path = os.path.expandvars(WormConfiguration.monkey_log_path_windows) if sys.platform == "win32" else WormConfiguration.monkey_log_path_linux log_path = os.path.expandvars(
WormConfiguration.monkey_log_path_windows) if sys.platform == "win32" else WormConfiguration.monkey_log_path_linux
monkey_cls = ChaosMonkey monkey_cls = ChaosMonkey
elif DROPPER_ARG == monkey_mode: elif DROPPER_ARG == monkey_mode:
log_path = os.path.expandvars(WormConfiguration.dropper_log_path_windows) if sys.platform == "win32" else WormConfiguration.dropper_log_path_linux log_path = os.path.expandvars(
WormConfiguration.dropper_log_path_windows) if sys.platform == "win32" else WormConfiguration.dropper_log_path_linux
monkey_cls = MonkeyDrops monkey_cls = MonkeyDrops
else: else:
return True return True
@ -117,6 +120,7 @@ def main():
finally: finally:
monkey.cleanup() monkey.cleanup()
if "__main__" == __name__: if "__main__" == __name__:
if not main(): if not main():
sys.exit(1) sys.exit(1)

View File

@ -143,7 +143,6 @@ class ChaosMonkey(object):
LOG.debug("Skipping %r - exploitation failed before", machine) LOG.debug("Skipping %r - exploitation failed before", machine)
continue continue
successful_exploiter = None
if monkey_tunnel: if monkey_tunnel:
monkey_tunnel.set_tunnel_for_host(machine) monkey_tunnel.set_tunnel_for_host(machine)
@ -151,6 +150,7 @@ class ChaosMonkey(object):
LOG.debug("Default server: %s set to machine: %r" % (self._default_server, machine)) LOG.debug("Default server: %s set to machine: %r" % (self._default_server, machine))
machine.set_default_server(self._default_server) machine.set_default_server(self._default_server)
successful_exploiter = None
for exploiter in self._exploiters: for exploiter in self._exploiters:
if not exploiter.is_os_supported(machine): if not exploiter.is_os_supported(machine):
LOG.info("Skipping exploiter %s host:%r, os is not supported", LOG.info("Skipping exploiter %s host:%r, os is not supported",

View File

@ -70,7 +70,7 @@ class WinAdvFirewall(FirewallApp):
try: try:
if _run_netsh_cmd('advfirewall firewall delete rule', netsh_args): if _run_netsh_cmd('advfirewall firewall delete rule', netsh_args):
if self._rules.has_key(name): if name in self._rules:
del self._rules[name] del self._rules[name]
return True return True
else: else:
@ -117,7 +117,8 @@ class WinFirewall(FirewallApp):
except: except:
return None return None
def add_firewall_rule(self, rule='allowedprogram', name="Firewall", mode="ENABLE", program=sys.executable, **kwargs): def add_firewall_rule(self, rule='allowedprogram', name="Firewall", mode="ENABLE", program=sys.executable,
**kwargs):
netsh_args = {'name': name, netsh_args = {'name': name,
'mode': mode, 'mode': mode,
'program': program} 'program': program}
@ -133,12 +134,13 @@ class WinFirewall(FirewallApp):
except: except:
return None return None
def remove_firewall_rule(self, rule='allowedprogram', name="Firewall", mode="ENABLE", program=sys.executable, **kwargs): def remove_firewall_rule(self, rule='allowedprogram', name="Firewall", mode="ENABLE", program=sys.executable,
**kwargs):
netsh_args = {'program': program} netsh_args = {'program': program}
netsh_args.update(kwargs) netsh_args.update(kwargs)
try: try:
if _run_netsh_cmd('firewall delete %s' % rule, netsh_args): if _run_netsh_cmd('firewall delete %s' % rule, netsh_args):
if self._rules.has_key(name): if name in self._rules:
del self._rules[name] del self._rules[name]
return True return True
else: else:
@ -162,6 +164,7 @@ class WinFirewall(FirewallApp):
except: except:
pass pass
if sys.platform == "win32": if sys.platform == "win32":
try: try:
win_ver = int(platform.version().split('.')[0]) win_ver = int(platform.version().split('.')[0])

View File

@ -10,10 +10,12 @@ from random import randint
if sys.platform == "win32": if sys.platform == "win32":
import netifaces import netifaces
def local_ips(): def local_ips():
local_hostname = socket.gethostname() local_hostname = socket.gethostname()
return socket.gethostbyname_ex(local_hostname)[2] return socket.gethostbyname_ex(local_hostname)[2]
def get_host_subnets(only_ips=False): def get_host_subnets(only_ips=False):
network_adapters = [] network_adapters = []
valid_ips = local_ips() valid_ips = local_ips()
@ -30,9 +32,9 @@ if sys.platform == "win32":
else: else:
import fcntl import fcntl
def get_host_subnets(only_ips=False): def get_host_subnets(only_ips=False):
"""Get the list of Linux network adapters.""" """Get the list of Linux network adapters."""
import fcntl
max_bytes = 8096 max_bytes = 8096
is_64bits = sys.maxsize > 2 ** 32 is_64bits = sys.maxsize > 2 ** 32
if is_64bits: if is_64bits:

View File

@ -41,9 +41,9 @@ class NetworkScanner(object):
scanner = scan_type() scanner = scan_type()
victims_count = 0 victims_count = 0
for range in self._ranges: for net_range in self._ranges:
LOG.debug("Scanning for potential victims in the network %r", range) LOG.debug("Scanning for potential victims in the network %r", net_range)
for victim in range: for victim in net_range:
if stop_callback and stop_callback(): if stop_callback and stop_callback():
LOG.debug("Got stop signal") LOG.debug("Got stop signal")
break break

View File

@ -64,7 +64,8 @@ class SMBNegoFingerData(Packet):
("separator2", "\x02"), ("separator2", "\x02"),
("dialect2", "\x4c\x41\x4e\x4d\x41\x4e\x31\x2e\x30\x00"), ("dialect2", "\x4c\x41\x4e\x4d\x41\x4e\x31\x2e\x30\x00"),
("separator3", "\x02"), ("separator3", "\x02"),
("dialect3", "\x57\x69\x6e\x64\x6f\x77\x73\x20\x66\x6f\x72\x20\x57\x6f\x72\x6b\x67\x72\x6f\x75\x70\x73\x20\x33\x2e\x31\x61\x00"), ("dialect3",
"\x57\x69\x6e\x64\x6f\x77\x73\x20\x66\x6f\x72\x20\x57\x6f\x72\x6b\x67\x72\x6f\x75\x70\x73\x20\x33\x2e\x31\x61\x00"),
("separator4", "\x02"), ("separator4", "\x02"),
("dialect4", "\x4c\x4d\x31\x2e\x32\x58\x30\x30\x32\x00"), ("dialect4", "\x4c\x4d\x31\x2e\x32\x58\x30\x30\x32\x00"),
("separator5", "\x02"), ("separator5", "\x02"),
@ -88,7 +89,8 @@ class SMBSessionFingerData(Packet):
("reserved2", "\x00\x00\x00\x00"), ("reserved2", "\x00\x00\x00\x00"),
("capabilities", "\xd4\x00\x00\xa0"), ("capabilities", "\xd4\x00\x00\xa0"),
("bcc1", ""), ("bcc1", ""),
("Data","\x60\x48\x06\x06\x2b\x06\x01\x05\x05\x02\xa0\x3e\x30\x3c\xa0\x0e\x30\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x2a\x04\x28\x4e\x54\x4c\x4d\x53\x53\x50\x00\x01\x00\x00\x00\x07\x82\x08\xa2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x01\x28\x0a\x00\x00\x00\x0f\x00\x57\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32\x00\x30\x00\x30\x00\x32\x00\x20\x00\x53\x00\x65\x00\x72\x00\x76\x00\x69\x00\x63\x00\x65\x00\x20\x00\x50\x00\x61\x00\x63\x00\x6b\x00\x20\x00\x33\x00\x20\x00\x32\x00\x36\x00\x30\x00\x30\x00\x00\x00\x57\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32\x00\x30\x00\x30\x00\x32\x00\x20\x00\x35\x00\x2e\x00\x31\x00\x00\x00\x00\x00"), ("Data",
"\x60\x48\x06\x06\x2b\x06\x01\x05\x05\x02\xa0\x3e\x30\x3c\xa0\x0e\x30\x0c\x06\x0a\x2b\x06\x01\x04\x01\x82\x37\x02\x02\x0a\xa2\x2a\x04\x28\x4e\x54\x4c\x4d\x53\x53\x50\x00\x01\x00\x00\x00\x07\x82\x08\xa2\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x01\x28\x0a\x00\x00\x00\x0f\x00\x57\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32\x00\x30\x00\x30\x00\x32\x00\x20\x00\x53\x00\x65\x00\x72\x00\x76\x00\x69\x00\x63\x00\x65\x00\x20\x00\x50\x00\x61\x00\x63\x00\x6b\x00\x20\x00\x33\x00\x20\x00\x32\x00\x36\x00\x30\x00\x30\x00\x00\x00\x57\x00\x69\x00\x6e\x00\x64\x00\x6f\x00\x77\x00\x73\x00\x20\x00\x32\x00\x30\x00\x30\x00\x32\x00\x20\x00\x35\x00\x2e\x00\x31\x00\x00\x00\x00\x00"),
]) ])
@ -133,7 +135,8 @@ class SMBFinger(HostFinger):
if data[8:10] == "\x73\x16": if data[8:10] == "\x73\x16":
length = struct.unpack('<H', data[43:45])[0] length = struct.unpack('<H', data[43:45])[0]
pack = tuple(data[47 + length:].split('\x00\x00\x00'))[:2] pack = tuple(data[47 + length:].split('\x00\x00\x00'))[:2]
os_version, service_client = tuple([e.replace('\x00','') for e in data[47+length:].split('\x00\x00\x00')[:2]]) os_version, service_client = tuple(
[e.replace('\x00', '') for e in data[47 + length:].split('\x00\x00\x00')[:2]])
if os_version.lower() != 'unix': if os_version.lower() != 'unix':
host.os['type'] = 'windows' host.os['type'] = 'windows'

View File

@ -16,7 +16,8 @@ class SSHFinger(HostFinger):
self._config = __import__('config').WormConfiguration self._config = __import__('config').WormConfiguration
self._banner_regex = re.compile(SSH_REGEX, re.IGNORECASE) self._banner_regex = re.compile(SSH_REGEX, re.IGNORECASE)
def _banner_match(self, service, host, banner): @staticmethod
def _banner_match(service, host, banner):
host.services[service]['name'] = 'ssh' host.services[service]['name'] = 'ssh'
for dist in LINUX_DIST_SSH: for dist in LINUX_DIST_SSH:
if banner.lower().find(dist) != -1: if banner.lower().find(dist) != -1:

View File

@ -40,6 +40,7 @@ class InfoCollector(object):
""" """
Generic Info Collection module Generic Info Collection module
""" """
def __init__(self): def __init__(self):
self.info = {} self.info = {}

View File

@ -15,4 +15,3 @@ class LinuxInfoCollector(InfoCollector):
self.get_hostname() self.get_hostname()
self.get_process_list() self.get_process_list()
return self.info return self.info