Exemplo n.º 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, ""
Exemplo n.º 2
0
def run_local_monkey():
    import platform
    import subprocess
    import stat

    # 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.get_island_port())]
        if sys.platform == "win32":
            args = "".join(args)
        pid = 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, "pis: %s" % pid