Пример #1
0
def index_md_gen():
    util.progress_bar("Index Page")
    start_time = time.time()
    index.javascript_settings()
    index.generate()
    end_time = time.time()
    util.progress_bar("Index Page", end_time - start_time)
Пример #2
0
def pelican_content():
    util.progress_bar("Pelican Content")

    # Run pelican with limited output, -q is for quiet
    if config.subdirectory:
        returned_out = subprocess.check_output(f"pelican content -q -o {config.web_directory}", shell=True)
    else:
        returned_out = subprocess.check_output("pelican content -q", shell=True)
    util.progress_bar("Pelican Content", float(str(returned_out).split(" ")[13]))
Пример #3
0
def get_stix_data(args):
    """Set up proxy if any and get STIX data"""

    # Set proxy
    proxy = ""
    if args.proxy is not None:
        proxy = args.proxy
    proxyDict = {"http": proxy, "https": proxy}

    use_local_stix = True
    for domain in config.settings_dict['domains']:
        if not (os.path.isfile('{0}/{1}.json'.format(config.stix_directory,
                                                     domain))):
            use_local_stix = False

    if (not os.path.isdir(config.stix_directory)):
        os.mkdir(config.stix_directory)
    try:
        util.progress_bar("Downloading STIX Data")
        start_time = time.time()

        for domain in config.settings_dict['domains']:
            # This is the unofficial STIX repository for AMITT for the time being.
            # Store a local copy of amitt-attack.json because things are likely to break.
            r = requests.get(
                f"https://raw.githubusercontent.com/VVX7/cti/master/{domain}/{domain}.json",
                verify=False,
                proxies=proxyDict)

            # r = requests.get(f"https://raw.githubusercontent.com/mitre/cti/master/{domain}/{domain}.json",
            #                  verify=False, proxies=proxyDict)

            with open(
                    os.path.join(config.stix_directory, domain + "_old.json"),
                    'w+') as f:
                f.write(json.dumps(r.json()))

                if (args.refresh or not os.path.isdir(config.stix_directory)
                        or not use_local_stix):
                    with open(
                            os.path.join(config.stix_directory,
                                         domain + ".json"), 'w+') as f:
                        f.write(json.dumps(r.json()))

        end_time = time.time()
        util.progress_bar("Downloading STIX Data", end_time - start_time)
    except:
        end_time = time.time()
        util.progress_bar("Downloading STIX Data", end_time - start_time)
        print("Unable to reach stix repository. Are you behind a (--proxy)?")
Пример #4
0
def software_md_gen():
    util.progress_bar("Software Pages")
    start_time = time.time()
    software.generate()
    end_time = time.time()
    util.progress_bar("Software Pages", end_time - start_time)
Пример #5
0
def group_md_gen():
    util.progress_bar("Group Pages")
    start_time = time.time()
    group.generate()
    end_time = time.time()
    util.progress_bar("Group Pages", end_time - start_time)
Пример #6
0
def grab_resources():
    util.progress_bar("Initializing Data")
    start_time = time.time()
    config.init_shared_data()
    end_time = time.time()
    util.progress_bar("Initializing Data", end_time - start_time)
Пример #7
0
def clean_website():
    util.progress_bar("Clean Build")
    start_time = time.time()
    clean.clean_website_build()
    end_time = time.time()
    util.progress_bar("Clean Build", end_time - start_time)
Пример #8
0
def deploy_current_version():
    util.progress_bar("Version permalink")
    start_time = time.time()
    versions.deploy_current_version()
    end_time = time.time()
    util.progress_bar("Current version permalink", end_time - start_time)
Пример #9
0
def contribute_md_gen():
    util.progress_bar("Contribute Page")
    start_time = time.time()
    contribute.generate()
    end_time = time.time()
    util.progress_bar("Contribute Page", end_time - start_time)
Пример #10
0
def tactic_md_gen():
    util.progress_bar("Tactic Pages")
    start_time = time.time()
    tactic.generate()
    end_time = time.time()
    util.progress_bar("Tactic Pages", end_time - start_time)
