Skip to content

Commit 4faae5a

Browse files
authored
Merge pull request #1928 from stratosphereips/alya/improve_integration_tests
Improve integration tests
2 parents 96794b6 + 2a54e55 commit 4faae5a

43 files changed

Lines changed: 1486 additions & 692 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/integration-tests.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,18 @@ jobs:
5353
run: |
5454
python3 -m pytest tests/${{ matrix.test_file }} -p no:warnings -vv -s -n 3
5555
56+
- name: Build Artifact Name
57+
# otherwise we get numeric names for the artifacts and we dont know which is which
58+
id: artifact-name
59+
run: |
60+
sanitized_test_file="${{ matrix.test_file }}"
61+
sanitized_test_file=$(printf '%s\n' "$sanitized_test_file" | tr '/' '_')
62+
echo "name=${sanitized_test_file}-integration-output" >> "$GITHUB_OUTPUT"
63+
5664
- name: Upload Artifacts
5765
if: always()
5866
uses: actions/upload-artifact@v6
5967
with:
60-
# Replaces slashes with underscores for valid artifact naming
61-
name: ${{ github.run_id }}-${{ strategy.job-index }}-integration-output
68+
name: ${{ steps.artifact-name.outputs.name }}
6269
path: |
63-
output/integration
70+
output/integration_tests

config/TI_feeds.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ https://mcfp.felk.cvut.cz/publicDatasets/CTU-AIPP-BlackList/Todays-Blacklists/AI
1111
https://mcfp.felk.cvut.cz/publicDatasets/CTU-AIPP-BlackList/Todays-Blacklists/AIP_historical_blacklist_prioritized_by_newest_attackers.csv,medium, ['phishing','honeypot']
1212
https://raw.githubusercontent.com/stratosphereips/Civilsphere/main/threatintel/strangereallintel-cyberthreatintel.csv,medium, ['phishing']
1313
https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/network.csv,medium, ['stalkerware']
14-
https://raw.githubusercontent.com/stratosphereips/Civilsphere/main/threatintel/adserversandtrackers.csv,medium, ['adtrackers']
14+
https://raw.githubusercontent.com/stratosphereips/Civilsphere/main/threatintel/adserversandtrackers.csv,info, ['adtrackers']
1515
https://raw.githubusercontent.com/stratosphereips/Civilsphere/main/threatintel/civilsphereindicators.csv,medium, ['apt']
1616
https://raw.githubusercontent.com/botherder/targetedthreats/master/targetedthreats.csv,medium, ['apt']
1717
https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt,medium, ['honeypot']
@@ -26,10 +26,10 @@ https://lists.blocklist.de/lists/mail.txt,medium, ['honeypot']
2626
https://lists.blocklist.de/lists/bruteforcelogin.txt,medium, ['honeypot']
2727
https://feodotracker.abuse.ch/downloads/ipblocklist.csv,medium, ['honeypot']
2828
https://reputation.alienvault.com/reputation.generic,medium, ['honeypot']
29-
https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt,medium, ['adtrackers']
29+
https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt,info, ['adtrackers']
3030
# bigdargon: Hosts block ads of Vietnamese
31-
https://raw.githubusercontent.com/bigdargon/hostsVN/master/option/domain.txt,medium, ['adtrackers']
32-
https://raw.githubusercontent.com/SweetSophia/mifitxiaomipiholelist/master/mifitblocklist.txt,medium, ['xiaomi-trackers']
31+
https://raw.githubusercontent.com/bigdargon/hostsVN/master/option/domain.txt,info, ['adtrackers']
32+
https://raw.githubusercontent.com/SweetSophia/mifitxiaomipiholelist/master/mifitblocklist.txt,info, ['xiaomi-trackers']
3333
https://raw.githubusercontent.com/CriticalPathSecurity/Zeek-Intelligence-Feeds/master/abuse-ch-ipblocklist.intel,medium, ['honeypot']
3434
https://raw.githubusercontent.com/CriticalPathSecurity/Zeek-Intelligence-Feeds/master/alienvault.intel,medium, ['honeypot']
3535
https://raw.githubusercontent.com/CriticalPathSecurity/Zeek-Intelligence-Feeds/master/cobaltstrike_ips.intel,medium, ['honeypot']

docs/fides.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ To be able to use the fides module, you should use ```--cap-add=NET_ADMIN```
2525
If you plan on using the Fides Module, please be aware that it is used only if Slips is running on an interface OR on a growing Zeek directory. The `--use_fides=True` is ignored when Slips is run on a file.
2626

2727
## Configuration
28-
The evaluation model used, the evaluation thresholds, and other configurations are located in ```fides.conf.yml``` file
28+
The evaluation model used, the evaluation thresholds, and other configurations are located in ```modules/fides/config/fides.conf.yml```.
29+
30+
If you need a Slips run to use a different Fides configuration file, set
31+
```global_p2p.fides_conf``` in Slips config to the relative path
32+
of that alternate YAML file.
2933

3034
**Possible threat intelligence evaluation models**
3135

modules/arp_poisoner/arp_poisoner.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-FileCopyrightText: 2021 Sebastian Garcia <sebastian.garcia@agents.fel.cvut.cz>
22
# SPDX-License-Identifier: GPL-2.0-only
33
import logging
4+
import shutil
45
import subprocess
56
import time
67
from threading import Lock
@@ -30,6 +31,8 @@ class ARPPoisoner(IModule):
3031
authors = ["Alya Gomaa"]
3132

