Beispiel #1
0
    def run_local_monkey():
        # get the monkey executable suitable to run on the server
        result = get_monkey_executable(platform.system().lower(), platform.machine().lower())
        if not result:
            return False, "OS Type not found"

        src_path = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc", "binaries", result["filename"])
        dest_path = os.path.join(LocalMonkeyRunService.DATA_DIR, result["filename"])

        # copy the executable to temp path (don't run the monkey from its current location as it may
        # delete itself)
        try:
            copyfile(src_path, dest_path)
            os.chmod(dest_path, stat.S_IRWXU | stat.S_IRWXG)
        except Exception as exc:
            logger.error("Copy file failed", exc_info=True)
            return False, "Copy file failed: %s" % exc

        # run the monkey
        try:
            ip = local_ip_addresses()[0]
            port = env_singleton.env.get_island_port()

            args = [dest_path, "m0nk3y", "-s", f"{ip}:{port}"]
            subprocess.Popen(args, cwd=LocalMonkeyRunService.DATA_DIR)
        except Exception as exc:
            logger.error("popen failed", exc_info=True)
            return False, "popen failed: %s" % exc

        return True, ""
Beispiel #2
0
    def get_island_cross_segment_issues():
        issues = []
        island_ips = local_ip_addresses()
        for monkey in mongo.db.monkey.find(
            {"tunnel": {"$exists": False}}, {"tunnel": 1, "guid": 1, "hostname": 1}
        ):
            found_good_ip = False
            monkey_subnets = ReportService.get_monkey_subnets(monkey["guid"])
            for subnet in monkey_subnets:
                for ip in island_ips:
                    if ipaddress.ip_address(str(ip)) in subnet:
                        found_good_ip = True
                        break
                if found_good_ip:
                    break
            if not found_good_ip:
                issues.append(
                    {
                        "type": "island_cross_segment",
                        "machine": monkey["hostname"],
                        "networks": [str(subnet) for subnet in monkey_subnets],
                        "server_networks": [str(subnet) for subnet in get_subnets()],
                    }
                )

        return issues
Beispiel #3
0
    def get_island_cross_segment_issues():
        issues = []
        island_ips = local_ip_addresses()
        for monkey in mongo.db.monkey.find({'tunnel': {
                '$exists': False
        }}, {
                'tunnel': 1,
                'guid': 1,
                'hostname': 1
        }):
            found_good_ip = False
            monkey_subnets = ReportService.get_monkey_subnets(monkey['guid'])
            for subnet in monkey_subnets:
                for ip in island_ips:
                    if ipaddress.ip_address(str(ip)) in subnet:
                        found_good_ip = True
                        break
                if found_good_ip:
                    break
            if not found_good_ip:
                issues.append({
                    'type':
                    'island_cross_segment',
                    'machine':
                    monkey['hostname'],
                    'networks': [str(subnet) for subnet in monkey_subnets],
                    'server_networks':
                    [str(subnet) for subnet in get_subnets()]
                })

        return issues
Beispiel #4
0
 def get_monkey_island_monkey():
     ip_addresses = local_ip_addresses()
     for ip_address in ip_addresses:
         monkey = NodeService.get_monkey_by_ip(ip_address)
         if monkey is not None:
             return monkey
     return None
Beispiel #5
0
 def get_monkey_label(monkey):
     # todo
     label = monkey["hostname"] + " : " + monkey["ip_addresses"][0]
     ip_addresses = local_ip_addresses()
     if len(set(monkey["ip_addresses"]).intersection(ip_addresses)) > 0:
         label = "MonkeyIsland - " + label
     return label
Beispiel #6
0
def _log_init_info():
    logger.info("Monkey Island Server is running!")
    logger.info(f"version: {get_version()}")
    logger.info("Listening on the following URLs: {}".format(", ".join([
        "https://{}:{}".format(x, env_singleton.env.get_island_port())
        for x in local_ip_addresses()
    ])))
    MonkeyDownload.log_executable_hashes()
Beispiel #7
0
 def set_server_ips_in_config(config):
     ips = local_ip_addresses()
     config["internal"]["island_server"]["command_servers"] = [
         "%s:%d" % (ip, env_singleton.env.get_island_port()) for ip in ips
     ]
     config["internal"]["island_server"]["current_server"] = "%s:%d" % (
         ips[0],
         env_singleton.env.get_island_port(),
     )
Beispiel #8
0
 def get_label_by_id(object_id):
     current_monkey = Monkey.get_single_monkey_by_id(object_id)
     label = Monkey.get_hostname_by_id(
         object_id) + " : " + current_monkey.ip_addresses[0]
     if len(
             set(current_monkey.ip_addresses).intersection(
                 local_ip_addresses())) > 0:
         label = "MonkeyIsland - " + label
     return label
Beispiel #9
0
    def get_monkey_group(monkey):
        keywords = []
        if len(set(monkey["ip_addresses"]).intersection(local_ip_addresses())) != 0:
            keywords.extend(["island", "monkey"])
        else:
            monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey"
            keywords.append(monkey_type)

        keywords.append(NodeService.get_monkey_os(monkey))
        if not Monkey.get_single_monkey_by_id(monkey["_id"]).is_dead():
            keywords.append("running")
        return NodeStates.get_by_keywords(keywords).value
Beispiel #10
0
def run_local_monkey():
    import platform
    import stat
    import subprocess

    # get the monkey executable suitable to run on the server
    result = get_monkey_executable(platform.system().lower(),
                                   platform.machine().lower())
    if not result:
        return False, "OS Type not found"

    monkey_path = os.path.join(MONKEY_ISLAND_ABS_PATH, 'cc', 'binaries',
                               result['filename'])
    target_path = os.path.join(MONKEY_ISLAND_ABS_PATH, result['filename'])

    # copy the executable to temp path (don't run the monkey from its current location as it may delete itself)
    try:
        copyfile(monkey_path, target_path)
        os.chmod(target_path, stat.S_IRWXU | stat.S_IRWXG)
    except Exception as exc:
        logger.error('Copy file failed', exc_info=True)
        return False, "Copy file failed: %s" % exc

    # run the monkey
    try:
        args = [
            '"%s" m0nk3y -s %s:%s' % (target_path, local_ip_addresses()[0],
                                      env_singleton.env.get_island_port())
        ]
        if sys.platform == "win32":
            args = "".join(args)
        subprocess.Popen(args, shell=True).pid
    except Exception as exc:
        logger.error('popen failed', exc_info=True)
        return False, "popen failed: %s" % exc

    return True, ""
Beispiel #11
0
 def get_server_info(self):
     return jsonify(
         ip_addresses=local_ip_addresses(),
         mongo=str(mongo.db),
         completed_steps=InfectionLifecycle.get_completed_steps())
Beispiel #12
0
 def get_monkey_island_node():
     island_node = NodeService.get_monkey_island_pseudo_net_node()
     island_node["ip_addresses"] = local_ip_addresses()
     island_node["domain_name"] = socket.gethostname()
     return island_node