Пример #11
0
def redirects_md_gen():
    util.progress_bar("Redirection Pages")
    start_time = time.time()
    redirects.generate()
    end_time = time.time()
    util.progress_bar("Redirection Pages", end_time - start_time)
Пример #12
0
def update(args):
    """Run all modules"""

    exit_codes = []

    # Start time of update
    update_start = time.time()

    # Clean output/content directory if flag is set
    if args.clean:
        generate.clean_website()

    # Grab shared resources and stix data
    if args.build:
        get_stix_data(args)
        generate.grab_resources()

    # Generate index markdown
    if args.build:
        generate.index_md_gen()

    # Generate group markdowns
    if args.build:
        if 'groups' in args.build:
            generate.group_md_gen()

    # Software markdown generation
    if args.build:
        if 'software' in args.build:
            generate.software_md_gen()

    # Generate technique markdowns
    if args.build:
        if 'techniques' in args.build:
            generate.technique_md_gen()

    # Generate matrix markdowns
    if args.build:
        if 'matrices' in args.build:
            generate.matrix_md_gen()

    # Generate tactic markdowns
    if args.build:
        if 'tactics' in args.build:
            generate.tactic_md_gen()

    # Generate mitigation markdowns
    if args.build:
        if 'mitigations' in args.build:
            generate.mitigation_md_gen()

    # Generate contribute markdowns
    if args.build:
        if 'contribute' in args.build:
            generate.contribute_md_gen()

    # Generate resources markdowns
    if args.build:
        if 'resources' in args.build:
            generate.resources_md_gen()

    # Generate redirects markdowns
    if args.build:
        if 'redirects' in args.build:
            generate.redirects_md_gen()

    # Generate Index
    if args.build:
        if 'search' in args.build:
            generate.generate_search_index()

    # Deploy previous version
    if args.build:
        if 'prev_versions' in args.build:
            generate.previous_versions_gen()

    # Pelican update
    if args.build:
        generate.pelican_content()
        # Remove unwanted files created by pelican
        generate.remove_unwanted_output()

    if args.build:
        build_end = time.time()
        build_time = build_end - update_start

    # Tests
    if (args.build and
        (sorted(args.build) == sorted(config.build_defaults))) or args.tests:
        # Start time of tests update
        test_start = time.time()
        exit_codes = tests.run_tests(args)
        test_end = time.time()
        test_time = test_end - test_start

    if args.build and ((sorted(args.build) == sorted(config.build_defaults))
                       or args.tests):
        util.progress_bar("TOTAL Build Time", build_time)
        util.progress_bar("TOTAL Test Time", test_time)

    update_end = time.time()
    util.progress_bar("TOTAL Update Time", update_end - update_start)

    if not args.override_exit_status:
        handle_exit(exit_codes)
