AegisShield integrates with MITRE ATT&CK®, the globally-accessible knowledge base of adversary tactics and techniques. Unlike the NVD and OTX integrations which use external APIs, the MITRE ATT&CK integration loads STIX 2.0 data from local JSON files, enabling offline threat analysis and technique mapping.
The data loading function intelligently combines matrices:
mitre_attack.py
def fetch_mitre_attack_data(app_type): logger.info(f"Fetching MITRE ATT&CK data for app_type: {app_type}") try: if app_type in MOBILE_APP_TYPES: with open("./MITRE_ATTACK_DATA/mobile-attack.json") as mobile_file, open( "./MITRE_ATTACK_DATA/enterprise-attack.json" ) as enterprise_file: mobile_data = json.load(mobile_file) enterprise_data = json.load(enterprise_file) stix_data = enterprise_data stix_data["objects"].extend(mobile_data["objects"]) logger.info("Successfully loaded mobile and enterprise attack data") elif app_type in ENTERPRISE_APP_TYPES: with open("./MITRE_ATTACK_DATA/enterprise-attack.json") as file: stix_data = json.load(file) logger.info("Successfully loaded enterprise attack data") elif app_type in ICS_APP_TYPES: with open("./MITRE_ATTACK_DATA/ics-attack.json") as ics_file, open( "./MITRE_ATTACK_DATA/enterprise-attack.json" ) as enterprise_file: ics_data = json.load(ics_file) enterprise_data = json.load(enterprise_file) stix_data = enterprise_data stix_data["objects"].extend(ics_data["objects"]) logger.info("Successfully loaded ICS and enterprise attack data") else: # Default to enterprise for unknown types with open("./MITRE_ATTACK_DATA/enterprise-attack.json") as file: stix_data = json.load(file) logger.info("Successfully loaded enterprise attack data") return stix_data except FileNotFoundError as e: handle_exception(e, "Required MITRE ATT&CK data file not found") except json.JSONDecodeError as e: handle_exception(e, "Invalid JSON format in MITRE ATT&CK data file")
Mobile and ICS applications automatically include enterprise techniques, providing comprehensive coverage.
STIX uses internal attack-pattern IDs, but users need human-readable technique IDs (T-codes):
mitre_attack.py
def map_attack_pattern_to_technique(stix_data): """Map attack pattern IDs to MITRE ATT&CK technique IDs (T####).""" logger.info("Starting attack pattern to technique mapping") attack_pattern_to_technique = {} try: if not stix_data or 'objects' not in stix_data: logger.warning("No objects found in STIX data") return attack_pattern_to_technique # Iterate through each object in the STIX data for obj in stix_data.get('objects', []): if obj.get('type') == 'attack-pattern': attack_pattern_id = obj.get('id') if not attack_pattern_id: logger.warning("Found attack pattern object without ID") continue external_refs = obj.get('external_references', []) # Loop through external references to find the MITRE ATT&CK technique ID for ref in external_refs: if ref.get('source_name') == 'mitre-attack' and 'external_id' in ref: technique_id = ref['external_id'] # Technique ID (T####) attack_pattern_to_technique[attack_pattern_id] = technique_id break logger.info(f"Successfully mapped {len(attack_pattern_to_technique)} attack patterns to techniques") return attack_pattern_to_technique except Exception as e: handle_exception(e, "Error mapping attack patterns to techniques")
The integration matches threats to techniques using keywords:
mitre_attack.py
for threat in threat_model: relevant_techniques = [] keywords = threat.get("MITRE ATT&CK Keywords", []) if not keywords: processed_data.append({ "threat": threat, "mitre_techniques": [], }) continue # Match relevant attack patterns based on keywords for obj in stix_data["objects"]: if obj["type"] == "attack-pattern": name = obj.get("name", "").lower() description = obj.get("description", "").lower() # Check if any keyword matches the attack pattern name or description for keyword in keywords: if keyword.lower() in name or keyword.lower() in description: relevant_techniques.append({ "name": obj["name"], "description": obj.get("description", "No description available"), "id": obj["id"], }) break # Keep the top N relevant techniques relevant_techniques = relevant_techniques[:MAX_TECHNIQUES]
Once candidate techniques are identified, OpenAI selects the most relevant:
mitre_attack.py
# Configuration constantsMAX_TECHNIQUES = 25 # Maximum number of techniques to consider per threatRATE_LIMIT_SLEEP_MIN = 0 # Minimum seconds to sleep between API callsRATE_LIMIT_SLEEP_MAX = 5 # Maximum seconds to sleep between API calls# Create prompt and get the top technique using OpenAIprompt = create_mitre_prompt(app_details, threat, relevant_techniques)random_integer = random.randint(RATE_LIMIT_SLEEP_MIN, RATE_LIMIT_SLEEP_MAX)time.sleep(random_integer) # Alleviate OpenAI API rate limitingtop_1_id = get_relevant_techniques(prompt, openai_api_key)# Retrieve the corresponding MITRE ATT&CK Technique IDtechnique_id = attack_pattern_to_technique.get(top_1_id[0], "N/A")
The prompt includes application context and threat details:
mitre_attack.py
def create_mitre_prompt(app_details, threat, techniques): technique_descriptions = [ {"id": tech["id"], "name": tech["name"], "description": tech["description"]} for tech in techniques ] prompt = f"""You are to respond in a very specific format. Do not include any additional text, explanations, or context. Only output the JSON array as specified below.Act as a cybersecurity expert in the {app_details['industry_sector']} sector with more than 20 years of experience using the STRIDE threat modeling methodology.Your task is to analyze the following threat scenario and select the single most relevant MITRE ATT&CK attack pattern from the provided list of 25.APPLICATION TYPE: {app_details['app_type']}INDUSTRY SECTOR: {app_details['industry_sector']}AUTHENTICATION METHODS: {app_details['authentication']}INTERNET FACING: {app_details['internet_facing']}SENSITIVE DATA: {app_details['sensitive_data']}APPLICATION DESCRIPTION: {app_details['app_input']}Threat Scenario:{json.dumps(threat, indent=2)}MITRE ATT&CK Techniques:{json.dumps(technique_descriptions, indent=2)}Your response should **ONLY** include the single most relevant MITRE ATT&CK Attack Pattern ID from the above MITRE ATT&CK Techniques, in a JSON array format like this:["attack-pattern--xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"]If none of the provided techniques are a perfect match, select the closest one. If there truly is no relevant match, respond with ["attack-pattern--00000000-0000-0000-0000-000000000000"].""" return prompt
Example Prompt
Act as a cybersecurity expert in the Financial Services sector with more than 20 years of experience using the STRIDE threat modeling methodology.Your task is to analyze the following threat scenario and select the single most relevant MITRE ATT&CK attack pattern from the provided list of 25.APPLICATION TYPE: Web applicationINDUSTRY SECTOR: Financial ServicesAUTHENTICATION METHODS: OAuth 2.0, MFAINTERNET FACING: YesSENSITIVE DATA: Customer PII, Financial RecordsAPPLICATION DESCRIPTION: Online banking platform with account management and transaction capabilitiesThreat Scenario:{ "Threat": "SQL Injection", "STRIDE Category": "Tampering", "MITRE ATT&CK Keywords": ["injection", "database", "sql"]}MITRE ATT&CK Techniques:[ { "id": "attack-pattern--...", "name": "Exploit Public-Facing Application", "description": "Adversaries may attempt to exploit weaknesses in Internet-facing applications..." }, ...]
try: with open("./MITRE_ATTACK_DATA/enterprise-attack.json") as file: stix_data = json.load(file)except FileNotFoundError as e: handle_exception(e, "Required MITRE ATT&CK data file not found")except json.JSONDecodeError as e: handle_exception(e, "Invalid JSON format in MITRE ATT&CK data file")