2019-03-29 14:26:25 +00:00
import glob
from data_source_mapping import *
from technique_mapping import *
from group_mapping import *
2019-08-13 12:30:43 +00:00
from eql_yaml import *
2019-03-29 14:26:25 +00:00
groups = ' all '
software_group = False
2020-10-15 09:03:36 +00:00
default_platform = [ ' Windows ' ]
2019-08-01 13:02:06 +00:00
default_stage = ' attack '
default_matrix = ' enterprise '
2019-03-29 14:26:25 +00:00
groups_overlay = ' '
2019-05-07 13:40:15 +00:00
overlay_type = ' group '
2019-04-23 11:13:50 +00:00
yaml_path = ' sample-data/ '
2019-08-13 12:30:43 +00:00
eql_all_scores = False
eql_query_detection = None
eql_query_visibility = None
eql_query_data_sources = None
2019-12-09 14:26:48 +00:00
yaml_all_techniques = False
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _clear ( ) :
2019-03-29 14:26:25 +00:00
"""
Clears the terminal screen and prints the title and version of the application .
: return :
"""
if sys . platform . startswith ( ' linux ' ) or sys . platform == ' darwin ' :
os . system ( ' clear ' )
elif sys . platform == ' win32 ' :
os . system ( ' cls ' )
name = ' -= %s =- ' % APP_NAME
desc = ' -- %s -- ' % APP_DESC
version = ' version %s ' % VERSION
2020-05-25 09:44:13 +00:00
print ( ' ' * int ( ( len ( desc ) - len ( name ) ) / 2 ) + name )
2019-03-29 14:26:25 +00:00
print ( desc )
2020-05-25 09:44:13 +00:00
print ( ' ' * int ( ( len ( desc ) - len ( version ) ) / 2 ) + version )
2019-03-29 14:26:25 +00:00
print ( ' ' )
2019-07-31 08:20:21 +00:00
def _ask_input ( ) :
2019-03-29 14:26:25 +00:00
"""
Waits for input from the terminal .
: return :
"""
return input ( ' >> ' )
2019-07-31 08:20:21 +00:00
def _wait ( ) :
2019-03-29 14:26:25 +00:00
"""
Prints wait statement and wait for pressing ENTER key .
: return :
"""
print ( ' ' )
2019-04-23 11:19:29 +00:00
print ( ' Press a key to continue ' )
2019-03-29 14:26:25 +00:00
input ( ' ' )
def interactive_menu ( ) :
"""
Main menu for interactive mode .
: return :
"""
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Select a mode: ' )
print ( ' 1. %s ' % MENU_NAME_DATA_SOURCE_MAPPING )
print ( ' 2. %s ' % MENU_NAME_VISIBILITY_MAPPING )
print ( ' 3. %s ' % MENU_NAME_DETECTION_COVERAGE_MAPPING )
print ( ' 4. %s ' % MENU_NAME_THREAT_ACTOR_GROUP_MAPPING )
print ( ' 5. Updates ' )
print ( ' 6. Statistics ' )
print ( ' 9. Quit ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
2019-07-31 08:20:21 +00:00
_menu_data_source ( _select_file ( MENU_NAME_DATA_SOURCE_MAPPING , ' data sources ' , FILE_TYPE_DATA_SOURCE_ADMINISTRATION ) )
2019-03-29 14:26:25 +00:00
elif choice == ' 2 ' :
2019-07-31 08:20:21 +00:00
_menu_visibility ( _select_file ( MENU_NAME_VISIBILITY_MAPPING , ' techniques (used to score the level of visibility) ' , FILE_TYPE_TECHNIQUE_ADMINISTRATION ) ,
_select_file ( MENU_NAME_VISIBILITY_MAPPING , ' data sources (used to add metadata on the involved data sources to the heat map) ' , FILE_TYPE_DATA_SOURCE_ADMINISTRATION , False ) )
2019-03-29 14:26:25 +00:00
elif choice == ' 3 ' :
2019-07-31 08:20:21 +00:00
_menu_detection ( _select_file ( MENU_NAME_DETECTION_COVERAGE_MAPPING , ' techniques ' , FILE_TYPE_TECHNIQUE_ADMINISTRATION ) )
2019-03-29 14:26:25 +00:00
elif choice == ' 4 ' :
2019-07-31 08:20:21 +00:00
_menu_groups ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 5 ' :
2019-07-31 08:20:21 +00:00
_menu_updates ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 6 ' :
2019-07-31 08:20:21 +00:00
_menu_statistics ( )
2019-03-29 14:26:25 +00:00
elif choice in [ ' 9 ' , ' q ' ] :
quit ( )
else :
interactive_menu ( )
2019-07-31 08:20:21 +00:00
def _select_file ( title , what , expected_file_type , b_clear = True ) :
2019-03-29 14:26:25 +00:00
"""
Prints and handles the file selection in the terminal . It shows just . yaml files .
: param title : title to print on top of this menu
: param what : print for what purpose the file is selected
: param expected_file_type : the expected file type of the YAML file
2019-08-15 13:34:31 +00:00
: param b_clear : clear the terminal before showing this menu
2019-03-29 14:26:25 +00:00
: return : filename of the selected file
"""
2019-04-23 11:13:50 +00:00
global yaml_path
2019-03-29 14:26:25 +00:00
if b_clear :
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: %s ' % title )
print ( ' ' )
print ( ' Select the YAML file with %s : ' % what )
print ( ' ' )
2019-04-23 11:13:50 +00:00
print ( ' Path: %s ' % yaml_path )
2019-03-29 14:26:25 +00:00
n = 1
files = [ ]
2019-04-23 11:13:50 +00:00
for f in glob . glob ( yaml_path + ' *.yaml ' ) :
2019-03-29 14:26:25 +00:00
files . append ( f )
print ( ' %d . %s ' % ( n , f ) )
n + = 1
change_path_nr = 8 if n < 8 else n + ( 5 - n % 5 ) - 1
print ( ' %d . Change path ' % change_path_nr )
back_nr = 9 if n < 9 else n + ( 5 - n % 5 )
print ( ' %d . Back to main menu. ' % back_nr )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == str ( change_path_nr ) :
print ( " Supply full or relative path: " )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
choice = choice if choice . endswith ( ' / ' ) else choice + ' / '
if os . path . exists ( choice ) :
2019-04-23 11:13:50 +00:00
yaml_path = choice
2019-07-31 08:20:21 +00:00
return _select_file ( title , what , expected_file_type , b_clear )
2019-03-29 14:26:25 +00:00
else :
print ( " [!] Path doesn ' t exist " )
2019-07-31 08:20:21 +00:00
_wait ( )
return _select_file ( title , what , expected_file_type , b_clear )
2019-03-29 14:26:25 +00:00
elif choice == str ( back_nr ) :
interactive_menu ( )
elif choice == ' q ' :
quit ( )
else :
if choice . isdigit ( ) and int ( choice ) < n :
filename = files [ int ( choice ) - 1 ]
2019-05-19 12:10:25 +00:00
file_type = check_file ( filename , file_type = expected_file_type )
2019-03-29 14:26:25 +00:00
if file_type :
2019-04-23 11:19:29 +00:00
print ( ' Selected file: ' + filename )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
return filename
else :
print ( " [!] Invalid choice " )
2019-07-31 08:20:21 +00:00
_wait ( )
return _select_file ( title , what , expected_file_type , b_clear )
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _menu_updates ( ) :
2019-03-29 14:26:25 +00:00
"""
Prints and handles the menu for the Updates functionality .
: return :
"""
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: Updates ' )
print ( ' ' )
print ( ' Select for what you want to see updates: ' )
print ( ' 1. Techniques (sorted by modified date) ' )
print ( ' 1s. Techniques (sorted by creation date) ' )
print ( ' 2. Groups (sorted by modified date) ' )
print ( ' 2s. Groups (sorted by creation date) ' )
print ( ' 3. Software (sorted by modified date) ' )
print ( ' 3s. Software (sorted by creation date) ' )
print ( ' 9. Back to main menu. ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
get_updates ( ' techniques ' )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1s ' :
get_updates ( ' techniques ' , ' created ' )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 2 ' :
get_updates ( ' groups ' )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 2s ' :
get_updates ( ' groups ' , ' created ' )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 3 ' :
get_updates ( ' software ' )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 3s ' :
get_updates ( ' software ' , ' created ' )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 9 ' :
interactive_menu ( )
elif choice == ' q ' :
quit ( )
2019-07-31 08:20:21 +00:00
_menu_updates ( )
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _menu_statistics ( ) :
2019-03-29 14:26:25 +00:00
"""
Handles the Statistics functionality .
: return :
"""
2019-08-01 13:02:06 +00:00
global default_matrix
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: Statistics ' )
print ( ' ' )
2019-08-01 13:02:06 +00:00
print ( ' Options: ' )
print ( ' 1. Matrix: %s ' % default_matrix )
2019-08-13 12:30:43 +00:00
print ( ' ' )
print ( ' Select what you want to do: ' )
2019-08-01 13:02:06 +00:00
print ( ' 2. Get a sorted count on how many ATT&CK Enterprise techniques are covered by a particular Data Source. ' )
print ( ' 3. Get a sorted count on how many ATT&CK Enterprise or Mobile techniques are covered by a Mitigation. ' )
print ( ' 9. Back to main menu. ' )
choice = _ask_input ( )
if choice == ' 1 ' :
2019-08-21 13:12:12 +00:00
default_matrix = ' mobile ' if default_matrix == ' enterprise ' else ' enterprise '
2019-08-01 13:02:06 +00:00
elif choice == ' 2 ' :
get_statistics_data_sources ( )
2019-08-21 13:12:12 +00:00
_wait ( )
2019-08-01 13:02:06 +00:00
elif choice == ' 3 ' :
get_statistics_mitigations ( default_matrix )
2019-08-21 13:12:12 +00:00
_wait ( )
2019-08-01 13:02:06 +00:00
elif choice == ' 9 ' :
interactive_menu ( )
2019-08-21 13:12:12 +00:00
_wait ( )
2019-08-01 13:02:06 +00:00
elif choice == ' q ' :
quit ( )
_menu_statistics ( )
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _menu_data_source ( filename_ds ) :
2019-03-29 14:26:25 +00:00
"""
Prints and handles the Data source mapping functionality .
2019-07-31 08:20:21 +00:00
: param filename_ds :
2019-03-29 14:26:25 +00:00
: return :
"""
2019-12-09 14:26:48 +00:00
global eql_query_data_sources , yaml_all_techniques
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: %s ' % MENU_NAME_DATA_SOURCE_MAPPING )
print ( ' ' )
2019-07-31 08:20:21 +00:00
print ( ' Selected data source YAML file: %s ' % filename_ds )
2019-03-29 14:26:25 +00:00
print ( ' ' )
2019-08-13 12:30:43 +00:00
print ( ' Options: ' )
eql_ds_str = ' ' if not eql_query_data_sources else eql_query_data_sources
print ( ' 1. Only include data sources which match the provided EQL query: ' + eql_ds_str )
2019-12-11 09:43:08 +00:00
print ( ' 2. Include all ATT&CK techniques in the generated YAML file that apply to the platform(s) '
2019-12-09 14:26:48 +00:00
' specified in the data source YAML file: ' + str ( yaml_all_techniques ) )
2019-08-13 12:30:43 +00:00
print ( ' ' )
2019-03-29 14:26:25 +00:00
print ( ' Select what you want to do: ' )
2019-12-09 14:26:48 +00:00
print ( ' 3. Generate a data source layer for the ATT&CK Navigator. ' )
print ( ' 4. Generate a graph with data sources added through time. ' )
print ( ' 5. Generate an Excel sheet with all data sources. ' )
print ( ' 6. Generate a technique administration YAML file with visibility scores, based on the number of available '
2019-03-29 14:26:25 +00:00
' data sources ' )
2019-12-09 14:26:48 +00:00
print ( ' 7. update the visibility scores within a technique administration YAML file based on changes within any of '
2019-07-31 08:20:21 +00:00
' the data sources. \n Past visibility scores are preserved in the score_logbook, and manually assigned scores are '
' not updated without your approval. \n The updated visibility are based on the number of available data sources. ' )
2019-12-09 14:26:48 +00:00
print ( ' 8. Check the data sources YAML file for errors. ' )
2019-03-29 14:26:25 +00:00
print ( ' 9. Back to main menu. ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
2019-08-13 12:30:43 +00:00
print ( ' Specify the EQL query for data source objects: ' )
eql_query_data_sources = _ask_input ( ) . lower ( )
2019-12-09 14:26:48 +00:00
elif choice == ' 2 ' :
yaml_all_techniques = not yaml_all_techniques
2019-08-13 12:30:43 +00:00
2019-12-09 14:26:48 +00:00
elif choice in [ ' 3 ' , ' 4 ' , ' 5 ' , ' 6 ' ] :
2019-08-13 12:30:43 +00:00
file_ds = filename_ds
if eql_query_data_sources :
2019-11-19 10:28:01 +00:00
file_ds = data_source_search ( filename_ds , eql_query_data_sources )
2019-08-13 12:30:43 +00:00
if not file_ds :
_wait ( ) # something went wrong in executing the search or 0 results where returned
_menu_data_source ( filename_ds )
2019-12-09 14:26:48 +00:00
if choice == ' 3 ' :
2019-08-13 12:30:43 +00:00
print ( ' Writing data sources layer... ' )
2020-06-08 14:56:56 +00:00
generate_data_sources_layer ( file_ds , None , None )
2019-08-13 12:30:43 +00:00
_wait ( )
2019-12-09 14:26:48 +00:00
elif choice == ' 4 ' :
2019-08-13 12:30:43 +00:00
print ( ' Drawing the graph... ' )
2020-05-25 09:44:13 +00:00
plot_data_sources_graph ( file_ds , None )
2019-08-13 12:30:43 +00:00
_wait ( )
2019-12-09 14:26:48 +00:00
elif choice == ' 5 ' :
2019-08-13 12:30:43 +00:00
print ( ' Generating Excel file... ' )
2020-05-25 09:44:13 +00:00
export_data_source_list_to_excel ( file_ds , None , eql_search = eql_query_data_sources )
2019-08-13 12:30:43 +00:00
_wait ( )
2019-12-09 14:26:48 +00:00
elif choice == ' 6 ' :
2019-08-13 12:30:43 +00:00
print ( ' Generating YAML file... ' )
2020-05-25 09:44:13 +00:00
generate_technique_administration_file ( file_ds , None , all_techniques = yaml_all_techniques )
2019-08-13 12:30:43 +00:00
_wait ( )
2019-12-09 14:26:48 +00:00
elif choice == ' 7 ' :
2019-07-31 08:20:21 +00:00
filename_t = _select_file ( MENU_NAME_DETECTION_COVERAGE_MAPPING , ' techniques (used to score the level of visibility) ' ,
FILE_TYPE_TECHNIQUE_ADMINISTRATION , False )
print ( ' Updating visibility scores... ' )
update_technique_administration_file ( filename_ds , filename_t )
_wait ( )
2019-12-09 14:26:48 +00:00
elif choice == ' 8 ' :
2019-08-20 09:14:07 +00:00
print ( ' Checking the data source YAML for errors... ' )
check_yaml_file_health ( filename_ds , FILE_TYPE_DATA_SOURCE_ADMINISTRATION , health_is_called = True )
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 9 ' :
interactive_menu ( )
elif choice == ' q ' :
quit ( )
2019-07-31 08:20:21 +00:00
_menu_data_source ( filename_ds )
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _menu_detection ( filename_t ) :
2019-03-29 14:26:25 +00:00
"""
Prints and handles the Detection coverage mapping functionality .
: param filename_t :
: return :
"""
2019-08-13 12:30:43 +00:00
global eql_all_scores , eql_query_detection , eql_query_visibility
filename_str = filename_t
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: %s ' % MENU_NAME_DETECTION_COVERAGE_MAPPING )
print ( ' ' )
2019-08-13 12:30:43 +00:00
print ( ' Selected techniques YAML file: %s ' % filename_str )
2019-03-29 14:26:25 +00:00
print ( ' ' )
2019-04-18 13:32:35 +00:00
print ( ' Options: ' )
2019-08-13 12:30:43 +00:00
eql_d_str = ' ' if not eql_query_detection else eql_query_detection
eql_v_str = ' ' if not eql_query_visibility else eql_query_visibility
print ( ' 1. Only include detection objects which match the EQL query: ' + eql_d_str )
print ( ' 2. Only include visibility objects which match the EQL query: ' + eql_v_str )
print ( ' 3. Include all \' score \' objects from the \' score_logbook \' in the EQL search: ' + str ( eql_all_scores ) )
2019-04-18 13:32:35 +00:00
print ( ' ' )
2019-03-29 14:26:25 +00:00
print ( ' Select what you want to do: ' )
2019-08-13 12:30:43 +00:00
print ( ' 4. Generate a layer for detection coverage for the ATT&CK Navigator. ' )
print ( ' 5. Generate a layer for detection coverage overlaid with visibility for the ATT&CK Navigator. ' )
2019-08-20 09:14:07 +00:00
print ( ' 6. Generate a graph with detections added through time. ' )
2019-08-13 12:30:43 +00:00
print ( ' 7. Generate an Excel sheet with all administrated techniques. ' )
print ( ' 8. Check the technique YAML file for errors. ' )
2019-03-29 14:26:25 +00:00
print ( ' 9. Back to main menu. ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
2019-08-13 12:30:43 +00:00
print ( ' Specify the EQL query for detection objects: ' )
eql_query_detection = _ask_input ( ) . lower ( )
2019-04-18 13:32:35 +00:00
elif choice == ' 2 ' :
2019-08-13 12:30:43 +00:00
print ( ' Specify the EQL query for visibility objects: ' )
eql_query_visibility = _ask_input ( ) . lower ( )
2019-04-18 13:32:35 +00:00
elif choice == ' 3 ' :
2019-08-21 13:12:12 +00:00
eql_all_scores = not eql_all_scores
2019-08-13 12:30:43 +00:00
elif choice in [ ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' ] :
file_tech = filename_t
if eql_query_detection or eql_query_visibility :
file_tech = techniques_search ( filename_t , eql_query_visibility , eql_query_detection ,
include_all_score_objs = eql_all_scores )
if not file_tech :
_wait ( ) # something went wrong in executing the search or 0 results where returned
_menu_detection ( filename_t )
if choice == ' 4 ' :
print ( ' Writing detection coverage layer... ' )
2020-06-08 14:56:56 +00:00
generate_detection_layer ( file_tech , None , False , None , None )
2019-08-13 12:30:43 +00:00
_wait ( )
elif choice == ' 5 ' :
filename_ds = _select_file ( MENU_NAME_DETECTION_COVERAGE_MAPPING , ' data sources (used to add metadata on the '
' involved data sources to the heat map) ' ,
FILE_TYPE_DATA_SOURCE_ADMINISTRATION , False )
print ( ' Writing detection coverage layer with visibility as overlay... ' )
2020-06-08 14:56:56 +00:00
generate_detection_layer ( file_tech , filename_ds , True , None , None )
2019-08-13 12:30:43 +00:00
_wait ( )
elif choice == ' 6 ' :
print ( ' Drawing the graph... ' )
2020-05-25 09:44:13 +00:00
plot_graph ( file_tech , ' detection ' , None )
2019-08-13 12:30:43 +00:00
_wait ( )
elif choice == ' 7 ' :
print ( ' Generating Excel file... ' )
2020-05-25 09:44:13 +00:00
export_techniques_list_to_excel ( file_tech , None )
2019-08-13 12:30:43 +00:00
_wait ( )
2019-08-20 09:14:07 +00:00
elif choice == ' 8 ' :
2019-05-17 12:08:17 +00:00
print ( ' Checking the technique YAML file for errors... ' )
2019-05-19 12:10:25 +00:00
check_yaml_file_health ( filename_t , FILE_TYPE_TECHNIQUE_ADMINISTRATION , health_is_called = True )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 9 ' :
interactive_menu ( )
elif choice == ' q ' :
quit ( )
2019-07-31 08:20:21 +00:00
_menu_detection ( filename_t )
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _menu_visibility ( filename_t , filename_ds ) :
2019-03-29 14:26:25 +00:00
"""
2019-07-13 12:42:29 +00:00
Prints and handles the Visibility coverage mapping functionality .
2019-03-29 14:26:25 +00:00
: param filename_t :
: param filename_ds :
: return :
"""
2019-08-13 12:30:43 +00:00
global eql_all_scores , eql_query_detection , eql_query_visibility
filename_str = filename_t
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: %s ' % MENU_NAME_VISIBILITY_MAPPING )
print ( ' ' )
2019-08-13 12:30:43 +00:00
print ( ' Selected techniques YAML file: %s ' % filename_str )
2019-03-29 14:26:25 +00:00
print ( ' Selected data source YAML file: %s ' % filename_ds )
print ( ' ' )
2019-04-23 13:43:28 +00:00
print ( ' Options: ' )
2019-08-13 12:30:43 +00:00
eql_d_str = ' ' if not eql_query_detection else eql_query_detection
eql_v_str = ' ' if not eql_query_visibility else eql_query_visibility
print ( ' 1. Only include visibility objects which match the EQL query: ' + eql_v_str )
print ( ' 2. Only include detection objects which match the EQL query: ' + eql_d_str )
print ( ' 3. Include all \' score \' objects from the \' score_logbook \' in the EQL search: ' + str ( eql_all_scores ) )
2019-04-23 13:43:28 +00:00
print ( ' ' )
2019-03-29 14:26:25 +00:00
print ( ' Select what you want to do: ' )
2019-08-13 12:30:43 +00:00
print ( ' 4. Generate a layer for visibility for the ATT&CK Navigator. ' )
print ( ' 5. Generate a layer for visibility overlaid with detection coverage for the ATT&CK Navigator. ' )
2019-08-20 09:14:07 +00:00
print ( ' 6. Generate a graph with visibility added through time. ' )
2019-08-15 14:00:06 +00:00
print ( ' 7. Generate an Excel sheet with all administrated techniques. ' )
print ( ' 8. Check the technique YAML file for errors. ' )
2019-03-29 14:26:25 +00:00
print ( ' 9. Back to main menu. ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
2019-08-13 12:30:43 +00:00
print ( ' Specify the EQL query for visibility objects: ' )
eql_query_visibility = _ask_input ( ) . lower ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 2 ' :
2019-08-13 12:30:43 +00:00
print ( ' Specify the EQL query for detection objects: ' )
eql_query_detection = _ask_input ( ) . lower ( )
2019-04-10 08:08:30 +00:00
elif choice == ' 3 ' :
2019-08-21 13:12:12 +00:00
eql_all_scores = not eql_all_scores
2019-08-13 12:30:43 +00:00
elif choice in [ ' 4 ' , ' 5 ' , ' 6 ' , ' 7 ' ] :
file_tech = filename_t
if eql_query_detection or eql_query_visibility :
file_tech = techniques_search ( filename_t , eql_query_visibility , eql_query_detection ,
include_all_score_objs = eql_all_scores )
if not file_tech :
_wait ( ) # something went wrong in executing the search or 0 results where returned
_menu_visibility ( filename_t , filename_ds )
if choice == ' 4 ' :
print ( ' Writing visibility coverage layer... ' )
2020-06-08 14:56:56 +00:00
generate_visibility_layer ( file_tech , filename_ds , False , None , None )
2019-08-13 12:30:43 +00:00
_wait ( )
elif choice == ' 5 ' :
print ( ' Writing visibility coverage layer overlaid with detections... ' )
2020-06-08 14:56:56 +00:00
generate_visibility_layer ( file_tech , filename_ds , True , None , None )
2019-08-13 12:30:43 +00:00
_wait ( )
elif choice == ' 6 ' :
2019-08-15 14:00:06 +00:00
print ( ' Drawing the graph... ' )
2020-05-25 09:44:13 +00:00
plot_graph ( file_tech , ' visibility ' , None )
2019-08-15 14:00:06 +00:00
_wait ( )
elif choice == ' 7 ' :
2019-08-13 12:30:43 +00:00
print ( ' Generating Excel file... ' )
2020-05-25 09:44:13 +00:00
export_techniques_list_to_excel ( file_tech , None )
2019-08-13 12:30:43 +00:00
_wait ( )
2019-08-15 14:00:06 +00:00
elif choice == ' 8 ' :
2019-08-13 12:30:43 +00:00
print ( ' Checking the technique YAML file for errors... ' )
check_yaml_file_health ( file_tech , FILE_TYPE_TECHNIQUE_ADMINISTRATION , health_is_called = True )
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 9 ' :
interactive_menu ( )
elif choice == ' q ' :
quit ( )
2019-07-31 08:20:21 +00:00
_menu_visibility ( filename_t , filename_ds )
2019-03-29 14:26:25 +00:00
2019-07-31 08:20:21 +00:00
def _menu_groups ( ) :
2019-03-29 14:26:25 +00:00
"""
Prints and handles the Threat actor group mapping functionality .
: return :
"""
2019-08-13 12:30:43 +00:00
global groups , software_group , default_platform , default_stage , groups_overlay , overlay_type , eql_all_scores , \
eql_query_detection , eql_query_visibility
2019-07-31 08:20:21 +00:00
_clear ( )
2019-03-29 14:26:25 +00:00
print ( ' Menu: %s ' % MENU_NAME_THREAT_ACTOR_GROUP_MAPPING )
print ( ' ' )
print ( ' Options: ' )
print ( ' 1. Software group: %s ' % str ( software_group ) )
2020-10-15 09:03:36 +00:00
print ( ' 2. Platform: %s ' % ' , ' . join ( default_platform ) )
2019-08-01 13:02:06 +00:00
print ( ' 3. Stage: %s ' % default_stage )
2019-03-29 14:26:25 +00:00
print ( ' 4. Groups: %s ' % groups )
print ( ' 5. Overlay: ' )
print ( ' - %s : %s ' % ( ' File ' if os . path . exists ( groups_overlay ) else ' Groups ' , groups_overlay ) )
print ( ' - Type: %s ' % overlay_type )
2019-08-13 12:30:43 +00:00
print ( ' 6. EQL search: ' )
eql_d_str = ' ' if not eql_query_detection else eql_query_detection
eql_v_str = ' ' if not eql_query_visibility else eql_query_visibility
print ( ' - Only include detection objects which match the EQL query: ' + eql_d_str )
print ( ' - Only include visibility objects which match the EQL query: ' + eql_v_str )
print ( ' - Include all \' score \' objects from the \' score_logbook \' in the EQL search: ' + str ( eql_all_scores ) )
2019-03-29 14:26:25 +00:00
print ( ' ' )
2019-08-13 12:30:43 +00:00
print ( ' Select what you want to do: ' )
2019-04-24 14:15:04 +00:00
print ( ' 7. Generate a heat map layer. ' )
2019-03-29 14:26:25 +00:00
print ( ' 9. Back to main menu. ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
2019-08-21 13:12:12 +00:00
software_group = not software_group
2019-03-29 14:26:25 +00:00
elif choice == ' 2 ' :
2019-11-04 13:48:58 +00:00
print ( ' Specify platform ( %s ): ' % ' , ' . join ( [ ' all ' ] + list ( PLATFORMS . values ( ) ) ) )
2019-07-31 08:20:21 +00:00
p = _ask_input ( ) . lower ( )
2020-10-15 09:03:36 +00:00
default_platform = [ PLATFORMS [ p ] ] if p in PLATFORMS . keys ( ) else [ ' all ' ]
2019-03-29 14:26:25 +00:00
elif choice == ' 3 ' :
print ( ' Specify stage (pre-attack, attack): ' )
2019-07-31 08:20:21 +00:00
s = _ask_input ( ) . lower ( )
2019-08-01 13:02:06 +00:00
default_stage = ' pre-attack ' if s == ' pre-attack ' else ' attack '
2019-03-29 14:26:25 +00:00
elif choice == ' 4 ' :
print ( ' Specify the groups to include separated using commas. Group can be their ID, name or alias '
' (default is all groups). Other option is to provide a YAML file with a custom group(s) ' )
2019-07-31 08:20:21 +00:00
g = _ask_input ( )
2019-12-05 09:43:07 +00:00
groups = g if g != ' ' else ' all '
2019-03-29 14:26:25 +00:00
elif choice == ' 5 ' :
print ( ' ' )
print ( ' 1. Overlay with groups. ' )
print ( ' 2. Overlay with detections. ' )
print ( ' 3. Overlay with visibility. ' )
print ( ' 4. No overlay. ' )
2019-07-31 08:20:21 +00:00
choice = _ask_input ( )
2019-03-29 14:26:25 +00:00
if choice == ' 1 ' :
print ( ' Specify the group(s) to overlay (in a different color) on the one specified in the Groups option. '
' A group can be their ID, name or alias separated using commas. Other option is to provide a YAML '
' file with a custom group(s). ' )
2019-05-02 18:15:43 +00:00
overlay_type = OVERLAY_TYPE_GROUP
2019-07-31 08:20:21 +00:00
groups_overlay = _ask_input ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 2 ' :
2019-05-02 18:15:43 +00:00
overlay_type = OVERLAY_TYPE_DETECTION
2019-07-31 08:20:21 +00:00
groups_overlay = _select_file ( MENU_NAME_THREAT_ACTOR_GROUP_MAPPING , ' techniques ' , FILE_TYPE_TECHNIQUE_ADMINISTRATION , False )
2019-03-29 14:26:25 +00:00
elif choice == ' 3 ' :
2019-05-02 18:15:43 +00:00
overlay_type = OVERLAY_TYPE_VISIBILITY
2019-07-31 08:20:21 +00:00
groups_overlay = _select_file ( MENU_NAME_THREAT_ACTOR_GROUP_MAPPING , ' techniques ' , FILE_TYPE_TECHNIQUE_ADMINISTRATION , False )
2019-03-29 14:26:25 +00:00
elif choice == ' 4 ' :
overlay_type = ' '
groups_overlay = ' '
elif choice == ' 6 ' :
2019-08-13 12:30:43 +00:00
print ( ' ' )
print ( ' 1. Only include detection objects which match the EQL query: ' + eql_d_str )
print ( ' 2. Only include visibility objects which match the EQL query: ' + eql_v_str )
print ( ' 3. Include all \' score \' objects from the \' score_logbook \' in the EQL search: ' + str ( eql_all_scores ) )
choice = _ask_input ( )
if choice == ' 1 ' :
print ( ' Specify the EQL query for detection objects: ' )
eql_query_detection = _ask_input ( ) . lower ( )
elif choice == ' 2 ' :
print ( ' Specify the EQL query for visibility objects: ' )
eql_query_visibility = _ask_input ( ) . lower ( )
elif choice == ' 3 ' :
2019-08-21 13:12:12 +00:00
eql_all_scores = not eql_all_scores
2019-08-13 12:30:43 +00:00
2019-04-24 14:15:04 +00:00
elif choice == ' 7 ' :
2020-06-19 07:22:54 +00:00
generate_group_heat_map ( groups , groups_overlay , overlay_type , default_stage , default_platform ,
software_group , eql_query_visibility , eql_query_detection , False ,
None , None , include_all_score_objs = eql_all_scores )
2019-07-31 08:20:21 +00:00
_wait ( )
2019-03-29 14:26:25 +00:00
elif choice == ' 9 ' :
interactive_menu ( )
elif choice == ' q ' :
quit ( )
2019-07-31 08:20:21 +00:00
_menu_groups ( )