Пример #13
0
def update(args):
    """Run all modules"""

    exit_codes = []

    # Start time of update
    update_start = time.time()

    # Clean output/content directory if flag is set
    if args.clean:
        generate.clean_website()    

    # Grab shared resources and stix data
    if args.build:
        get_stix_data(args)
        generate.grab_resources()

    # Set website path with subdirectory
    if args.subdirectory:
        config.set_subdirectory(args.subdirectory)

    # Generate index markdown
    if args.build:
        generate.index_md_gen()
        generate.tour_gen()

    # Generate group markdowns
    if args.build:
        if 'groups' in args.build:
            generate.group_md_gen()

    # Software markdown generation
    if args.build:
        if 'software' in args.build:
            generate.software_md_gen()

    # Generate technique markdowns
    if args.build:
        if 'techniques' in args.build:
            generate.technique_md_gen()

    # Generate matrix markdowns
    if args.build:
        if 'matrices' in args.build:
            generate.matrix_md_gen()

    # Generate tactic markdowns
    if args.build:
        if 'tactics' in args.build:
            generate.tactic_md_gen()

    # Generate mitigation markdowns
    if args.build:
        if 'mitigations' in args.build:
            generate.mitigation_md_gen()

    # Generate contribute markdowns
    if args.build:
        if 'contribute' in args.build:
            generate.contribute_md_gen()
    
    # Generate resources markdowns
    if args.build:
        if 'resources' in args.build:
            generate.resources_md_gen()
        
    # Generate redirects markdowns
    if args.build:
        if 'redirects' in args.build:
            generate.redirects_md_gen()

    # Set website path with subdirectory
    if args.subdirectory:
        config.set_subdirectory(args.subdirectory)

    # Deploy versions
    if args.build:
        if 'versions' in args.build:
    	    generate.previous_versions_gen()

    # Pelican update
    if args.build:
        generate.pelican_content()
        # Remove unwanted files created by pelican
        generate.remove_unwanted_output()

    # Generate search index
    # note: this should come basically last in the build process
    # because it parses the content of the output directory to build the index
    if args.build:
        if 'search' in args.build:
    	    generate.generate_search_index()
    
    # Preserve current version
    if args.build:
        if 'versions' in args.build:
            generate.deploy_current_version()

    # Replace output directory links with subdirectory
    if args.subdirectory:
        generate.subdirectory_gen()

    if args.build:
        build_end = time.time()
        build_time = build_end - update_start
    
    # Tests
    if (args.build and (sorted(args.build) == sorted(config.build_defaults))) or args.tests:
        # Start time of tests update
        test_start = time.time()
        exit_codes = tests.run_tests(args)
        test_end = time.time()
        test_time = test_end - test_start
    
    if args.build and ((sorted(args.build) == sorted(config.build_defaults)) or args.tests):
        util.progress_bar("TOTAL Build Time", build_time)
        util.progress_bar("TOTAL Test Time", test_time)
    
    update_end = time.time()
    util.progress_bar("TOTAL Update Time", update_end - update_start)

    if not args.override_exit_status:
        handle_exit(exit_codes)
Пример #14
0
def subdirectory_gen():
    util.progress_bar("Subdirectory")
    start_time = time.time()
    subdirectory.replace()
    end_time = time.time()
    util.progress_bar("Subdirectory", end_time - start_time)
Пример #15
0
def tour_gen():
    util.progress_bar("Tour")
    start_time = time.time()
    tour.generate_tour()
    end_time = time.time()
    util.progress_bar("Tour", end_time - start_time)
Пример #16
0
def technique_md_gen():
    util.progress_bar("Technique Pages")
    start_time = time.time()
    technique.generate()
    end_time = time.time()
    util.progress_bar("Technique Pages", end_time - start_time)
Пример #17
0
def matrix_md_gen():
    util.progress_bar("Matrix Pages")
    start_time = time.time()
    matrix.generate()
    end_time = time.time()
    util.progress_bar("Matrix Pages", end_time - start_time)
Пример #18
0
def pelican_content():
    util.progress_bar("Pelican Content")
    # Run pelican with limited output, -q is for quiet
    returned_out = subprocess.check_output("pelican content -q", shell=True)
    util.progress_bar("Pelican Content",
                      float(str(returned_out).split(" ")[13]))
Пример #19
0
def mitigation_md_gen():
    util.progress_bar("Mitigation Pages")
    start_time = time.time()
    mitigation.generate()
    end_time = time.time()
    util.progress_bar("Mitigation Pages", end_time - start_time)
Пример #20
0
def generate_search_index():
    util.progress_bar("Search Index")
    start_time = time.time()
    search.generate_index()
    end_time = time.time()
    util.progress_bar("Search Index", end_time - start_time)
Пример #21
0
def resources_md_gen():
    util.progress_bar("Resources Page")
    start_time = time.time()
    resources.generate()
    end_time = time.time()
    util.progress_bar("Resources Page", end_time - start_time)
Пример #22
0
def previous_versions_gen():
    util.progress_bar("Previous Versions")
    start_time = time.time()
    archives.deploy()
    end_time = time.time()
    util.progress_bar("Previous Versions", end_time - start_time)