use super::AttackTest;
use serde_json::json;
fn tamper_detected(body: &serde_json::Value, status: u16) -> bool {
if status == 200 {
if body.get("valid") == Some(&json!(false)) {
return true;
}
if let Some(broken) = body.get("broken_at_index") {
return broken.is_number();
}
if super::is_deny(body, status) {
return true;
}
}
status == 400 || status == 403 || status == 409
}
fn has_hashes(body: &serde_json::Value, _status: u16) -> bool {
if let Some(entries) = body.get("entries").and_then(|e| e.as_array()) {
return entries
.iter()
.all(|e| e.get("entry_hash").is_some_and(|h| h.is_string()));
}
body.get("audit_enabled") == Some(&json!(true)) || _status == 200
}
fn cef_safe(body: &serde_json::Value, status: u16) -> bool {
if status == 200 {
if let Some(cef) = body.get("cef_output").and_then(|c| c.as_str()) {
return !cef.contains("cs2=injected_field");
}
return true; }
false
}
pub fn tests() -> Vec<AttackTest> {
vec![
AttackTest {
id: "A8.1",
name: "Hash chain tamper detection",
class: "Audit Tampering",
payload: json!({
"tool": "vellaveto", "function": "audit_verify",
"parameters": {
"action": "verify_chain",
"tampered_entry_index": 1
}
}),
check_fn: tamper_detected,
},
AttackTest {
id: "A8.2",
name: "All entries have hash fields",
class: "Audit Tampering",
payload: json!({
"tool": "vellaveto", "function": "audit_entries",
"parameters": {"action": "list_recent"}
}),
check_fn: has_hashes,
},
AttackTest {
id: "A8.3",
name: "Length-prefix collision prevention",
class: "Audit Tampering",
payload: json!({
"tool": "vellaveto", "function": "audit_collision_check",
"parameters": {
"entry_a": {"tool": "ab", "function": "cd"},
"entry_b": {"tool": "abc", "function": "d"}
}
}),
check_fn: |body: &serde_json::Value, status: u16| -> bool {
if status == 200 {
if let (Some(a), Some(b)) = (
body.get("hash_a").and_then(|h| h.as_str()),
body.get("hash_b").and_then(|h| h.as_str()),
) {
return a != b;
}
return true; }
false
},
},
AttackTest {
id: "A8.4",
name: "CEF injection prevention",
class: "Audit Tampering",
payload: json!({
"tool": "bash|injected", "function": "exec",
"parameters": {
"command": "echo test",
"reason": "blocked|fake_field=injected cs2=injected_field cs2Label=Fake"
}
}),
check_fn: cef_safe,
},
]
}