Skip to content

Commit 78d9565

Browse files
authored
Merge pull request #1069 from stratosphereips/alya/improve_inbound_traffic_detection
improve inbound traffic detection in timeline.py
2 parents 7d5c6d4 + 86bed41 commit 78d9565

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

modules/timeline/timeline.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import sys
33
import time
44
import json
5-
from typing import Any
5+
from typing import (
6+
Any,
7+
List,
8+
)
69

710
from slips_files.common.flow_classifier import FlowClassifier
811
from slips_files.common.parsers.config_parser import ConfigParser
@@ -20,15 +23,19 @@ class Timeline(IModule):
2023
authors = ["Sebastian Garcia", "Alya Gomaa"]
2124

2225
def init(self):
23-
self.separator = self.db.get_field_separator()
26+
self.read_configuration()
2427
self.c1 = self.db.subscribe("new_flow")
2528
self.channels = {
2629
"new_flow": self.c1,
2730
}
31+
self.classifier = FlowClassifier()
32+
self.host_ip: str = self.db.get_host_ip()
33+
34+
def read_configuration(self):
2835
conf = ConfigParser()
2936
self.is_human_timestamp = conf.timeline_human_timestamp()
3037
self.analysis_direction = conf.analysis_direction()
31-
self.classifier = FlowClassifier()
38+
self.client_ips: List[str] = conf.client_ips()
3239

3340
def convert_timestamp_to_slips_format(self, timestamp: float) -> str:
3441
if self.is_human_timestamp:
@@ -42,7 +49,11 @@ def ensure_int_bytes(self, bytes: Any) -> int:
4249

4350
def is_inbound_traffic(self, flow) -> bool:
4451
"""return True if profileid's IP is the same as the daddr"""
45-
return self.analysis_direction == "all" and flow.daddr == flow.saddr
52+
if self.analysis_direction != "all":
53+
# slips only detects inbound traffic in the "all" direction
54+
return False
55+
56+
return flow.daddr == self.host_ip or flow.daddr in self.client_ips
4657

4758
def process_dns_altflow(self, alt_flow: dict):
4859
answer = alt_flow["answers"]

modules/update_manager/update_manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ def parse_ssl_feed(self, url, full_path):
574574

575575
async def update_TI_file(self, link_to_download: str) -> bool:
576576
"""
577-
Update remote TI files, JA3 feeds and SSL feeds by writing them to disk and parsing them
577+
Update remote TI files, JA3 feeds and SSL feeds by writing them to
578+
disk and parsing them
578579
"""
579580
try:
580581
self.log(f"Updating the remote file {link_to_download}")

tests/test_timeline.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def test_interpret_dport(flow, expected_dport_name):
454454
{
455455
"timestamp": 1625097700,
456456
"dport_name": "HTTPS",
457-
"preposition": "from",
457+
"preposition": "to",
458458
"dns_resolution": "????",
459459
"daddr": "10.0.0.1",
460460
"dport/proto": "443/TCP",
@@ -545,7 +545,7 @@ def test_ensure_int_bytes(input_bytes, expected):
545545

546546

547547
@pytest.mark.parametrize(
548-
"saddr, daddr," "analysis_direction, expected_result",
548+
"host_ip, daddr," "analysis_direction, expected_result",
549549
[
550550
# testcase1: Inbound traffic,
551551
# analysis direction is "all"
@@ -561,12 +561,14 @@ def test_ensure_int_bytes(input_bytes, expected):
561561
("10.0.0.1", "10.0.0.1", "all", True),
562562
],
563563
)
564-
def test_is_inbound_traffic(saddr, daddr, analysis_direction, expected_result):
564+
def test_is_inbound_traffic(
565+
host_ip, daddr, analysis_direction, expected_result
566+
):
565567
timeline = ModuleFactory().create_timeline_object()
568+
timeline.host_ip = host_ip
566569
timeline.analysis_direction = analysis_direction
567570
flow = Mock()
568571
flow.daddr = daddr
569-
flow.saddr = saddr
570572
assert timeline.is_inbound_traffic(flow) == expected_result
571573

572574

0 commit comments

Comments
 (0)