Skip to content

Commit 76998df

Browse files
committed
fix problem getting ioc type when converting evidence to idmef
1 parent b70f583 commit 76998df

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

slips_files/common/idmefv2.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ def extract_role_type(
112112
IoCType.DOMAIN.name: "Hostname",
113113
IoCType.URL.name: "URL",
114114
}
115+
ioc_type = ioc_type.name if isinstance(ioc_type, IoCType) else ioc_type
115116
# todo make sure that its a fq domain
116117
return ioc, type_[ioc_type]
117118

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
from unittest.mock import Mock, patch
2+
3+
import pytest
4+
5+
from slips_files.common.idmefv2 import IDMEFv2
6+
from slips_files.core.structures.evidence import (
7+
Direction,
8+
EvidenceType,
9+
IoCType,
10+
Proto,
11+
ThreatLevel,
12+
)
13+
from tests.module_factory import ModuleFactory
14+
15+
16+
class MessageStub(dict):
17+
"""Minimal dict-like IDMEF message for converter unit tests."""
18+
19+
def validate(self) -> None:
20+
"""Skip external schema validation.
21+
22+
Return:
23+
None.
24+
"""
25+
return None
26+
27+
28+
@pytest.mark.parametrize(
29+
"threat_level, expected_priority",
30+
[
31+
(ThreatLevel.INFO, "Info"),
32+
(ThreatLevel.LOW, "Low"),
33+
(ThreatLevel.MEDIUM, "Medium"),
34+
(ThreatLevel.HIGH, "High"),
35+
(ThreatLevel.CRITICAL, "High"),
36+
],
37+
)
38+
def test_convert_threat_level_to_idmefv2_priority(
39+
threat_level: ThreatLevel, expected_priority: str
40+
) -> None:
41+
"""Verify Slips threat levels map to IDMEFv2 priority values.
42+
43+
Parameters:
44+
threat_level: Slips threat level to convert.
45+
expected_priority: Expected IDMEFv2 priority string.
46+
47+
Return:
48+
None.
49+
"""
50+
module_factory = ModuleFactory()
51+
idmefv2 = IDMEFv2(module_factory.logger, Mock())
52+
53+
assert (
54+
idmefv2.convert_threat_level_to_idmefv2_priority(threat_level)
55+
== expected_priority
56+
)
57+
58+
59+
def test_convert_to_idmef_event_uses_priority_field() -> None:
60+
"""Verify converted IDMEFv2 events use Priority instead of Severity.
61+
62+
Return:
63+
None.
64+
"""
65+
module_factory = ModuleFactory()
66+
db = Mock()
67+
db.is_running_non_stop.return_value = False
68+
idmefv2 = IDMEFv2(module_factory.logger, db)
69+
attacker = module_factory.create_attacker_obj(
70+
value="192.168.1.1", direction=Direction.SRC, ioc_type=IoCType.IP
71+
)
72+
victim = module_factory.create_victim_obj(
73+
value="192.168.1.2", direction=Direction.DST, ioc_type=IoCType.IP
74+
)
75+
evidence = module_factory.create_evidence_obj(
76+
evidence_type=EvidenceType.ARP_SCAN,
77+
description="ARP scan detected",
78+
attacker=attacker,
79+
threat_level=ThreatLevel.MEDIUM,
80+
victim=victim,
81+
profile=module_factory.create_profileid_obj(ip="192.168.1.1"),
82+
timewindow=module_factory.create_timewindow_obj(number=1),
83+
uid=["uid1"],
84+
timestamp="2023/10/26 10:10:10.000000+0000",
85+
proto=Proto.TCP,
86+
dst_port=80,
87+
id="d4afbe1a-1cb9-4db4-9fac-74f2da6f5f34",
88+
confidence=0.8,
89+
)
90+
91+
with patch("slips_files.common.idmefv2.Message", MessageStub):
92+
event = idmefv2.convert_to_idmef_event(evidence)
93+
94+
assert event["Priority"] == "Medium"
95+
assert "Severity" not in event

0 commit comments

Comments
 (0)