Skip to content

Commit 70719f8

Browse files
committed
fix: [stix2 import] Better handling of network-traffic patterns
- Patterns that obviously are single ip address, even when they look slightly more complex than just the single ipv4 or ipv6 address definition, are converted as single ip MISP attribute
1 parent 68d8112 commit 70719f8

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

misp_stix_converter/stix2misp/converters/stix2_indicator_converter.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@ def _handle_pattern_mapping(self, indicator: _INDICATOR_TYPING) -> str:
375375
# INDICATORS PARSING METHODS #
376376
############################################################################
377377

378+
@staticmethod
379+
def _network_traffic_pattern_as_single_attribute(pattern: PatternData) -> bool:
380+
if len(pattern.comparisons) > 1:
381+
return False
382+
comparisons = pattern.comparisons['network-traffic']
383+
if len(comparisons) > 2:
384+
return False
385+
for keys, _, _ in comparisons:
386+
if keys[0] == 'extensions':
387+
return False
388+
if keys[0] not in ('src_ref', 'dst_ref'):
389+
return False
390+
return True
391+
378392
def _parse_asn_pattern(
379393
self, pattern: PatternData, indicator: _INDICATOR_TYPING):
380394
attributes = []
@@ -806,7 +820,18 @@ def _parse_network_traffic_attribute(
806820

807821
def _parse_network_traffic_pattern(
808822
self, pattern: PatternData, indicator: _INDICATOR_TYPING):
809-
if 'socket-ext' in indicator.pattern:
823+
if self._network_traffic_pattern_as_single_attribute(pattern):
824+
for keys, assertion, value in pattern.comparisons['network-traffic']:
825+
if assertion not in self._mapping.valid_pattern_assertions():
826+
continue
827+
if 'type' in keys:
828+
continue
829+
attribute = {
830+
'type': f"ip-{keys[0].split('_')[0]}", 'value': value,
831+
**self._create_attribute_dict(indicator)
832+
}
833+
self.main_parser._add_misp_attribute(attribute, indicator)
834+
elif 'socket-ext' in indicator.pattern:
810835
self._parse_network_socket_pattern(pattern, indicator)
811836
else:
812837
self._parse_network_connection_pattern(pattern, indicator)

0 commit comments

Comments
 (0)