Exemplo n.º 1
0
def install(enabled, force, rewrite, archive):
    if archive:
        if not os.path.isfile(archive):
            print("ERROR: Provided archive not found!")
            sys.exit(-1)

        data = open(archive, "rb").read()
    else:
        data = download_archive()

    temp, source = extract_archive(data)

    folders = {
        "signatures": os.path.join("modules", "signatures"),
        "processing": os.path.join("modules", "processing"),
        "reporting": os.path.join("modules", "reporting"),
        "machinery": os.path.join("modules", "machinery"),
        "analyzer": os.path.join("analyzer"),
        "monitor": os.path.join("data", "monitor"),
        "agent": os.path.join("agent"),
    }

    for category in enabled:
        folder = folders[category]

        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        origin = os.path.join(source, folder)
        if not os.path.isdir(origin):
            print "  No candidates available, continuing."
            continue

        installdir(origin, os.path.join(CUCKOO_ROOT, folder), force, rewrite)

    shutil.rmtree(temp)
Exemplo n.º 2
0
def install(enabled, force, rewrite):
    (temp, source) = download_archive()

    folders = {
        "signatures": os.path.join("modules", "signatures"),
        "processing": os.path.join("modules", "processing"),
        "reporting": os.path.join("modules", "reporting"),
        "machinery": os.path.join("modules", "machinery"),
        "analyzer": os.path.join("analyzer"),
        "monitor": os.path.join("data", "monitor"),
        "agent": os.path.join("agent"),
    }

    for category in enabled:
        folder = folders[category]

        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        origin = os.path.join(source, folder)
        if not os.path.isdir(origin):
            print "  No candidates available, continuing."
            continue

        installdir(origin, os.path.join(CUCKOO_ROOT, folder), force, rewrite)

    shutil.rmtree(temp)
Exemplo n.º 3
0
def install(enabled, force, rewrite):
    (temp, source) = download_archive()

    folders = {
        "signatures": os.path.join("modules", "signatures"),
        "processing": os.path.join("modules", "processing"),
        "reporting": os.path.join("modules", "reporting"),
        "machinery": os.path.join("modules", "machinery"),
        "analyzer": os.path.join("analyzer"),
        "monitor": os.path.join("data", "monitor"),
        "agent": os.path.join("agent"),
    }

    for category in enabled:
        folder = folders[category]

        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        origin = os.path.join(source, folder)
        if not os.path.isdir(origin):
            print "  No candidates available, continuing."
            continue

        installdir(origin, os.path.join(CUCKOO_ROOT, folder), force, rewrite)

    shutil.rmtree(temp)
Exemplo n.º 4
0
def install(enabled, force, rewrite, archive):
    if archive:
        if not os.path.isfile(archive):
            print("ERROR: Provided archive not found!")
            sys.exit(-1)

        data = open(archive, "rb").read()
    else:
        data = download_archive()

    temp, source = extract_archive(data)

    folders = {
        "signatures": os.path.join("modules", "signatures"),
        "processing": os.path.join("modules", "processing"),
        "reporting": os.path.join("modules", "reporting"),
        "machinery": os.path.join("modules", "machinery"),
        "analyzer": os.path.join("analyzer"),
        "monitor": os.path.join("data", "monitor"),
        "agent": os.path.join("agent"),
    }

    for category in enabled:
        folder = folders[category]

        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        origin = os.path.join(source, folder)
        if not os.path.isdir(origin):
            print "  No candidates available, continuing."
            continue

        installdir(origin, os.path.join(CUCKOO_ROOT, folder), force, rewrite)

    shutil.rmtree(temp)
Exemplo n.º 5
0
def install(enabled, force, rewrite):
    (temp, source) = download_archive()

    folders = {
        "signatures": os.path.join("modules", "signatures"),
        "processing": os.path.join("modules", "processing"),
        "reporting": os.path.join("modules", "reporting"),
        "machinemanagers": os.path.join("modules", "machinemanagers"),
        "windows": os.path.join("analyzer", "windows", "bin"),
    }

    for category in enabled:
        folder = folders[category]

        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        origin = os.path.join(source, folder)
        if not os.path.isdir(origin):
            print "  No candidates available, continuing."
            continue

        for file_name in os.listdir(origin):
            if file_name == ".gitignore":
                continue

            destination = os.path.join(CUCKOO_ROOT, folder, file_name)

            if not rewrite:
                if os.path.exists(destination):
                    print("File \"{0}\" already exists, "
                          "{1}".format(file_name, colors.yellow("skipped")))
                    continue

            install = False

            if not force:
                while 1:
                    choice = raw_input("Do you want to install file "
                                       "\"{0}\"? [yes/no] ".format(file_name))
                    if choice.lower() == "yes":
                        install = True
                        break
                    elif choice.lower() == "no":
                        break
                    else:
                        continue
            else:
                install = True

            if install:
                shutil.copy(os.path.join(origin, file_name), destination)
                print("File \"{0}\" {1}".format(file_name,
                                                colors.green("installed")))

    shutil.rmtree(temp)
