Skip to content

Commit 69c8e9f

Browse files
authored
[client] add SignatureType supporting classes (#11)
Signed-off-by: Antoine MAZEAS <[email protected]>
1 parent 4b6927c commit 69c8e9f

File tree

12 files changed

+164
-5
lines changed

12 files changed

+164
-5
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ jobs:
3232
- ms-teams/report:
3333
only_on_fail: true
3434
webhook_url: $MS_TEAMS_WEBHOOK_URL
35+
test:
36+
docker:
37+
- image: cimg/python:3.13
38+
working_directory: ~/repo
39+
steps:
40+
- checkout
41+
- run:
42+
name: install dependencies
43+
command: pip3 install -r requirements.txt --user
44+
- run:
45+
name: install test-dependencies
46+
command: pip3 install -r test-requirements.txt --user
47+
- run:
48+
name: run tests
49+
command: python -m unittest
3550
linter:
3651
docker:
3752
- image: alpine/flake8
@@ -144,6 +159,10 @@ workflows:
144159
filters:
145160
tags:
146161
only: /.*/
162+
- test:
163+
filters:
164+
tags:
165+
only: /.*/
147166
- build:
148167
filters:
149168
tags:

pyobas/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: utf-8 -*-
2-
__version__ = "1.9.0"
2+
__version__ = "1.10.0"
33

44
from pyobas._version import ( # noqa: F401
55
__author__,

pyobas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
__email__ = "[email protected]"
44
__license__ = "Apache 2.0"
55
__title__ = "python-openbas"
6-
__version__ = "1.9.0"
6+
__version__ = "1.10.0"

pyobas/helpers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ def get_conf(self, variable, is_number=None, default=None, required=None):
310310

311311
class OpenBASCollectorHelper:
312312
def __init__(
313-
self, config: OpenBASConfigHelper, icon, security_platform_type=None
313+
self,
314+
config: OpenBASConfigHelper,
315+
icon,
316+
security_platform_type=None,
317+
connect_run_and_terminate: bool = False,
314318
) -> None:
315319
self.config_helper = config
316320
self.api = OpenBAS(
@@ -351,11 +355,10 @@ def __init__(
351355

352356
collector_icon = (icon_name, open(icon, "rb"), "image/png")
353357
self.api.collector.create(self.config, collector_icon)
354-
self.connect_run_and_terminate = False
355358
# self.api.injector.create(self.config)
356359
self.scheduler = sched.scheduler(time.time, time.sleep)
357360
# Start ping thread
358-
if not self.connect_run_and_terminate:
361+
if not connect_run_and_terminate:
359362
self.ping = PingAlive(
360363
self.api, self.config, self.collector_logger, "collector"
361364
)

pyobas/signatures/__init__.py

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pyobas.exceptions import OpenBASError
2+
from pyobas.signatures.types import MatchTypes
3+
4+
5+
class SignatureMatch:
6+
def __init__(self, match_type: MatchTypes, match_score: int | None):
7+
if match_score is None and match_type != MatchTypes.MATCH_TYPE_SIMPLE:
8+
raise OpenBASError(
9+
f"Match type {match_type} requires score to be set, found score = {match_score}"
10+
)
11+
self.match_type = match_type
12+
self.match_score = match_score
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from pyobas.signatures.signature_match import SignatureMatch
2+
from pyobas.signatures.types import MatchTypes, SignatureTypes
3+
4+
5+
class SignatureType:
6+
def __init__(
7+
self,
8+
label: SignatureTypes,
9+
match_type: MatchTypes = MatchTypes.MATCH_TYPE_SIMPLE,
10+
match_score: int = None,
11+
):
12+
self.label = label
13+
self.match_policy = SignatureMatch(match_type, match_score)
14+
15+
# provided some `data`, formats a dictionary specifying the matching
16+
# policy to use by the helper to match expected signatures (from expectations)
17+
# with actual, alert signatures (from the security software)
18+
# Output: {
19+
# "type": str,
20+
# "data": any,
21+
# "score": (optional) int
22+
# }
23+
def make_struct_for_matching(self, data):
24+
struct = {
25+
"type": self.match_policy.match_type,
26+
"data": data,
27+
}
28+
29+
if self.match_policy.match_score is not None:
30+
struct["score"] = self.match_policy.match_score
31+
32+
return struct

pyobas/signatures/types.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from enum import Enum
2+
3+
4+
class MatchTypes(Enum):
5+
MATCH_TYPE_FUZZY = "fuzzy"
6+
MATCH_TYPE_SIMPLE = "simple"
7+
8+
9+
class SignatureTypes(Enum):
10+
SIG_TYPE_PARENT_PROCESS_NAME = "parent_process_name"
11+
SIG_TYPE_HOSTNAME = "hostname"

test/__init__.py

Whitespace-only changes.

test/signatures/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)