forked from p15670423/monkey
configuration print and meaningless spaces fixes
This commit is contained in:
parent
7466cdccfb
commit
3081ac6d91
|
@ -14,6 +14,7 @@ GUID = str(uuid.getnode())
|
||||||
|
|
||||||
EXTERNAL_CONFIG_FILE = os.path.join(os.path.dirname(sys.argv[0]), 'monkey.bin')
|
EXTERNAL_CONFIG_FILE = os.path.join(os.path.dirname(sys.argv[0]), 'monkey.bin')
|
||||||
|
|
||||||
|
|
||||||
def _cast_by_example(value, example):
|
def _cast_by_example(value, example):
|
||||||
example_type = type(example)
|
example_type = type(example)
|
||||||
if example_type is str:
|
if example_type is str:
|
||||||
|
@ -35,17 +36,18 @@ def _cast_by_example(value, example):
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Configuration(object):
|
class Configuration(object):
|
||||||
|
|
||||||
def from_dict(self, data):
|
def from_dict(self, data):
|
||||||
for key,value in data.items():
|
for key, value in data.items():
|
||||||
if key.startswith('_'):
|
if key.startswith('_'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
default_value = getattr(Configuration, key)
|
default_value = getattr(Configuration, key)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
raise
|
||||||
|
|
||||||
setattr(self, key, _cast_by_example(value, default_value))
|
setattr(self, key, _cast_by_example(value, default_value))
|
||||||
|
|
||||||
|
@ -79,7 +81,7 @@ class Configuration(object):
|
||||||
###########################
|
###########################
|
||||||
|
|
||||||
use_file_logging = True
|
use_file_logging = True
|
||||||
dropper_log_path = os.path.expandvars("%temp%\~df1562.tmp") if sys.platform == "win32" else '/tmp/user-1562'
|
dropper_log_path = os.path.expandvars("%temp%\~df1562.tmp") if sys.platform == "win32" else '/tmp/user-1562'
|
||||||
monkey_log_path = os.path.expandvars("%temp%\~df1563.tmp") if sys.platform == "win32" else '/tmp/user-1563'
|
monkey_log_path = os.path.expandvars("%temp%\~df1563.tmp") if sys.platform == "win32" else '/tmp/user-1563'
|
||||||
|
|
||||||
###########################
|
###########################
|
||||||
|
@ -98,7 +100,7 @@ class Configuration(object):
|
||||||
|
|
||||||
alive = True
|
alive = True
|
||||||
|
|
||||||
self_delete_in_cleanup = True
|
self_delete_in_cleanup = False
|
||||||
|
|
||||||
singleton_mutex_name = "{2384ec59-0df8-4ab9-918c-843740924a28}"
|
singleton_mutex_name = "{2384ec59-0df8-4ab9-918c-843740924a28}"
|
||||||
|
|
||||||
|
@ -134,7 +136,7 @@ class Configuration(object):
|
||||||
#range_class = RelativeRange
|
#range_class = RelativeRange
|
||||||
range_size = 8
|
range_size = 8
|
||||||
range_class = FixedRange
|
range_class = FixedRange
|
||||||
range_fixed = ("10.0.0.9", "10.0.0.13", "192.168.1.100", "192.168.1.95", "50.50.50.56", "50.50.50.4")
|
range_fixed = ("10.0.1.39", )
|
||||||
|
|
||||||
# TCP Scanner
|
# TCP Scanner
|
||||||
tcp_target_ports = [22, 2222, 445, 135, 3389]
|
tcp_target_ports = [22, 2222, 445, 135, 3389]
|
||||||
|
@ -157,7 +159,7 @@ class Configuration(object):
|
||||||
|
|
||||||
# psexec exploiter
|
# psexec exploiter
|
||||||
psexec_user = "Administrator"
|
psexec_user = "Administrator"
|
||||||
psexec_passwords = ["Password1!", "1234", "password", "password", "12345678"]
|
psexec_passwords = ["Password1!", "1234", "password", "12345678"]
|
||||||
|
|
||||||
#ssh exploiter
|
#ssh exploiter
|
||||||
ssh_user = "root"
|
ssh_user = "root"
|
||||||
|
@ -166,4 +168,4 @@ class Configuration(object):
|
||||||
#rdp exploiter
|
#rdp exploiter
|
||||||
rdp_use_vbs_download = True
|
rdp_use_vbs_download = True
|
||||||
|
|
||||||
WormConfiguration = Configuration()
|
WormConfiguration = Configuration()
|
||||||
|
|
|
@ -23,6 +23,7 @@ LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
MOVEFILE_DELAY_UNTIL_REBOOT = 4
|
MOVEFILE_DELAY_UNTIL_REBOOT = 4
|
||||||
|
|
||||||
|
|
||||||
class MonkeyDrops(object):
|
class MonkeyDrops(object):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
if args:
|
if args:
|
||||||
|
|
|
@ -30,6 +30,7 @@ LOG_CONFIG = {'version': 1,
|
||||||
'handlers': ['console']},
|
'handlers': ['console']},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global LOG
|
global LOG
|
||||||
|
|
||||||
|
@ -39,7 +40,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
|
||||||
|
|
||||||
|
@ -47,17 +48,18 @@ def main():
|
||||||
arg_parser.add_argument('-c', '--config')
|
arg_parser.add_argument('-c', '--config')
|
||||||
opts, monkey_args = arg_parser.parse_known_args(sys.argv[2:])
|
opts, monkey_args = arg_parser.parse_known_args(sys.argv[2:])
|
||||||
if opts.config:
|
if opts.config:
|
||||||
config_file = opts.config
|
config_file = opts.config
|
||||||
|
print "Config file is: %s" % config_file
|
||||||
if os.path.isfile(config_file):
|
if os.path.isfile(config_file):
|
||||||
# using print because config can also change log locations
|
# using print because config can also change log locations
|
||||||
print "Loading config from %s." % config_file
|
print "Loading config from %s." % config_file
|
||||||
try:
|
try:
|
||||||
with open(config_file) as config_fo:
|
with open(config_file) as config_fo:
|
||||||
json_dict = json.load(config_fo)
|
json_dict = json.load(config_fo)
|
||||||
WormConfiguration.from_dict(json_dict)
|
WormConfiguration.from_dict(json_dict)
|
||||||
except ValueError:
|
print "Configuration loaded: %r" % WormConfiguration.as_dict()
|
||||||
print "Error loading config, using default."
|
except ValueError as e:
|
||||||
|
print "Error loading config, using default: %s" % e
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if MONKEY_ARG == monkey_mode:
|
if MONKEY_ARG == monkey_mode:
|
||||||
|
@ -94,7 +96,7 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
monkey.start()
|
monkey.start()
|
||||||
|
|
||||||
if WormConfiguration.serialize_config:
|
if WormConfiguration.serialize_config:
|
||||||
with open(config_file, 'w') as config_fo:
|
with open(config_file, 'w') as config_fo:
|
||||||
json_dict = WormConfiguration.as_dict()
|
json_dict = WormConfiguration.as_dict()
|
||||||
|
@ -106,4 +108,4 @@ def main():
|
||||||
|
|
||||||
if "__main__" == __name__:
|
if "__main__" == __name__:
|
||||||
if not main():
|
if not main():
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -61,7 +61,6 @@ class ChaosMonkey(object):
|
||||||
firewall.add_firewall_rule()
|
firewall.add_firewall_rule()
|
||||||
|
|
||||||
ControlClient.wakeup(parent=self._parent, default_tunnel=self._default_tunnel)
|
ControlClient.wakeup(parent=self._parent, default_tunnel=self._default_tunnel)
|
||||||
|
|
||||||
monkey_tunnel = ControlClient.create_control_tunnel()
|
monkey_tunnel = ControlClient.create_control_tunnel()
|
||||||
if monkey_tunnel:
|
if monkey_tunnel:
|
||||||
monkey_tunnel.start()
|
monkey_tunnel.start()
|
||||||
|
|
|
@ -13,6 +13,7 @@ LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
SCAN_DELAY = 0
|
SCAN_DELAY = 0
|
||||||
|
|
||||||
|
|
||||||
class NetworkScanner(object):
|
class NetworkScanner(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._ip_addresses = None
|
self._ip_addresses = None
|
||||||
|
@ -26,14 +27,12 @@ class NetworkScanner(object):
|
||||||
raise Exception("Cannot find local IP address for the machine")
|
raise Exception("Cannot find local IP address for the machine")
|
||||||
|
|
||||||
LOG.info("Found local IP addresses of the machine: %r", self._ip_addresses)
|
LOG.info("Found local IP addresses of the machine: %r", self._ip_addresses)
|
||||||
|
|
||||||
# for fixed range, only scan once.
|
# for fixed range, only scan once.
|
||||||
if WormConfiguration.range_class is FixedRange:
|
if WormConfiguration.range_class is FixedRange:
|
||||||
self._ranges = [WormConfiguration.range_class('0.0.0.0')]
|
self._ranges = [WormConfiguration.range_class('0.0.0.0')]
|
||||||
else:
|
else:
|
||||||
self._ranges = [WormConfiguration.range_class(ip_address)
|
self._ranges = [WormConfiguration.range_class(ip_address)
|
||||||
for ip_address in self._ip_addresses]
|
for ip_address in self._ip_addresses]
|
||||||
|
|
||||||
LOG.info("Base local networks to scan are: %r", self._ranges)
|
LOG.info("Base local networks to scan are: %r", self._ranges)
|
||||||
|
|
||||||
def get_victim_machines(self, scan_type, max_find=5):
|
def get_victim_machines(self, scan_type, max_find=5):
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import socket
|
import socket
|
||||||
import random
|
import random
|
||||||
import struct
|
import struct
|
||||||
|
@ -7,6 +6,7 @@ from model.host import VictimHost
|
||||||
|
|
||||||
__author__ = 'itamar'
|
__author__ = 'itamar'
|
||||||
|
|
||||||
|
|
||||||
class NetworkRange(object):
|
class NetworkRange(object):
|
||||||
__metaclass__ = ABCMeta
|
__metaclass__ = ABCMeta
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ MONKEY_DOWNLOADS = [
|
||||||
{
|
{
|
||||||
'type' : 'windows',
|
'type' : 'windows',
|
||||||
'filename' : 'monkey-windows-32.exe',
|
'filename' : 'monkey-windows-32.exe',
|
||||||
},]
|
},
|
||||||
|
]
|
||||||
|
|
||||||
MONGO_URL = os.environ.get('MONGO_URL')
|
MONGO_URL = os.environ.get('MONGO_URL')
|
||||||
if not MONGO_URL:
|
if not MONGO_URL:
|
||||||
|
@ -49,7 +50,6 @@ mongo = PyMongo(app)
|
||||||
|
|
||||||
|
|
||||||
class Monkey(restful.Resource):
|
class Monkey(restful.Resource):
|
||||||
|
|
||||||
def get(self, **kw):
|
def get(self, **kw):
|
||||||
guid = kw.get('guid')
|
guid = kw.get('guid')
|
||||||
timestamp = request.args.get('timestamp')
|
timestamp = request.args.get('timestamp')
|
||||||
|
@ -77,9 +77,7 @@ class Monkey(restful.Resource):
|
||||||
if monkey_json.has_key('tunnel'):
|
if monkey_json.has_key('tunnel'):
|
||||||
update['$set']['tunnel'] = monkey_json['tunnel']
|
update['$set']['tunnel'] = monkey_json['tunnel']
|
||||||
|
|
||||||
return mongo.db.monkey.update({"guid": guid},
|
return mongo.db.monkey.update({"guid": guid}, update, upsert=False)
|
||||||
update,
|
|
||||||
upsert=False)
|
|
||||||
|
|
||||||
def post(self, **kw):
|
def post(self, **kw):
|
||||||
monkey_json = json.loads(request.data)
|
monkey_json = json.loads(request.data)
|
||||||
|
@ -117,6 +115,7 @@ class Monkey(restful.Resource):
|
||||||
{"$set" : monkey_json},
|
{"$set" : monkey_json},
|
||||||
upsert=True)
|
upsert=True)
|
||||||
|
|
||||||
|
|
||||||
class Telemetry(restful.Resource):
|
class Telemetry(restful.Resource):
|
||||||
def get(self, **kw):
|
def get(self, **kw):
|
||||||
monkey_guid = kw.get('monkey_guid')
|
monkey_guid = kw.get('monkey_guid')
|
||||||
|
@ -157,6 +156,7 @@ class Telemetry(restful.Resource):
|
||||||
|
|
||||||
return mongo.db.telemetry.find_one_or_404({"_id": telem_id})
|
return mongo.db.telemetry.find_one_or_404({"_id": telem_id})
|
||||||
|
|
||||||
|
|
||||||
class NewConfig(restful.Resource):
|
class NewConfig(restful.Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
config = mongo.db.config.find_one({'name' : 'newconfig'}) or {}
|
config = mongo.db.config.find_one({'name' : 'newconfig'}) or {}
|
||||||
|
@ -180,7 +180,7 @@ class MonkeyDownload(restful.Resource):
|
||||||
result = None
|
result = None
|
||||||
for download in MONKEY_DOWNLOADS:
|
for download in MONKEY_DOWNLOADS:
|
||||||
if host_os.get('type') == download.get('type') and \
|
if host_os.get('type') == download.get('type') and \
|
||||||
host_os.get('machine') == download.get('machine'):
|
host_os.get('machine') == download.get('machine'):
|
||||||
result = download
|
result = download
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -192,6 +192,7 @@ class MonkeyDownload(restful.Resource):
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
||||||
class Root(restful.Resource):
|
class Root(restful.Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
return {
|
return {
|
||||||
|
@ -199,6 +200,7 @@ class Root(restful.Resource):
|
||||||
'mongo': str(mongo.db),
|
'mongo': str(mongo.db),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def normalize_obj(obj):
|
def normalize_obj(obj):
|
||||||
if obj.has_key('_id') and not obj.has_key('id'):
|
if obj.has_key('_id') and not obj.has_key('id'):
|
||||||
obj['id'] = obj['_id']
|
obj['id'] = obj['_id']
|
||||||
|
@ -217,12 +219,14 @@ def normalize_obj(obj):
|
||||||
value[i] = normalize_obj(value[i])
|
value[i] = normalize_obj(value[i])
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
def output_json(obj, code, headers=None):
|
def output_json(obj, code, headers=None):
|
||||||
obj = normalize_obj(obj)
|
obj = normalize_obj(obj)
|
||||||
resp = make_response(bson.json_util.dumps(obj), code)
|
resp = make_response(bson.json_util.dumps(obj), code)
|
||||||
resp.headers.extend(headers or {})
|
resp.headers.extend(headers or {})
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
|
||||||
@app.route('/admin/<path:path>')
|
@app.route('/admin/<path:path>')
|
||||||
def send_admin(path):
|
def send_admin(path):
|
||||||
return send_from_directory('admin/ui', path)
|
return send_from_directory('admin/ui', path)
|
||||||
|
|
Loading…
Reference in New Issue