Exemplo n.º 6
0
def install(enabled, force, rewrite, filepath):
    (temp, source) = download_archive(filepath)

    folders = {
        "feeds": os.path.join("modules", "feeds"),
        "signatures": os.path.join("modules", "signatures"),
        "processing": os.path.join("modules", "processing"),
        "reporting": os.path.join("modules", "reporting"),
        "machinery": os.path.join("modules", "machinery")
    }

    for category in enabled:
        folder = folders.get(category, False)
        if not folder:
            continue
        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        origin = os.path.join(source, folder)

        for file_name in os.listdir(origin):
            if file_name == ".gitignore":
                continue

            destination = os.path.join(CUCKOO_ROOT, folder, file_name)

            if not rewrite:
                if os.path.exists(destination):
                    print("File \"{0}\" already exists, "
                          "{1}".format(file_name, colors.yellow("skipped")))
                    continue

            install = False

            if not force:
                while 1:
                    choice = input("Do you want to install file "
                                       "\"{0}\"? [yes/no] ".format(file_name))
                    if choice.lower() == "yes":
                        install = True
                        break
                    elif choice.lower() == "no":
                        break
                    else:
                        continue
            else:
                install = True

            if install:
                shutil.copy(os.path.join(origin, file_name), destination)
                print("File \"{0}\" {1}".format(file_name,
                                                colors.green("installed")))

    shutil.rmtree(temp)
Exemplo n.º 7
0
    def emit(self, record):
        colored = copy.copy(record)

        if record.levelname == "WARNING":
            colored.msg = yellow(record.msg)
        elif record.levelname == "ERROR" or record.levelname == "CRITICAL":
            colored.msg = red(record.msg)
        else:
            if "analysis procedure completed" in record.msg:
                colored.msg = cyan(record.msg)
            else:
                colored.msg = record.msg

        logging.StreamHandler.emit(self, colored)
Exemplo n.º 8
0
    def emit(self, record):
        colored = copy.copy(record)

        if record.levelname == "WARNING":
            colored.msg = yellow(record.msg)
        elif record.levelname == "ERROR" or record.levelname == "CRITICAL":
            colored.msg = red(record.msg)
        else:
            if "analysis procedure completed" in record.msg:
                colored.msg = cyan(record.msg)
            else:
                colored.msg = record.msg

        logging.StreamHandler.emit(self, colored)
Exemplo n.º 9
0
def install(enabled, force, rewrite):
    (temp, source) = download_archive()

    folders = {"signatures" : os.path.join("modules", "signatures")}

    for category in enabled:
        folder = folders[category]

        print("\nInstalling %s" % colors.cyan(category.upper()))

        origin = os.path.join(source, folder)

        for file_name in os.listdir(origin):
            destination = os.path.join(ROOT, folder, file_name)

            if not rewrite:
                if os.path.exists(destination):
                    print("File \"%s\" already exists, %s" % (file_name, colors.yellow("skipped")))
                    continue

            install = False

            if not force:
                while 1:
                    choice = raw_input("Do you want to install file \"%s\"? [yes/no] " % file_name)
                    if choice.lower() == "yes":
                        install = True
                        break
                    elif choice.lower() == "no":
                        break
                    else:
                        continue
            else:
                install = True

            if install:
                shutil.copy(os.path.join(origin, file_name), destination)
                print("File \"%s\" %s" % (file_name, colors.green("installed")))

    shutil.rmtree(temp)
Exemplo n.º 10
0
def install(enabled, force, rewrite, filepath):
    if filepath and os.path.exists(filepath):
        data = open(filepath, "rb").read()
    else:
        print("Downloading modules from {0}".format(URL))
        try:
            http = urllib3.PoolManager()
            data = http.request("GET", URL).data
            t = tarfile.TarFile.open(fileobj=BytesIO(data), mode="r:gz")
        except Exception as e:
            print("ERROR: Unable to download archive: %s" % e)
            sys.exit(-1)

    folders = {
        "feeds": "modules/feeds",
        "signatures": "modules/signatures",
        "processing": "modules/processing",
        "reporting": "modules/reporting",
        "machinery": "modules/machinery",
        "analyzer": "analyzer",
        "data": "data",
    }

    members = t.getmembers()
    directory = members[0].name.split("/")[0]

    for category in enabled:
        folder = folders.get(category, False)
        if not folder:
            continue

        print("\nInstalling {0}".format(colors.cyan(category.upper())))

        # E.g., "community-master/modules/signatures".
        name_start = "%s/%s" % (directory, folder)
        for member in members:
            if not member.name.startswith(
                    name_start) or name_start == member.name:
                continue

            filepath = os.path.join(CUCKOO_ROOT, folder,
                                    member.name[len(name_start) + 1:])
            if member.name.endswith(".gitignore"):
                continue

            if member.isdir():
                if not os.path.exists(filepath):
                    os.mkdir(filepath)
                continue

            if not rewrite:
                if os.path.exists(filepath):
                    print('File "{}" already exists, {}'.format(
                        filepath, colors.yellow("skipped")))
                    continue

            install = False
            dest_file = os.path.basename(filepath)
            if not force:
                while 1:
                    choice = input(
                        'Do you want to install file "{}"? [yes/no] '.format(
                            dest_file))
                    if choice.lower() == "yes":
                        install = True
                        break
                    elif choice.lower() == "no":
                        break
                    else:
                        continue
            else:
                install = True

            if install:
                if not os.path.exists(os.path.dirname(filepath)):
                    os.makedirs(os.path.dirname(filepath))

                print('File "{}" {}'.format(filepath,
                                            colors.green("installed")))
                open(filepath, "wb").write(t.extractfile(member).read())