{description}
+{description}
+{description}
+ This is the official documentation for the ATT&CK Data Model library. +
++ Get up and running with ATT&CK data in minutes +
+npm install @mitre-attack/attack-data-model
+ {`import { registerDataSource, loadDataModel } from '@mitre-attack/attack-data-model';
+
+const uuid = await registerDataSource(dataSource);
+const attackModel = loadDataModel(uuid);`}
+ Documentation
+MITRE ATT&CKยฎ Data Model
C:\\Windows\\System32\\ by default) of a domain controller and/or local computer with a corresponding entry in HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Lsa\\Notification Packages. (Citation: Microsoft Install Password Filter n.d)",
- x_mitre_deprecated: true,
- x_mitre_version: "1.0",
- x_mitre_modified_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- spec_version: "2.1",
- x_mitre_attack_spec_version: "2.1.0",
-};
-
-console.log("\nExample 5 - Parsing the provided example mitigation:");
-const e5 = mitigationSchema.safeParse(exampleOfRealMitigation);
-if (e5.success) {
- console.log("Parsed successfully. Mitigation name:", e5.data.name);
-} else {
- console.log(z.prettifyError(e5.error as z.core.$ZodError));
-}
-
-/** ************************************************************************************************* */
-// Example 6: Mitigation with unknown property
-/** ************************************************************************************************* */
-const mitigationWithUnknownProperty = {
- ...validMitigation,
- foo: 'bar'
-}
-
-console.log("\nExample 6 - Parsing a mitigation with an unknown property (foo: 'bar'):");
-const e6 = mitigationSchema.safeParse(mitigationWithUnknownProperty);
-if (e6.success) {
- console.log("Parsed successfully. Mitigation name:", e6.data.name);
-} else {
- console.log(z.prettifyError(e6.error as z.core.$ZodError));
-}
\ No newline at end of file
diff --git a/examples/sdo/software.example.ts b/examples/sdo/software.example.ts
deleted file mode 100644
index 659cba6c..00000000
--- a/examples/sdo/software.example.ts
+++ /dev/null
@@ -1,490 +0,0 @@
-import { z } from "zod/v4";
-import { malwareSchema } from "../../src/schemas/sdo/malware.schema.js";
-import { toolSchema } from "../../src/schemas/sdo/tool.schema.js";
-
-// Malware Examples -
-console.log("****************************************************************************************************")
-console.log("Malware Examples")
-console.log("****************************************************************************************************")
-/** ************************************************************************************************* */
-// Example 1: Valid Malware
-/** ************************************************************************************************* */
-
-const validMalware = {
- type: 'malware',
- id: 'malware--2daa14d6-cbf3-4308-bb8e-213c324a08e4',
- spec_version: '2.1',
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- created: "2017-05-31T21:32:29.203Z",
- modified: "2021-02-09T13:58:23.806Z",
- name: "HAMMERTOSS",
- description: "[HAMMERTOSS](https://attack.mitre.org/software/S0037) is a backdoor that was used by [APT29](https://attack.mitre.org/groups/G0016) in 2015. (Citation: FireEye APT29) (Citation: F-Secure The Dukes)",
- external_references: [
- {
- source_name: "mitre-attack",
- url: "https://attack.mitre.org/software/S0037",
- external_id: "S0037"
- },
- {
- source_name: "FireEye APT29",
- description: "FireEye Labs. (2015, July). HAMMERTOSS: Stealthy Tactics Define a Russian Cyber Threat Group. Retrieved September 17, 2015.",
- url: "https://www2.fireeye.com/rs/848-DID-242/images/rpt-apt29-hammertoss.pdf"
- },
- {
- source_name: "F-Secure The Dukes",
- description: "F-Secure Labs. (2015, September 17). The Dukes: 7 years of Russian cyberespionage. Retrieved December 10, 2015.",
- url: "https://www.f-secure.com/documents/996508/1030745/dukes_whitepaper.pdf"
- }
- ],
- object_marking_refs: [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- x_mitre_attack_spec_version: "2.1.0",
- x_mitre_domains: [
- "enterprise-attack"
- ],
- x_mitre_modified_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- is_family: false,
- x_mitre_version: "1.2"
-};
-
-console.log("Example 1 - Valid Malware:");
-console.log(malwareSchema.parse(validMalware));
-
-/** ************************************************************************************************* */
-// Example 2: Invalid Malware (missing required fields)
-/** ************************************************************************************************* */
-
-const invalidMalware = {
- type: 'malware',
- id: 'malware--2daa14d6-cbf3-4308-bb8e-213c324a08e4',
- spec_version: '2.1',
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- created: "2017-05-31T21:32:29.203Z",
- modified: "2021-02-09T13:58:23.806Z",
- name: "HAMMERTOSS",
- description: "[HAMMERTOSS](https://attack.mitre.org/software/S0037) is a backdoor that was used by [APT29](https://attack.mitre.org/groups/G0016) in 2015. (Citation: FireEye APT29) (Citation: F-Secure The Dukes)",
- external_references: [
- {
- source_name: "mitre-attack",
- url: "https://attack.mitre.org/software/S0037",
- external_id: "S0037"
- },
- {
- source_name: "FireEye APT29",
- description: "FireEye Labs. (2015, July). HAMMERTOSS: Stealthy Tactics Define a Russian Cyber Threat Group. Retrieved September 17, 2015.",
- url: "https://www2.fireeye.com/rs/848-DID-242/images/rpt-apt29-hammertoss.pdf"
- },
- {
- source_name: "F-Secure The Dukes",
- description: "F-Secure Labs. (2015, September 17). The Dukes: 7 years of Russian cyberespionage. Retrieved December 10, 2015.",
- url: "https://www.f-secure.com/documents/996508/1030745/dukes_whitepaper.pdf"
- }
- ],
- x_mitre_aliases: [
- "HAMMERTOSS",
- "HammerDuke",
- "NetDuke"
- ],
- x_mitre_attack_spec_version: "2.1.0",
- x_mitre_domains: [
- "enterprise-attack"
- ],
- x_mitre_platforms: [
- "Windows"
- ],
- x_mitre_version: "1.2"
-};
-
-console.log("Example 2 - Invalid Malware (missing required fields):");
-const e2 = malwareSchema.safeParse(invalidMalware);
-console.log(z.prettifyError(e2.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 3: Malware with optional fields
-/** ************************************************************************************************* */
-const malwareWithOptionalFields = {
- ...validMalware,
- x_mitre_aliases: [
- "HAMMERTOSS",
- "HammerDuke",
- "NetDuke"
- ],
- x_mitre_platforms: [
- "Windows"
- ],
- x_mitre_contributors: ["Contributor"],
- x_mitre_deprecated: false,
- x_mitre_old_attack_id: "MOB-S0123"
-};
-
-console.log("\nExample 3 - Malware with optional fields:");
-console.log(malwareSchema.parse(malwareWithOptionalFields));
-
-/** ************************************************************************************************* */
-// Example 4: Malware with invalid type
-/** ************************************************************************************************* */
-const malwareWithInvalidType = {
- ...validMalware,
- type: "invalid-type",
-};
-
-console.log("\nExample 4 - Malware with invalid type:");
-const e4 = malwareSchema.safeParse(malwareWithInvalidType);
-console.log(z.prettifyError(e4.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 5: Malware with invalid id
-/** ************************************************************************************************* */
-const malwareWithInvalidId = {
- ...validMalware,
- id: 'tool--11f8d7eb-1927-4806-9267-3a11d4d4d6be',
-};
-
-console.log("\nExample 5 - Malware with invalid id:");
-const e5 = malwareSchema.safeParse(malwareWithInvalidId);
-console.log(z.prettifyError(e5.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 6: Malware with fields in STIX but not in ATT&CK
-/** ************************************************************************************************* */
-const malwareWithStixFields = {
- ...validMalware,
- kill_chain_phases: [
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "command-and-control"
- }
- ],
- aliases: [
- "HAMMERTOSS",
- "HammerDuke",
- "NetDuke"
- ],
- first_seen: "2015-07-01T00:00:00.000Z",
- last_seen: "2016-07-01T00:00:00.000Z",
- malware_types: ["remote-access-trojan"],
- os_execution_envs: [
- "Windows",
- "Linux"
- ],
- architecture_execution_envs: [
- "x86"
- ],
- capabilities: [
- "exfiltrates-data",
- "accesses-remote-machines"
- ],
- sample_refs: [
- "file--a3b8b3b2-4d2f-4a2e-9a1b-1c8b3e4e6f5d"
- ],
- implementation_languages: [
- "python"
- ]
-};
-
-console.log("\nExample 6 - Malware with fields in STIX but not in ATT&CK:");
-console.log(malwareSchema.parse(malwareWithStixFields));
-
-/** ************************************************************************************************* */
-// Example 7: Parsing the provided example malware
-/** ************************************************************************************************* */
-
-const exampleOfRealMalware = {
- "type": "malware",
- "id": "malware--2daa14d6-cbf3-4308-bb8e-213c324a08e4",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "created": "2017-05-31T21:32:29.203Z",
- "modified": "2021-02-09T13:58:23.806Z",
- "name": "HAMMERTOSS",
- "description": "[HAMMERTOSS](https://attack.mitre.org/software/S0037) is a backdoor that was used by [APT29](https://attack.mitre.org/groups/G0016) in 2015. (Citation: FireEye APT29) (Citation: F-Secure The Dukes)",
- "labels": [
- "malware"
- ],
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/software/S0037",
- "external_id": "S0037"
- },
- {
- "source_name": "FireEye APT29",
- "description": "FireEye Labs. (2015, July). HAMMERTOSS: Stealthy Tactics Define a Russian Cyber Threat Group. Retrieved September 17, 2015.",
- "url": "https://www2.fireeye.com/rs/848-DID-242/images/rpt-apt29-hammertoss.pdf"
- },
- {
- "source_name": "F-Secure The Dukes",
- "description": "F-Secure Labs. (2015, September 17). The Dukes: 7 years of Russian cyberespionage. Retrieved December 10, 2015.",
- "url": "https://www.f-secure.com/documents/996508/1030745/dukes_whitepaper.pdf"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_aliases": [
- "HAMMERTOSS",
- "HammerDuke",
- "NetDuke"
- ],
- "x_mitre_attack_spec_version": "2.1.0",
- "x_mitre_domains": [
- "enterprise-attack"
- ],
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "x_mitre_platforms": [
- "Windows"
- ],
- "x_mitre_version": "1.2",
- "spec_version": '2.1',
- "is_family": false
-}
-
-console.log("\nExample 7 - Parsing the provided example malware:");
-const e7 = malwareSchema.safeParse(exampleOfRealMalware);
-if (e7.success) {
- console.log(e7.data);
- console.log("Parsed successfully. Malware name:", e7.data.name);
-} else {
- console.log(z.prettifyError(e7.error as z.core.$ZodError));
-}
-
-/** ************************************************************************************************* */
-// Example 8: Malware with unknown property
-/** ************************************************************************************************* */
-const malwareWithUnknownProperty = {
- ...exampleOfRealMalware,
- foo: 'bar'
-}
-
-console.log("\nExample 8 - Parsing a malware with an unknown property (foo: 'bar'):");
-const e8 = malwareSchema.safeParse(malwareWithUnknownProperty);
-if (e8.success) {
- console.log("Parsed successfully. Malware name:", e8.data.name);
-} else {
- console.log(z.prettifyError(e8.error as z.core.$ZodError));
-}
-
-// Tool Examples -
-console.log("****************************************************************************************************")
-console.log("Tool Examples")
-console.log("****************************************************************************************************")
-
-/** ************************************************************************************************* */
-// Example 1: Valid Tool
-/** ************************************************************************************************* */
-
-const validTool = {
- type: 'tool',
- id: 'tool--11f8d7eb-1927-4806-9267-3a11d4d4d6be',
- spec_version: '2.1',
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- created: "2021-07-30T15:43:17.770Z",
- modified: "2024-04-11T00:06:01.264Z",
- name: "Sliver",
- description: '[Sliver](https://attack.mitre.org/software/S0633) is an open source, cross-platform, red team command and control framework written in Golang.(Citation: Bishop Fox Sliver Framework August 2019)',
- external_references: [
- {
- source_name: "mitre-attack",
- url: "https://attack.mitre.org/software/S0049",
- external_id: "S0049"
- },
- {
- source_name: "F-Secure The Dukes",
- description: "F-Secure Labs. (2015, September 17). The Dukes: 7 years of Russian cyberespionage. Retrieved December 10, 2015.",
- url: "https://www.f-secure.com/documents/996508/1030745/dukes_whitepaper.pdf"
- }
- ],
- object_marking_refs: [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- x_mitre_domains: [
- "enterprise-attack"
- ],
- x_mitre_modified_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- x_mitre_version: "1.2",
- x_mitre_attack_spec_version: "3.2.0"
-};
-
-console.log("Example 1 - Valid Tool:");
-console.log(toolSchema.parse(validTool));
-
-/** ************************************************************************************************* */
-// Example 2: Invalid Tool (missing required fields)
-/** ************************************************************************************************* */
-
-const invalidTool = {
- type: 'tool',
- id: 'tool--11f8d7eb-1927-4806-9267-3a11d4d4d6be',
- spec_version: '2.1',
- created: "2021-07-30T15:43:17.770Z",
- modified: "2024-04-11T00:06:01.264Z",
- name: "Sliver",
- description: '[Sliver](https://attack.mitre.org/software/S0633) is an open source, cross-platform, red team command and control framework written in Golang.(Citation: Bishop Fox Sliver Framework August 2019)',
- x_mitre_aliases: [
- "Sliver"
- ],
- x_mitre_contributors: [
- "Achute Sharma, Keysight",
- "Ayan Saha, Keysight"
- ],
- x_mitre_deprecated: false,
- x_mitre_domains: [
- "enterprise-attack"
- ],
- x_mitre_modified_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- x_mitre_platforms: [
- "Windows",
- "Linux",
- "macOS"
- ],
- x_mitre_version: "1.2"
-};
-
-console.log("Example 2 - Invalid Tool (missing required fields):");
-const et2 = toolSchema.safeParse(invalidTool);
-console.log(z.prettifyError(et2.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 3: Tool with optional fields
-/** ************************************************************************************************* */
-const toolWithOptionalFields = {
- ...validTool,
- x_mitre_contributors: [
- "Achute Sharma, Keysight",
- "Ayan Saha, Keysight"
- ],
- x_mitre_aliases: [
- "Sliver"
- ],
- x_mitre_deprecated: false,
- x_mitre_platforms: [
- "Windows",
- "Linux",
- "macOS"
- ]
-};
-
-console.log("\nExample 3 - Tool with optional fields:");
-console.log(toolSchema.parse(toolWithOptionalFields));
-
-/** ************************************************************************************************* */
-// Example 4: Tool with invalid type
-/** ************************************************************************************************* */
-const toolWithInvalidType = {
- ...validTool,
- type: "invalid-type",
-};
-
-console.log("\nExample 4 - Tool with invalid type:");
-const et4 = toolSchema.safeParse(toolWithInvalidType);
-console.log(z.prettifyError(et4.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 5: Tool with invalid id
-/** ************************************************************************************************* */
-const toolWithInvalidId = {
- ...validTool,
- id: 'malware--11f8d7eb-1927-4806-9267-3a11d4d4d6be',
-};
-
-console.log("\nExample 5 - Tool with invalid id:");
-const et5 = toolSchema.safeParse(toolWithInvalidId);
-console.log(z.prettifyError(et5.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 6: Tool with fields in STIX but not in ATT&CK
-/** ************************************************************************************************* */
-const toolWithStixFields = {
- ...validTool,
- kill_chain_phases: [
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "command-and-control"
- }
- ],
- aliases: [
- "Sliver"
- ],
- tool_types: ["remote-access"],
- tool_version: "1.0"
-};
-
-console.log("\nExample 6 - Tool with fields in STIX but not in ATT&CK:");
-console.log(toolSchema.parse(toolWithStixFields));
-
-/** ************************************************************************************************* */
-// Example 7: Parsing the provided example tool
-/** ************************************************************************************************* */
-
-const exampleOfRealTool = {
- "type": "tool",
- "id": "tool--11f8d7eb-1927-4806-9267-3a11d4d4d6be",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "created": "2021-07-30T15:43:17.770Z",
- "modified": "2024-04-11T00:06:01.264Z",
- "name": "Sliver",
- "description": "[Sliver](https://attack.mitre.org/software/S0633) is an open source, cross-platform, red team command and control framework written in Golang.(Citation: Bishop Fox Sliver Framework August 2019)",
- "labels": [
- "tool"
- ],
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/software/S0633",
- "external_id": "S0633"
- },
- {
- "source_name": "Bishop Fox Sliver Framework August 2019",
- "description": "Kervella, R. (2019, August 4). Cross-platform General Purpose Implant Framework Written in Golang. Retrieved July 30, 2021.",
- "url": "https://labs.bishopfox.com/tech-blog/sliver"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_aliases": [
- "Sliver"
- ],
- "x_mitre_attack_spec_version": "3.2.0",
- "x_mitre_contributors": [
- "Achute Sharma, Keysight",
- "Ayan Saha, Keysight"
- ],
- "x_mitre_deprecated": false,
- "x_mitre_domains": [
- "enterprise-attack"
- ],
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "x_mitre_platforms": [
- "Windows",
- "Linux",
- "macOS"
- ],
- "x_mitre_version": "1.2",
- "spec_version": "2.0"
-}
-
-console.log("\nExample 7 - Parsing the provided example tool:");
-const et7 = toolSchema.safeParse(exampleOfRealTool);
-if (et7.success) {
- console.log(et7.data);
- console.log("Parsed successfully. Tool name:", et7.data.name);
-} else {
- console.log(z.prettifyError(et7.error as z.core.$ZodError));
-}
-
-/** ************************************************************************************************* */
-// Example 8: Tool with unknown property
-/** ************************************************************************************************* */
-const toolWithUnknownProperty = {
- ...exampleOfRealTool,
- foo: 'bar'
-}
-
-console.log("\nExample 8 - Parsing a tool with an unknown property (foo: 'bar'):");
-const et8 = toolSchema.safeParse(toolWithUnknownProperty);
-if (et8.success) {
- console.log("Parsed successfully. Tool name:", et8.data.name);
-} else {
- console.log(z.prettifyError(et8.error as z.core.$ZodError));
-}
\ No newline at end of file
diff --git a/examples/sdo/stix-bundle.example.ts b/examples/sdo/stix-bundle.example.ts
deleted file mode 100644
index f0527b63..00000000
--- a/examples/sdo/stix-bundle.example.ts
+++ /dev/null
@@ -1,298 +0,0 @@
-import { z } from "zod/v4";
-import { stixBundleSchema } from '../../src/schemas/sdo/stix-bundle.schema.js';
-import type { StixCreatedTimestamp, StixModifiedTimestamp } from "../../src/schemas/common/index.js";
-import { v4 as uuidv4 } from 'uuid';
-import { identitySchema } from "../../src/schemas/sdo/identity.schema.js";
-import { assetSchema } from "../../src/schemas/sdo/asset.schema.js";
-import { campaignSchema } from "../../src/schemas/sdo/campaign.schema.js";
-import { malwareSchema } from "../../src/schemas/sdo/malware.schema.js";
-import { matrixSchema } from "../../src/schemas/sdo/matrix.schema.js";
-import { toolSchema } from "../../src/schemas/sdo/tool.schema.js";
-import { groupSchema } from "../../src/schemas/sdo/group.schema.js";
-import { mitigationSchema } from "../../src/schemas/sdo/mitigation.schema.js";
-import { dataComponentSchema } from "../../src/schemas/sdo/data-component.schema.js";
-import { dataSourceSchema } from "../../src/schemas/sdo/data-source.schema.js";
-import { tacticSchema } from "../../src/schemas/sdo/tactic.schema.js";
-import { techniqueSchema } from "../../src/schemas/sdo/technique.schema.js";
-import { collectionSchema } from "../../src/schemas/sdo/collection.schema.js";
-import { markingDefinitionSchema } from "../../src/schemas/smo/marking-definition.schema.js";
-import { relationshipSchema } from "../../src/schemas/sro/relationship.schema.js";
-
-const StixObjectSchema: {[key: string]: z.ZodSchema} = {
- "x-mitre-asset": assetSchema,
- "campaign": campaignSchema,
- "x-mitre-collection": collectionSchema,
- "x-mitre-data-component": dataComponentSchema,
- "x-mitre-data-source": dataSourceSchema,
- "intrusion-set": groupSchema,
- "identity": identitySchema,
- "malware": malwareSchema,
- "marking-definition": markingDefinitionSchema,
- "x-mitre-matrix": matrixSchema,
- "course-of-action": mitigationSchema,
- "x-mitre-tactic": tacticSchema,
- "attack-pattern": techniqueSchema,
- "tool": toolSchema,
- "relationship": relationshipSchema
-};
-
-/** ************************************************************************************************* */
-// Example 1: Valid Stix Bundle
-/** ************************************************************************************************* */
-
-const minimalCollection = {
- id: `x-mitre-collection--${uuidv4()}`,
- type: 'x-mitre-collection',
- spec_version: '2.1',
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- created: '2021-01-01T00:00:00.000Z' as StixCreatedTimestamp,
- modified: '2021-01-01T00:00:00.000Z' as StixModifiedTimestamp,
- object_marking_refs: [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- name: 'Test Collection',
- description: 'This is a test collection.',
- x_mitre_attack_spec_version: "2.1.0",
- x_mitre_version: "1.0",
- x_mitre_contents: [
- {
- object_ref: "attack-pattern--0042a9f5-f053-4769-b3ef-9ad018dfa298",
- object_modified: "2021-01-01T00:00:00.000Z" as StixModifiedTimestamp
- }
- ]
-};
-
-const validBundle = {
- id: `bundle--${uuidv4()}`,
- type: 'bundle',
- spec_version: '2.1',
- objects: [minimalCollection],
-};
-
-console.log("Example 1 - Valid Stix Bundle:");
-console.log(stixBundleSchema.parse(validBundle));
-
-/** ************************************************************************************************* */
-// Example 2: Invalid Stix Bundle (missing required fields)
-/** ************************************************************************************************* */
-
-const invalidBundle = {
- id: `bundle--${uuidv4()}`,
- objects: [minimalCollection]
-};
-
-console.log("Example 2 - Invalid Stix Bundle (missing required fields):");
-const e2 = stixBundleSchema.safeParse(invalidBundle);
-console.log(z.prettifyError(e2.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 3: Invalid Stix Bundle (missing required fields)
-/** ************************************************************************************************* */
-
-const bundleWithInvalidCollection = {
- id: `bundle--${uuidv4()}`,
- type: 'bundle',
- spec_version: '2.1',
- objects: [
- {
- id: `x-mitre-collection--${uuidv4()}`,
- type: 'x-mitre-collection',
- spec_version: '2.1',
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- created: '2021-01-01T00:00:00.000Z' as StixCreatedTimestamp,
- modified: '2021-01-01T00:00:00.000Z' as StixModifiedTimestamp,
- object_marking_refs: [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- name: 'Test Collection',
- description: 'This is a test collection.',
- x_mitre_attack_spec_version: "2.1.0",
- x_mitre_version: "1.0",
- x_mitre_contents: [
- {
- object_ref: "attack-pattern--0042a9f5-f053-4769-b3ef-9ad018dfa298",
- object_modified: "2021-01-01T00:00:00.000Z" as StixModifiedTimestamp
- }
- ]
- },
- {
- type: "identity",
- id: `identity--${uuidv4()}`,
- spec_version: "2.3",
- created: "2017-06-01T00:00:00.000Z" as StixCreatedTimestamp,
- modified: "2017-06-01T00:00:00.000Z" as StixModifiedTimestamp,
- name: "The MITRE Corporation",
- object_marking_refs: [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168",
- ],
- x_mitre_attack_spec_version: "2.1.0",
- x_mitre_domains: ["enterprise-attack"],
- x_mitre_version: "1.0"
- }
- ]
-};
-console.log("Example 3 - Invalid Collection (missing required fields):");
-
-const e3 = stixBundleSchema.safeParse(bundleWithInvalidCollection);
-if (!e3.success) {
- const errors: string[] = [];
- e3.error.issues.forEach((issue) => {
- const objectIndex = issue.path.find((p) => typeof p === 'number');
- const errorObject = objectIndex !== undefined ? bundleWithInvalidCollection.objects[objectIndex as number] : undefined;
- console.log("\n")
- let errorMessage = `Error in bundle`;
- let objectMessage = `Validation errors: `;
- if (errorObject) {
- errorMessage += `\n Object Index: ${objectIndex}`;
- errorMessage += `\n Object ID: ${errorObject.id}`;
- errorMessage += `\n Object Type: ${errorObject.type}`;
- errorMessage += `\n Object Name: ${(errorObject as any).name || 'N/A'}`;
-
- let objectStatus = 'Active';
- if ((errorObject as any).x_mitre_deprecated) {
- objectStatus = 'Deprecated';
- }
- errorMessage += `\n Object Status: ${objectStatus}`;
- const schema = StixObjectSchema[errorObject.type];
- const objValidation = schema.safeParse(errorObject);
- if (!objValidation.success) {
- objectMessage += objValidation.error.issues.map(err => `\n - ${err.path.join('.')} : ${err.message}`).join('');
- }
- }
- errorMessage += `\n Path: ${issue.path.join('.')}`;
- errorMessage += `\n Error: ${issue.message}`;
- errors.push(errorMessage);
- console.warn(errorMessage);
- console.warn(objectMessage);
- });
-}
-
-/** ************************************************************************************************* */
-// Example 4: Stix Bundle with invalid type
-/** ************************************************************************************************* */
-const stixBundleWithInvalidType = {
- ...validBundle,
- type: "invalid-type",
-};
-
-console.log("\nExample 4 - Stix Bundle with invalid type:");
-const e4 = stixBundleSchema.safeParse(stixBundleWithInvalidType);
-console.log(z.prettifyError(e4.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 5: Stix Bundle with invalid id
-/** ************************************************************************************************* */
-const stixBundleWithInvalidId = {
- ...validBundle,
- id: 'tool--11f8d7eb-1927-4806-9267-3a11d4d4d6be',
-};
-
-console.log("\nExample 5 - Stix Bundle with invalid id:");
-const e5 = stixBundleSchema.safeParse(stixBundleWithInvalidId);
-console.log(z.prettifyError(e5.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 6: Parsing the provided example stix bundle
-/** ************************************************************************************************* */
-
-const exampleOfRealStixBundle = {
- "id": `bundle--${uuidv4()}`,
- "type": 'bundle',
- "spec_version": '2.1',
- "objects": [
- {
- "id": `x-mitre-collection--${uuidv4()}`,
- "type": 'x-mitre-collection',
- "spec_version": '2.1',
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "created": '2021-01-01T00:00:00.000Z' as StixCreatedTimestamp,
- "modified": '2021-01-01T00:00:00.000Z' as StixModifiedTimestamp,
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "name": 'Test Collection',
- "description": 'This is a test collection.',
- "x_mitre_attack_spec_version": "2.1.0",
- "x_mitre_version": "1.0",
- "x_mitre_contents": [
- {
- "object_ref": "attack-pattern--0042a9f5-f053-4769-b3ef-9ad018dfa298",
- "object_modified": "2021-01-01T00:00:00.000Z" as StixModifiedTimestamp
- }
- ]
- },
- {
- "type": "malware",
- "id": "malware--2daa14d6-cbf3-4308-bb8e-213c324a08e4",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "created": "2017-05-31T21:32:29.203Z",
- "modified": "2021-02-09T13:58:23.806Z",
- "name": "HAMMERTOSS",
- "description": "[HAMMERTOSS](https://attack.mitre.org/software/S0037) is a backdoor that was used by [APT29](https://attack.mitre.org/groups/G0016) in 2015. (Citation: FireEye APT29) (Citation: F-Secure The Dukes)",
- "labels": [
- "malware"
- ],
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/software/S0037",
- "external_id": "S0037"
- },
- {
- "source_name": "FireEye APT29",
- "description": "FireEye Labs. (2015, July). HAMMERTOSS: Stealthy Tactics Define a Russian Cyber Threat Group. Retrieved September 17, 2015.",
- "url": "https://www2.fireeye.com/rs/848-DID-242/images/rpt-apt29-hammertoss.pdf"
- },
- {
- "source_name": "F-Secure The Dukes",
- "description": "F-Secure Labs. (2015, September 17). The Dukes: 7 years of Russian cyberespionage. Retrieved December 10, 2015.",
- "url": "https://www.f-secure.com/documents/996508/1030745/dukes_whitepaper.pdf"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_aliases": [
- "HAMMERTOSS",
- "HammerDuke",
- "NetDuke"
- ],
- "x_mitre_attack_spec_version": "2.1.0",
- "x_mitre_domains": [
- "enterprise-attack"
- ],
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "x_mitre_platforms": [
- "Windows"
- ],
- "x_mitre_version": "1.2",
- "spec_version": '2.1',
- "is_family": false
- }
- ]
-}
-
-console.log("\nExample 6 - Parsing the provided example stixBundle:");
-const e6 = stixBundleSchema.safeParse(exampleOfRealStixBundle);
-if (e6.success) {
- console.log(e6.data);
- console.log("Parsed successfully. stix bundle ID:", e6.data.id);
-} else {
- console.log(z.prettifyError(e6.error as z.core.$ZodError));
-}
-
-/** ************************************************************************************************* */
-// Example 7: Stix Bundle with unknown property
-/** ************************************************************************************************* */
-const stixBundleWithUnknownProperty = {
- ...exampleOfRealStixBundle,
- foo: 'bar',
-}
-
-console.log("\nExample 7 - Parsing a stix bundle with an unknown property (foo: 'bar'):");
-const e7 = stixBundleSchema.safeParse(stixBundleWithUnknownProperty);
-if (e7.success) {
- console.log("Parsed successfully. Stix Bundle name:", e7.data.id);
-} else {
- console.log(z.prettifyError(e7.error as z.core.$ZodError));
-}
\ No newline at end of file
diff --git a/examples/sdo/tactic.example.ts b/examples/sdo/tactic.example.ts
deleted file mode 100644
index 416d28dc..00000000
--- a/examples/sdo/tactic.example.ts
+++ /dev/null
@@ -1,121 +0,0 @@
-import { z } from "zod/v4";
-import { tacticSchema } from "../../src/schemas/sdo/tactic.schema.js";
-
-/****************************************************************************************************/
-// Example 1: Valid Tactic
-/****************************************************************************************************/
-const validTactic = {
- "id": "x-mitre-tactic--4ca45d45-df4d-4613-8980-bac22d278fa5",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "name": "Execution",
- "description": "The adversary is trying to run malicious code.\n\nExecution consists of techniques that result in adversary-controlled code running on a local or remote system. Techniques that run malicious code are often paired with techniques from all other tactics to achieve broader goals, like exploring a network or stealing data. For example, an adversary might use a remote access tool to run a PowerShell script that does Remote System Discovery. ",
- "external_references": [
- {
- "external_id": "TA0002",
- "url": "https://attack.mitre.org/tactics/TA0002",
- "source_name": "mitre-attack"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_shortname": "execution",
- "type": "x-mitre-tactic",
- "modified": "2019-07-19T17:42:06.909Z",
- "created": "2018-10-17T00:14:20.652Z",
- "spec_version": "2.1",
- "x_mitre_attack_spec_version": "2.1.0",
- "x_mitre_domains": [
- "enterprise-attack"
- ],
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "x_mitre_version": "1.0"
-};
-
-console.log("\nExample 1: Valid Tactic:");
-console.log(`SUCCESS ${tacticSchema.parse(validTactic).name}`)
-
-/****************************************************************************************************/
-// Example 2: Invalid Tactic (ATT&CK ID does not match format TA####)
-/****************************************************************************************************/
-const invalidTacticID = {
- ...validTactic,
- external_references: [
- {
- source_name: "mitre-attack",
- external_id: "X0000"
- }
- ]
-};
-
-console.log("\nExample 2: Invalid Tactic (ATT&CK ID does not match format TA####):");
-const e2 = tacticSchema.safeParse(invalidTacticID);
-console.log(z.prettifyError(e2.error as z.core.$ZodError));
-
-/****************************************************************************************************/
-// Example 3: Invalid Tactic (missing required fields)
-/****************************************************************************************************/
-const invalidTacticMissingFields = {
- "id": "x-mitre-tactic--4ca45d45-df4d-4613-8980-bac22d278fa5",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "description": "The adversary is trying to run malicious code.\n\nExecution consists of techniques that result in adversary-controlled code running on a local or remote system. Techniques that run malicious code are often paired with techniques from all other tactics to achieve broader goals, like exploring a network or stealing data. For example, an adversary might use a remote access tool to run a PowerShell script that does Remote System Discovery. ",
- "external_references": [
- {
- "external_id": "TA0002",
- "url": "https://attack.mitre.org/tactics/TA0002",
- "source_name": "mitre-attack"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "type": "x-mitre-tactic",
- "modified": "2019-07-19T17:42:06.909Z",
- "created": "2018-10-17T00:14:20.652Z",
- "spec_version": "2.1",
- "x_mitre_attack_spec_version": "2.1.0",
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5"
-};
-
-console.log("\nExample 3: Invalid Tactic (missing required fields):");
-const e3 = tacticSchema.safeParse(invalidTacticMissingFields);
-console.log(z.prettifyError(e3.error as z.core.$ZodError));
-
-/****************************************************************************************************/
-// Example 4: Tactic with invalid type
-/****************************************************************************************************/
-const tacticWithInvalidType = {
- ...validTactic,
- type: "invalid-type"
-};
-
-console.log("\nExample 4: Tactic with invalid type:");
-const e4 = tacticSchema.safeParse(tacticWithInvalidType);
-console.log(z.prettifyError(e4.error as z.core.$ZodError));
-
-/****************************************************************************************************/
-// Example 5: Tactic with optional fields
-/****************************************************************************************************/
-const tacticWithOptionalFields = {
- ...validTactic,
- x_mitre_deprecated: true
-}
-
-console.log("\nExample 5: Tactic with optional fields:");
-console.log(tacticSchema.parse(tacticWithOptionalFields));
-
-/** ************************************************************************************************* */
-// Example 6: Tactic with unknown property
-/** ************************************************************************************************* */
-const tacticWithUnknownProperty = {
- ...validTactic,
- foo: 'bar'
-}
-
-console.log("\nExample 6 - Parsing a tactic with an unknown property (foo: 'bar'):");
-const e6 = tacticSchema.safeParse(tacticWithUnknownProperty);
-if (e6.success) {
- console.log("Parsed successfully. Tactic name:", e6.data.name);
-} else {
- console.log(z.prettifyError(e6.error as z.core.$ZodError));
-}
\ No newline at end of file
diff --git a/examples/sdo/technique.example.ts b/examples/sdo/technique.example.ts
deleted file mode 100644
index 34cc8089..00000000
--- a/examples/sdo/technique.example.ts
+++ /dev/null
@@ -1,436 +0,0 @@
-import { z } from "zod/v4";
-import { techniqueSchema } from "../../src/schemas/sdo/technique.schema.js";
-
-/*************************************************************************************************** */
-// Example 1: Valid Technique
-/*************************************************************************************************** */
-const validEnterpriseTechnique = {
- "modified": "2024-02-02T19:04:35.389Z",
- "name": "Data Obfuscation",
- "description": "Adversaries may obfuscate command and control traffic to make it more difficult to detect.(Citation: Bitdefender FunnyDream Campaign November 2020) Command and control (C2) communications are hidden (but not necessarily encrypted) in an attempt to make the content more difficult to discover or decipher and to make the communication less conspicuous and hide commands from being seen. This encompasses many methods, such as adding junk data to protocol traffic, using steganography, or impersonating legitimate protocols. ",
- "kill_chain_phases": [
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "command-and-control"
- }
- ],
- "x_mitre_deprecated": false,
- "x_mitre_domains": [
- "enterprise-attack"
- ],
- "x_mitre_is_subtechnique": false,
- "x_mitre_platforms": [
- "Linux",
- "macOS",
- "Windows"
- ],
- "x_mitre_version": "1.1",
- "type": "attack-pattern",
- "id": "attack-pattern--ad255bfe-a9e6-4b52-a258-8d3462abe842",
- "created": "2017-05-31T21:30:18.931Z",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "revoked": false,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T1001",
- "external_id": "T1001"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_attack_spec_version": "3.2.0",
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "spec_version": "2.1"
-};
-
-console.log("\nExample 1 - Valid Technique:");
-console.log(`SUCCESS ${techniqueSchema.parse(validEnterpriseTechnique).name}`)
-
-/*************************************************************************************************** */
-// Example 2: Invalid Technique (ATT&CK ID does not match format T####)
-/*************************************************************************************************** */
-const invalidTechniqueID = {
- ...validEnterpriseTechnique,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T1001",
- "external_id": "A00"
- }
- ],
-};
-
-console.log("\nExample 2 - Invalid Technique (ATT&CK ID does not match format T####):");
-const e2 = techniqueSchema.safeParse(invalidTechniqueID);
-console.log(z.prettifyError(e2.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 3: Valid Sub-technique
-/*************************************************************************************************** */
-const validSubtechnique = {
- "modified": "2023-03-20T18:43:03.218Z",
- "name": "Uninstall Malicious Application",
- "description": "Adversaries may include functionality in malware that uninstalls the malicious application from the device. This can be achieved by: \n \n* Abusing device owner permissions to perform silent uninstallation using device owner API calls. \n* Abusing root permissions to delete files from the filesystem. \n* Abusing the accessibility service. This requires sending an intent to the system to request uninstallation, and then abusing the accessibility service to click the proper places on the screen to confirm uninstallation.",
- "kill_chain_phases": [
- {
- "kill_chain_name": "mitre-mobile-attack",
- "phase_name": "defense-evasion"
- }
- ],
- "x_mitre_deprecated": false,
- "x_mitre_detection": "Users can see a list of applications that can use accessibility services in the device settings. Application vetting services could look for use of the accessibility service or features that typically require root access.",
- "x_mitre_domains": [
- "mobile-attack"
- ],
- "x_mitre_is_subtechnique": true,
- "x_mitre_platforms": [
- "Android"
- ],
- "x_mitre_version": "1.1",
- "x_mitre_tactic_type": [
- "Post-Adversary Device Access"
- ],
- "type": "attack-pattern",
- "id": "attack-pattern--0cdd66ad-26ac-4338-a764-4972a1e17ee3",
- "created": "2022-03-30T19:31:31.855Z",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "revoked": false,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T1630/001",
- "external_id": "T1630.001"
- },
- {
- "source_name": "NIST Mobile Threat Catalogue",
- "url": "https://pages.nist.gov/mobile-threat-catalogue/application-threats/APP-43.html",
- "external_id": "APP-43"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_attack_spec_version": "3.1.0",
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "spec_version": "2.1"
-}
-console.log("\nExample 3 - Valid Subtechnique:");
-console.log(`SUCCESS ${techniqueSchema.parse(validSubtechnique).name}`)
-
-/*************************************************************************************************** */
-// Example 4: Invalid Sub-technique (ATT&CK ID does not match format T####.###)
-/*************************************************************************************************** */
-const invalidSubtechniqueID = {
- ...validSubtechnique,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T1630/001",
- "external_id": "T1630"
- },
- {
- "source_name": "NIST Mobile Threat Catalogue",
- "url": "https://pages.nist.gov/mobile-threat-catalogue/application-threats/APP-43.html",
- "external_id": "APP-43"
- }
- ],
-}
-
-console.log("\nExample 4 - Invalid Subtechnique (ATT&CK ID does not match format T####.###):");
-const e4 = techniqueSchema.safeParse(invalidSubtechniqueID);
-console.log(z.prettifyError(e4.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 5: Invalid Technique (missing required fields)
-/*************************************************************************************************** */
-const invalidTechniqueMissingFields = {
- "modified": "2024-02-02T19:04:35.389Z",
- "description": "Adversaries may obfuscate command and control traffic to make it more difficult to detect.(Citation: Bitdefender FunnyDream Campaign November 2020) Command and control (C2) communications are hidden (but not necessarily encrypted) in an attempt to make the content more difficult to discover or decipher and to make the communication less conspicuous and hide commands from being seen. This encompasses many methods, such as adding junk data to protocol traffic, using steganography, or impersonating legitimate protocols. ",
- "x_mitre_deprecated": false,
- "x_mitre_is_subtechnique": false,
- "x_mitre_platforms": [
- "Linux",
- "macOS",
- "Windows"
- ],
- "type": "attack-pattern",
- "id": "attack-pattern--ad255bfe-a9e6-4b52-a258-8d3462abe842",
- "created": "2017-05-31T21:30:18.931Z",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "revoked": false,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T1001",
- "external_id": "T1001"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_attack_spec_version": "3.2.0",
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "spec_version": "2.1"
-};
-
-console.log("\nExample 5 - Invalid Technique (missing required fields):");
-const e5 = techniqueSchema.safeParse(invalidTechniqueMissingFields);
-console.log(z.prettifyError(e5.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 6: Technique with invalid type
-/*************************************************************************************************** */
-const techniqueWithInvalidType = {
- ...validEnterpriseTechnique,
- "type": 'invalid-type'
-}
-
-console.log("\nExample 6 - Technique with invalid type:");
-const e6 = techniqueSchema.safeParse(techniqueWithInvalidType);
-console.log(z.prettifyError(e6.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 7: Valid Enterprise Technique with Enterprise-only fields
-/*************************************************************************************************** */
-const validTechniqueWithEnterpriseFields = {
- ...validEnterpriseTechnique,
- "kill_chain_phases": [
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "privilege-escalation"
- },
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "defense-evasion"
- },
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "execution"
- },
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "impact"
- }
- ],
- "x_mitre_system_requirements": ["Windows 10"],
- "x_mitre_permissions_required": ["User"],
- "x_mitre_effective_permissions": ["Administrator"],
- "x_mitre_defense_bypassed": ["Anti-virus"],
- "x_mitre_remote_support": true,
- "x_mitre_impact_type": ["Integrity"]
-};
-console.log("\nExample 7: Valid Enterprise Technique with Enterprise-only fields:");
-let result = techniqueSchema.parse(validTechniqueWithEnterpriseFields);
-console.log(`SUCCESS ${result.name} (${result.x_mitre_domains})`)
-
-/*************************************************************************************************** */
-// Example 8: Invalid Enterprise Technique with Mobile-only fields
-/*************************************************************************************************** */
-const invalidEnterpriseTechnique = {
- ...validEnterpriseTechnique,
- "x_mitre_tactic_type": ["Post-Adversary Device Access"],
-};
-
-console.log("\nExample 8: Invalid Enterprise Technique with Mobile-only fields:");
-const e8 = techniqueSchema.safeParse(invalidEnterpriseTechnique);
-console.log(z.prettifyError(e8.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 9: Valid Mobile Technique with Mobile-only fields
-/*************************************************************************************************** */
-const validMobileTechnique = {
- "modified": "2023-03-15T16:23:59.281Z",
- "name": "Abuse Elevation Control Mechanism",
- "description": "Adversaries may circumvent mechanisms designed to control elevated privileges to gain higher-level permissions. Most modern systems contain native elevation control mechanisms that are intended to limit privileges that a user can gain on a machine. Authorization has to be granted to specific users in order to perform tasks that are designated as higher risk. An adversary can use several methods to take advantage of built-in control mechanisms in order to escalate privileges on a system. ",
- "kill_chain_phases": [
- {
- "kill_chain_name": "mitre-mobile-attack",
- "phase_name": "privilege-escalation"
- }
- ],
- "x_mitre_deprecated": false,
- "x_mitre_detection": "When an application requests administrator permission, users are presented with a popup and the option to grant or deny the request. Application vetting services can detect when an application requests administrator permission. Extra scrutiny could be applied to applications that do",
- "x_mitre_domains": [
- "mobile-attack"
- ],
- "x_mitre_is_subtechnique": false,
- "x_mitre_platforms": [
- "Android"
- ],
- "x_mitre_version": "1.1",
- "x_mitre_tactic_type": [
- "Post-Adversary Device Access"
- ],
- "type": "attack-pattern",
- "id": "attack-pattern--08ea902d-ecb5-47ed-a453-2798057bb2d3",
- "created": "2022-04-01T15:54:05.633Z",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "revoked": false,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T1626",
- "external_id": "T1626"
- },
- {
- "source_name": "NIST Mobile Threat Catalogue",
- "url": "https://pages.nist.gov/mobile-threat-catalogue/application-threats/APP-22.html",
- "external_id": "APP-22"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "x_mitre_attack_spec_version": "3.1.0",
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "spec_version": "2.1"
-}
-
-console.log("\nExample 9: Valid Mobile Technique with Mobile-only fields:");
-result = techniqueSchema.parse(validMobileTechnique);
-console.log(`SUCCESS ${result.name} (${result.x_mitre_domains})`)
-
-/*************************************************************************************************** */
-// Example 10: Invalid Mobile Technique with Enterprise-only fields
-/*************************************************************************************************** */
-const invalidMobileTechnique = {
- ...validMobileTechnique,
- "x_mitre_system_requirements": ["system requirements"]
-}
-
-console.log("\nExample 10: Invalid Mobile Technique with Enterprise-only fields:");
-const e10 = techniqueSchema.safeParse(invalidMobileTechnique);
-console.log(z.prettifyError(e10.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 11: Valid ICS Technique with ICS-only fields
-/*************************************************************************************************** */
-const validIcsTechnique = {
- "modified": "2023-10-13T17:56:58.380Z",
- "name": "Block Command Message",
- "description": "Adversaries may block a command message from reaching its intended target to prevent command execution. In OT networks, command messages are sent to provide instructions to control system devices. A blocked command message can inhibit response functions from correcting a disruption or unsafe condition. (Citation: Bonnie Zhu, Anthony Joseph, Shankar Sastry 2011) (Citation: Electricity Information Sharing and Analysis Center; SANS Industrial Control Systems March 2016)",
- "kill_chain_phases": [
- {
- "kill_chain_name": "mitre-ics-attack",
- "phase_name": "inhibit-response-function"
- }
- ],
- "x_mitre_attack_spec_version": "3.2.0",
- "x_mitre_deprecated": false,
- "x_mitre_domains": [
- "ics-attack"
- ],
- "x_mitre_is_subtechnique": false,
- "x_mitre_modified_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "x_mitre_platforms": [
- "None"
- ],
- "x_mitre_version": "1.1",
- "x_mitre_data_sources": [
- "Process: Process Termination",
- "Operational Databases: Process History/Live Data",
- "Application Log: Application Log Content",
- "Network Traffic: Network Traffic Flow",
- "Operational Databases: Process/Event Alarm"
- ],
- "type": "attack-pattern",
- "id": "attack-pattern--008b8f56-6107-48be-aa9f-746f927dbb61",
- "created": "2020-05-21T17:43:26.506Z",
- "created_by_ref": "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- "revoked": false,
- "external_references": [
- {
- "source_name": "mitre-attack",
- "url": "https://attack.mitre.org/techniques/T0803",
- "external_id": "T0803"
- },
- {
- "source_name": "Bonnie Zhu, Anthony Joseph, Shankar Sastry 2011",
- "description": "Bonnie Zhu, Anthony Joseph, Shankar Sastry 2011 A Taxonomy of Cyber Attacks on SCADA Systems Retrieved. 2018/01/12 ",
- "url": "http://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=6142258"
- },
- {
- "source_name": "Electricity Information Sharing and Analysis Center; SANS Industrial Control Systems March 2016",
- "description": "Electricity Information Sharing and Analysis Center; SANS Industrial Control Systems 2016, March 18 Analysis of the Cyber Attack on the Ukranian Power Grid: Defense Use Case Retrieved. 2018/03/27 ",
- "url": "https://assets.contentstack.io/v3/assets/blt36c2e63521272fdc/blt6a77276749b76a40/607f235992f0063e5c070fff/E-ISAC_SANS_Ukraine_DUC_5%5b73%5d.pdf"
- }
- ],
- "object_marking_refs": [
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168"
- ],
- "spec_version": "2.1"
-}
-
-console.log("\nExample 11: Valid ICS Technique with ICS-only fields:");
-result = techniqueSchema.parse(validIcsTechnique);
-console.log(`SUCCESS ${result.name} (${result.x_mitre_domains})`)
-
-/*************************************************************************************************** */
-// Example 12: Invalid ICS Technique with Enterprise-only fields
-/*************************************************************************************************** */
-const invalidIcsTechnique = {
- ...validIcsTechnique,
- "x_mitre_permissions_required": ["permissions required"]
-}
-
-console.log("\nExample 12: Invalid ICS Technique with Enterprise-only fields:");
-const e12 = techniqueSchema.safeParse(invalidIcsTechnique);
-console.log(z.prettifyError(e12.error as z.core.$ZodError));
-
-/*************************************************************************************************** */
-// Example 13: Valid multi-domain Technique with Enterprise/ICS-only fields
-/*************************************************************************************************** */
-const validMultiDomainTechnique = {
- ...validEnterpriseTechnique,
- "x_mitre_domains": [
- "enterprise-attack",
- "ics-attack"
- ],
- "x_mitre_data_sources": [
- "Process: Process Termination",
- "Operational Databases: Process History/Live Data",
- "Application Log: Application Log Content",
- "Network Traffic: Network Traffic Flow",
- "Operational Databases: Process/Event Alarm"
- ],
-}
-
-console.log("\nExample 13: Valid multi-domain Technique with Enterprise/ICS-only fields:");
-result = techniqueSchema.parse(validMultiDomainTechnique);
-console.log(`SUCCESS ${result.name} (${result.x_mitre_domains})`)
-
-/*************************************************************************************************** */
-// Example 14: Enterprise-only fields in the wrong tactic
-/*************************************************************************************************** */
-console.log("\nExample 14: Invalid Enterprise Technique with Enterprise-only field in wrong tactic:");
-const invalidEnterpriseTechniqueWrongTactic = {
- ...validEnterpriseTechnique,
- "kill_chain_phases": [
- {
- "kill_chain_name": "mitre-attack",
- "phase_name": "execution"
- }
- ],
- "x_mitre_permissions_required": ["User"]
-};
-
-const e14 = techniqueSchema.safeParse(invalidEnterpriseTechniqueWrongTactic);
-console.log(z.prettifyError(e14.error as z.core.$ZodError));
-
-/** ************************************************************************************************* */
-// Example 15: Technique with unknown property
-/** ************************************************************************************************* */
-const techniqueWithUnknownProperty = {
- ...validEnterpriseTechnique,
- foo: 'bar'
-}
-
-console.log("\nExample 15 - Parsing a technique with an unknown property (foo: 'bar'):");
-const e15 = techniqueSchema.safeParse(techniqueWithUnknownProperty);
-if (e15.success) {
- console.log("Parsed successfully. Technique name:", e15.data.name);
-} else {
- console.log(z.prettifyError(e15.error as z.core.$ZodError));
-}
\ No newline at end of file
diff --git a/examples/smo/marking-definition.example.ts b/examples/smo/marking-definition.example.ts
deleted file mode 100644
index de072770..00000000
--- a/examples/smo/marking-definition.example.ts
+++ /dev/null
@@ -1,175 +0,0 @@
-import { markingDefinitionSchema } from "../../src/schemas/smo/marking-definition.schema.js";
-import { z } from "zod";
-
-/** ************************************************************************************************* */
-// Example 1: Valid Marking Definition
-/** ************************************************************************************************* */
-const validMarkingDefinition = {
- definition: {
- statement: "Copyright 2015-2024, The MITRE Corporation. MITRE ATT&CK and ATT&CK are registered trademarks of The MITRE Corporation.",
- },
- id: "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168",
- type: "marking-definition",
- created: "2017-06-01T00:00:00.000Z",
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- definition_type: "statement",
- x_mitre_attack_spec_version: "2.1.0",
- spec_version: "2.1",
- x_mitre_domains: ["mobile-attack"],
-};
-
-console.log("Example 1 - Valid Marking Definition:");
-console.log(markingDefinitionSchema.parse(validMarkingDefinition));
-// {
-// id: 'marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168',
-// type: 'marking-definition',
-// spec_version: '2.1',
-// created: '2017-06-01T00:00:00.000Z',
-// created_by_ref: 'identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5',
-// definition_type: 'statement',
-// definition: {
-// statement: 'Copyright 2015-2024, The MITRE Corporation. MITRE ATT&CK and ATT&CK are registered trademarks of The MITRE Corporation.'
-// },
-// x_mitre_domains: [ 'mobile-attack' ],
-// x_mitre_attack_spec_version: '2.1.0'
-// }
-
-
-/** ************************************************************************************************* */
-// Example 2: Invalid Marking Definition (missing required fields)
-/** ************************************************************************************************* */
-const invalidMarkingDefinition = {
- definition: {
- statement:
- "Copyright 2015-2024, The MITRE Corporation. MITRE ATT&CK and ATT&CK are registered trademarks of The MITRE Corporation.",
- },
- id: "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168",
- type: "marking-definition",
- // missing created
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- // missing definition_type
- x_mitre_attack_spec_version: "2.1.0",
- spec_version: "2.1",
- x_mitre_domains: ["mobile-attack"],
-};
-
-console.log(
- "\nExample 2 - Invalid Marking Definition (missing required fields):"
-);
-try {
- markingDefinitionSchema.parse(invalidMarkingDefinition);
-} catch (error) {
- if (error instanceof z.ZodError) {
- console.log("Validation errors:", error.errors);
- }
-}
-// Validation errors: [
-// {
-// code: 'custom',
-// message: "Invalid STIX timestamp format: must be an RFC3339 timestamp with a timezone specification of 'Z'.",
-// fatal: true,
-// path: [ 'created' ]
-// },
-// {
-// expected: "'statement' | 'tlp'",
-// received: 'undefined',
-// code: 'invalid_type',
-// path: [ 'definition_type' ],
-// message: "definition_type must be either 'statement' or 'tlp'"
-// }
-// ]
-
-/** ************************************************************************************************* */
-// Example 3: Marking Definition with invalid fields
-/** ************************************************************************************************* */
-const invalidDefinitionStatement = {
- statement: "Example statement",
- name: "Example name", // <--- This property is not allowed on definition statements
- external_references: [ // <--- This property is not allowed on definition statements
- {
- source_name: "mitre-attack",
- url: "https://attack.mitre.org/software/S0698",
- external_id: "S0698",
- },
- ],
- object_marking_refs: [ // <--- This property is not allowed on definition statements
- "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168",
- ],
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5", // <--- This property is not allowed on definition statements
-}
-
-const markingDefinitionWithOptionalFields = {
- ...validMarkingDefinition,
- definition: invalidDefinitionStatement,
-};
-
-console.log("\nExample 3 - Marking Definition with optional fields:");
-try {
- markingDefinitionSchema.parse(markingDefinitionWithOptionalFields);
-} catch (error) {
- if (error instanceof z.ZodError) {
- console.log("Validation errors:", error.errors);
- }
-}
-// Validation errors: [
-// {
-// code: 'unrecognized_keys',
-// keys: [
-// 'name',
-// 'external_references',
-// 'object_marking_refs',
-// 'created_by_ref'
-// ],
-// path: [ 'definition' ],
-// message: "Unrecognized key(s) in object: 'name', 'external_references', 'object_marking_refs', 'created_by_ref'"
-// }
-// ]
-
-/** ************************************************************************************************* */
-// Example 4: Marking Definition with invalid type
-/** ************************************************************************************************* */
-const markingDefinitionWithInvalidType = {
- ...validMarkingDefinition,
- type: "invalid-type",
-};
-
-console.log("\nExample 4 - Marking Definition with invalid type:");
-try {
- markingDefinitionSchema.parse(markingDefinitionWithInvalidType);
-} catch (error) {
- if (error instanceof z.ZodError) {
- console.log("Validation error:", error.errors[0].message);
- // Validation error: Invalid literal value, expected "marking-definition"
- }
-}
-
-/** ************************************************************************************************* */
-// Example 5: Parsing the provided example Marking Definition
-/** ************************************************************************************************* */
-const exampleOfRealMarkingDefinition = {
- definition: {
- statement:
- "Copyright 2015-2024, The MITRE Corporation. MITRE ATT&CK and ATT&CK are registered trademarks of The MITRE Corporation.",
- },
- id: "marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168",
- type: "marking-definition",
- created: "2017-06-01T00:00:00.000Z",
- created_by_ref: "identity--c78cb6e5-0c4b-4611-8297-d1b8b55e40b5",
- definition_type: "statement",
- x_mitre_attack_spec_version: "2.1.0",
- spec_version: "2.1",
- x_mitre_domains: ["mobile-attack"],
-};
-
-console.log("\nExample 5 - Parsing the provided example Marking Definition:");
-try {
- const parsedMarkingDefinition = markingDefinitionSchema.parse(
- exampleOfRealMarkingDefinition
- );
- console.log(`Parsed successfully. marking definition id: ${parsedMarkingDefinition.id}`);
-} catch (error) {
- if (error instanceof z.ZodError) {
- console.log("Validation errors:", error.errors);
- }
-}
-// Parsed successfully. Marking Definition id: marking-definition--fa42a846-8d90-4e51-bc29-71d5b4802168
diff --git a/scripts/validate-local-stix21-bundle.ts b/examples/validate-stix/validate-local-stix21-bundle.ts
similarity index 84%
rename from scripts/validate-local-stix21-bundle.ts
rename to examples/validate-stix/validate-local-stix21-bundle.ts
index d87b5e3c..33b3bbaf 100644
--- a/scripts/validate-local-stix21-bundle.ts
+++ b/examples/validate-stix/validate-local-stix21-bundle.ts
@@ -38,7 +38,7 @@ import fs from 'fs/promises';
import path from 'path';
import { z } from 'zod';
-import { stixBundleSchema, type StixBundle } from '../src/schemas/sdo/stix-bundle.schema';
+import { stixBundleSchema, type StixBundle } from '@mitre-attack/attack-data-model';
/**
* Formats a ZodError into a readable string with context about the failing objects
@@ -147,24 +147,28 @@ function formatZodError(error: z.ZodError, bundle: StixBundle): string {
function formatError(issue: z.ZodIssue): string {
// For enum validation errors, reformat to include the received value clearly
if (issue.code === 'invalid_enum_value' && issue.received) {
- return `Invalid enum value. Received '${issue.received}' but expected one of: ${issue.options.map(opt => `'${opt}'`).join(' | ')}`;
+ return `Invalid enum value. Received '${issue.received}' but expected one of: ${issue.options.map((opt) => `'${opt}'`).join(' | ')}`;
}
-
+
// For invalid arguments, include value clearly
if (issue.code === 'invalid_arguments' && issue.argumentsError) {
return `Invalid arguments: ${issue.message}`;
}
// For custom validation errors that contain 'Expected X, received Y' format
- if (issue.code === 'custom' && issue.message.includes('Expected') && issue.message.includes('received')) {
+ if (
+ issue.code === 'custom' &&
+ issue.message.includes('Expected') &&
+ issue.message.includes('received')
+ ) {
return issue.message;
}
-
+
// Handle invalid types more clearly
if (issue.code === 'invalid_type') {
return `Invalid type. Expected ${issue.expected}, received ${issue.received}`;
}
-
+
// Return the original message for other types of errors
return issue.message;
}
@@ -174,40 +178,58 @@ function formatError(issue: z.ZodIssue): string {
* @returns Structured data about validation errors for analysis
*/
function collectErrorStatistics(
- error: z.ZodError,
- bundle: StixBundle
+ error: z.ZodError,
+ bundle: StixBundle,
): {
- invalidEnumValues: Map