Пример #1
0
def menu(menu_parser):
    """
    Parser for the command line parameter menu and calls the appropriate functions.
    :param menu_parser: the argparse menu as created with 'init_menu()'
    :return:
    """
    args = menu_parser.parse_args()

    if args.interactive:
        interactive_menu()

    elif args.subparser in ['datasource', 'ds']:
        if check_file_type(args.file, FILE_TYPE_DATA_SOURCE_ADMINISTRATION):
            if args.layer:
                generate_data_sources_layer(args.file)
            if args.excel:
                export_data_source_list_to_excel(args.file)
            if args.graph:
                plot_data_sources_graph(args.file)
            if args.yaml:
                generate_technique_administration_file(args.file)

    elif args.subparser in ['visibility', 'v']:
        if check_file_type(args.file_tech, FILE_TYPE_TECHNIQUE_ADMINISTRATION) and \
           check_file_type(args.file_ds, FILE_TYPE_DATA_SOURCE_ADMINISTRATION):
            if args.layer:
                generate_visibility_layer(args.file_tech, args.file_ds, False)
            if args.overlay:
                generate_visibility_layer(args.file_tech, args.file_ds, True)

    elif args.subparser in ['group', 'g']:
        generate_group_heat_map(args.groups, args.overlay, args.overlay_type,
                                args.stage, args.platform, args.software_group)

    elif args.subparser in ['detection', 'd']:
        if args.overlay:
            if not args.file_ds:
                print(
                    '[!] Doing an overlay requires adding the data source administration YAML file (\'--file-ds\')'
                )
                quit()
            if not check_file_type(args.file_ds,
                                   FILE_TYPE_DATA_SOURCE_ADMINISTRATION):
                quit()

        if check_file_type(args.file_tech, FILE_TYPE_TECHNIQUE_ADMINISTRATION):
            if args.layer:
                generate_detection_layer(args.file_tech, args.file_ds, False)
            if args.overlay and check_file_type(
                    args.file_ds, FILE_TYPE_DATA_SOURCE_ADMINISTRATION):
                generate_detection_layer(args.file_tech, args.file_ds, True)
            if args.graph:
                plot_detection_graph(args.file_tech)

    elif args.subparser in ['generic', 'ge']:
        if args.statistics:
            get_statistics()
        elif args.updates:
            get_updates(args.updates, args.sort)
Пример #2
0
def _menu(menu_parser):
    """
    Parser for the command line parameter menu and calls the appropriate functions.
    :param menu_parser: the argparse menu as created with '_init_menu()'
    :return:
    """
    args = menu_parser.parse_args()

    if args.interactive:
        interactive_menu()

    elif args.subparser in ['datasource', 'ds']:
        if check_file(args.file_ds, FILE_TYPE_DATA_SOURCE_ADMINISTRATION, args.health):
            file_ds = args.file_ds

            if args.search:
                file_ds = data_source_search(args.file_ds, args.search)
                if not file_ds:
                    quit()  # something went wrong in executing the search or 0 results where returned
            if args.update and check_file(args.file_tech, FILE_TYPE_TECHNIQUE_ADMINISTRATION, args.health):
                update_technique_administration_file(file_ds, args.file_tech)
            if args.layer:
                generate_data_sources_layer(file_ds)
            if args.excel:
                export_data_source_list_to_excel(file_ds)
            if args.graph:
                plot_data_sources_graph(file_ds)
            if args.yaml:
                generate_technique_administration_file(file_ds)

    elif args.subparser in ['visibility', 'v']:
        if args.layer or args.overlay:
            if not args.file_ds:
                print('[!] Generating a visibility layer or an overlay requires the data source '
                      'administration YAML file (\'-fd, --file-ds\')')
                quit()
            if not check_file(args.file_ds, FILE_TYPE_DATA_SOURCE_ADMINISTRATION, args.health):
                quit()

        if check_file(args.file_tech, FILE_TYPE_TECHNIQUE_ADMINISTRATION, args.health):
            file_tech = args.file_tech

            if args.search_detection or args.search_visibility:
                file_tech = techniques_search(args.file_tech, args.search_visibility, args.search_detection,
                                              include_all_score_objs=args.all_scores)
                if not file_tech:
                    quit()  # something went wrong in executing the search or 0 results where returned
            if args.layer:
                generate_visibility_layer(file_tech, args.file_ds, False)
            if args.overlay:
                generate_visibility_layer(file_tech, args.file_ds, True)
            if args.graph:
                plot_graph(file_tech, 'visibility')
            if args.excel:
                export_techniques_list_to_excel(file_tech)

    # toto add search capabilities
    elif args.subparser in ['group', 'g']:
        if not generate_group_heat_map(args.groups, args.overlay, args.overlay_type, args.stage, args.platform,
                                       args.software_group, args.search_visibility, args.search_detection, args.health,
                                       include_all_score_objs=args.all_scores):
            quit()  # something went wrong in executing the search or 0 results where returned

    elif args.subparser in ['detection', 'd']:
        if args.overlay:
            if not args.file_ds:
                print('[!] An overlay requires the data source administration YAML file (\'-fd, --file-ds\')')
                quit()
            if not check_file(args.file_ds, FILE_TYPE_DATA_SOURCE_ADMINISTRATION, args.health):
                quit()

        if check_file(args.file_tech, FILE_TYPE_TECHNIQUE_ADMINISTRATION, args.health):
            file_tech = args.file_tech

            if args.search_detection or args.search_visibility:
                file_tech = techniques_search(args.file_tech, args.search_visibility, args.search_detection,
                                              include_all_score_objs=args.all_scores)
                if not file_tech:
                    quit()  # something went wrong in executing the search or 0 results where returned
            if args.layer:
                generate_detection_layer(file_tech, args.file_ds, False)
            if args.overlay and check_file(args.file_ds, FILE_TYPE_DATA_SOURCE_ADMINISTRATION, args.health):
                generate_detection_layer(file_tech, args.file_ds, True)
            if args.graph:
                plot_graph(file_tech, 'detection')
            if args.excel:
                export_techniques_list_to_excel(file_tech)

    elif args.subparser in ['generic', 'ge']:
        if args.datasources:
            get_statistics_data_sources()
        elif args.mitigations:
            get_statistics_mitigations(args.mitigations)
        elif args.updates:
            get_updates(args.updates, args.sort)

    else:
        menu_parser.print_help()