nx_attack_taxonomy_test.nx source
↩ module page · 80 lines · 3767 B
1// nx_attack_taxonomy_test.nx -- smoke for MITRE taxonomy enums.
2//
3// Asserts:
4// 1. Tactic validity predicate behaves
5// 2. Tactic name lookup returns non-empty
6// 3. MITRE ID lookup returns the published TA0001..TA0043 numerics
7// 4. CWE validity predicate behaves
8// 5. CWE MITRE ID lookup returns the published CWE numbers
9// 6. Severity validity predicate behaves
10//
11// expect_exit: 0
12//
13// license_tier: ORIGINAL
14
15import "nx_syscalls.nx"
16import "nx_runtime.nx"
17import "nx_types.nx"
18import "nx_tier.nx"
19import "nx_attack_taxonomy.nx"
20
21func _strlen(s: *u8) -> nx_int {
22 var n: nx_int = 0
23 while 1 == 1 {
24 let p: *u8 = (s as nx_int + n) as *u8
25 let c: nx_int = p[0] as nx_int
26 if (c & 255) == 0 { return n }
27 n = n + 1
28 }
29 return n
30}
31
32func main() -> nx_int {
33 // ---- Test 1: tactic validity -----------------------------------
34 if nx_attack_tactic_is_valid(NX_ATTACK_TA_RECON) != 1 { return 1 }
35 if nx_attack_tactic_is_valid(NX_ATTACK_TA_IMPACT) != 1 { return 2 }
36 if nx_attack_tactic_is_valid(NX_ATTACK_TA_N) != 0 { return 3 }
37 if nx_attack_tactic_is_valid(-1) != 0 { return 4 }
38
39 // ---- Test 2: tactic name --------------------------------------
40 let n_recon: *u8 = nx_attack_tactic_name(NX_ATTACK_TA_RECON)
41 if _strlen(n_recon) < 4 { return 5 }
42 let n_impact: *u8 = nx_attack_tactic_name(NX_ATTACK_TA_IMPACT)
43 if _strlen(n_impact) < 4 { return 6 }
44
45 // ---- Test 3: tactic MITRE IDs match published values ----------
46 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_RECON) != 43 { return 10 }
47 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_RESOURCE_DEV) != 42 { return 11 }
48 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_INITIAL_ACCESS) != 1 { return 12 }
49 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_EXECUTION) != 2 { return 13 }
50 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_PERSISTENCE) != 3 { return 14 }
51 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_PRIV_ESC) != 4 { return 15 }
52 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_DEFENSE_EVASION) != 5 { return 16 }
53 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_CRED_ACCESS) != 6 { return 17 }
54 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_DISCOVERY) != 7 { return 18 }
55 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_LATERAL) != 8 { return 19 }
56 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_COLLECTION) != 9 { return 20 }
57 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_C2) != 11 { return 21 }
58 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_EXFIL) != 10 { return 22 }
59 if nx_attack_tactic_mitre_id(NX_ATTACK_TA_IMPACT) != 40 { return 23 }
60
61 // ---- Test 4: CWE validity --------------------------------------
62 if nx_cwe_is_valid(NX_CWE_BUFFER_OVERFLOW) != 1 { return 30 }
63 if nx_cwe_is_valid(NX_CWE_NULL_DEREF) != 1 { return 31 }
64 if nx_cwe_is_valid(NX_CWE_N) != 0 { return 32 }
65 if nx_cwe_is_valid(-1) != 0 { return 33 }
66
67 // ---- Test 5: CWE MITRE IDs match published values --------------
68 if nx_cwe_mitre_id(NX_CWE_BUFFER_OVERFLOW) != 119 { return 40 }
69 if nx_cwe_mitre_id(NX_CWE_OOB_READ) != 125 { return 41 }
70 if nx_cwe_mitre_id(NX_CWE_OOB_WRITE) != 787 { return 42 }
71 if nx_cwe_mitre_id(NX_CWE_USE_AFTER_FREE) != 416 { return 43 }
72 if nx_cwe_mitre_id(NX_CWE_NULL_DEREF) != 476 { return 44 }
73
74 // ---- Test 6: severity validity --------------------------------
75 if nx_attack_sev_is_valid(NX_ATTACK_SEV_INFO) != 1 { return 50 }
76 if nx_attack_sev_is_valid(NX_ATTACK_SEV_CRITICAL) != 1 { return 51 }
77 if nx_attack_sev_is_valid(NX_ATTACK_SEV_N) != 0 { return 52 }
78
79 return 0
80}