3233
def init(self):
34+
self.arp_scan_path = shutil.which("arp-scan")
35+
self.arp_scan_bin_available = self.arp_scan_path is not None
3336
self._time_since_last_repoison = {}
3437
self._time_since_last_internet_cut = {}
3538
self.log_file_path = self.get_module_specific_output_path(
@@ -56,13 +59,32 @@ def init(self):
5659
self.ip_interface_map = {}
5760

5861
def subscribe_to_channels(self):
62+
if not self.arp_scan_bin_available:
63+
self.channels = {}
64+
return
5965
self.c1 = self.db.subscribe("new_blocking")
6066
self.c2 = self.db.subscribe("tw_closed")
6167
self.channels = {
6268
"new_blocking": self.c1,
6369
"tw_closed": self.c2,
6470
}
6571

72+
def pre_main(self) -> bool:
73+
"""
74+
Stop the module before entering the main loop when arp-scan is
75+
unavailable.
76+
77+
:return: True when the module should shut down, otherwise False.
78+
"""
79+
if self.arp_scan_bin_available:
80+
return False
81+
82+
self.print(
83+
"The arp-scan tool is not installed. ARP poisoner module is "
84+
"stopping.",
85+
)
86+
return True
87+
6688
def log(self, text):
6789
"""Logs the given text to the blocking log file"""
6890
with self.blocking_logfile_lock:

modules/fides/fides.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@ def init(self):
5353

5454
# load trust model configuration
5555
current_dir = Path(__file__).resolve().parent
56-
config_path = current_dir / "config" / "fides.conf.yml"
57-
self.__trust_model_config = load_configuration(config_path.__str__())
56+
default_config_path = current_dir / "config" / "fides.conf.yml"
57+
config_path = self.conf.read_configuration(
58+
"global_p2p", "fides_conf", str(default_config_path)
59+
)
60+
self.__trust_model_config = load_configuration(config_path)
5861

5962
# prepare variables for global protocols
6063
self.__bridge: NetworkBridge

modules/fides/messaging/message_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict, List, Callable, Optional, Union
22

3-
3+
from slips_files.common.slips_utils import utils
44
from ..messaging.dacite import from_dict
55

66
from ..messaging.model import (
@@ -28,7 +28,7 @@ class MessageHandler:
2828
# def print(self, *args, **kwargs):
2929
# return self.printer.print(*args, **kwargs)
3030

31-
version = 1
31+
version = utils.get_current_version()
3232

3333
def __init__(
3434
self,

modules/fides/messaging/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@dataclass
1414
class NetworkMessage:
1515
type: str
16-
version: int
16+
version: str
1717
data: Any
1818

1919

modules/fides/messaging/network_bridge.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from dataclasses import asdict
33
from typing import Dict, List
44

5+
from slips_files.common.slips_utils import utils
56
from .dacite import from_dict
67

78
from .message_handler import MessageHandler
@@ -24,7 +25,7 @@ class NetworkBridge:
2425
execute "listen" method.
2526
"""
2627

27-
version = 1
28+
version = utils.get_current_version()
2829

2930
def __init__(self, queue: Queue):
3031
self.__queue = queue
@@ -36,14 +37,15 @@ def listen(self, handler: MessageHandler, block: bool = False):
3637
"""
3738

3839
def message_received(message: str):
40+
"""this is the callback that executes every new msg"""
3941
try:
40-
# with open("fides_nb.txt", "a") as f:
41-
# f.write(message)
42+
4243
logger.debug("New message received! Trying to parse.")
4344
parsed = json.loads(message)
4445
network_message = from_dict(
4546
data_class=NetworkMessage, data=parsed
4647
)
48+
4749
logger.debug("Message parsed. Executing handler.")
4850
handler.on_message(network_message)
4951
except Exception as e:

modules/fides/model/peer_trust_data.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33

44
from ..model.aliases import PeerId, OrganisationId
55
from ..model.peer import PeerInfo
6-
from ..model.recommendation_history import RecommendationHistory
7-
from ..model.service_history import ServiceHistory
6+
from ..model.recommendation_history import (
7+
RecommendationHistory,
8+
RecommendationHistoryRecord,
9+
)
10+
from ..model.service_history import ServiceHistory, ServiceHistoryRecord
811

912

1013
@dataclass
@@ -121,6 +124,7 @@ def to_dict(self, remove_histories: bool = False):
121124
# Method to create an object from a dictionary
122125
@classmethod
123126
def from_dict(cls, data):
127+
"""Create a PeerTrustData instance from a dictionary payload."""
124128
return cls(
125129
info=PeerInfo.from_dict(
126130
data["info"]
@@ -135,14 +139,13 @@ def from_dict(cls, data):
135139
"initial_reputation_provided_by_count"
136140
],
137141
service_history=[
138-
ServiceHistory.from_dict(sh) for sh in data["service_history"]
142+
ServiceHistoryRecord.from_dict(sh)
143+
for sh in data["service_history"]
139144
],
140-
# Assuming ServiceHistory has from_dict
141145
recommendation_history=[
142-
RecommendationHistory.from_dict(rh)
146+
RecommendationHistoryRecord.from_dict(rh)
143147
for rh in data["recommendation_history"]
144148
],
145-
# Assuming RecommendationHistory has from_dict
146149
)
147150

148151

0 commit comments

Comments
 (0)