Skip to content

Commit 8f7c485

Browse files
authored
Merge pull request #1195 from stratosphereips/alya/fix_whitelists
Fix reading tranco whitelist and support checking attacker and victim SNIs for whitelisted domains
2 parents 7179b8b + 55e7712 commit 8f7c485

File tree

22 files changed

+161
-106
lines changed

22 files changed

+161
-106
lines changed

.github/workflows/integration-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
8888
- name: Upload Artifacts
8989
if: success() || failure()
90-
uses: actions/upload-artifact@v3
90+
uses: actions/upload-artifact@v4
9191
with:
9292
name: test_slips_locally-integration-tests-output
9393
path: |

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ jobs:
125125
126126
- name: Upload Artifacts
127127
if: success() || failure()
128-
uses: actions/upload-artifact@v3
128+
uses: actions/upload-artifact@v4
129129
with:
130130
name: test_slips_locally-integration-tests-output
131131
path: |

.pre-commit-config.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ repos:
2020
exclude: '.*dataset/.*|^config/local_ti_files/own_malicious_JA3.csv$|.*test.*|.*\.md$'
2121

2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
# Ruff version.
2423
rev: v0.3.4
2524
hooks:
2625
# Run the linter.
2726
- id: ruff
2827
args: [ --fix ]
2928
# excludes formatting slips_files/common/imports.py
30-
exclude: (imports|sqlite_db.*)
29+
exclude: (imports|sqlite_db.*|conftest.py)
3130

3231
- repo: https://github.com/psf/black-pre-commit-mirror
3332
rev: 24.4.2
@@ -36,7 +35,7 @@ repos:
3635
args: ['--line-length' , '79']
3736
language_version: python3.12.3
3837
# excludes formatting slips_files/common/imports.py
39-
exclude: imports
38+
exclude: (imports|conftest.py)
4039

4140
- repo: https://github.com/adrienverge/yamllint.git
4241
rev: v1.31.0

conftest.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from slips_files.core.database.database_manager import DBManager
1515
from slips_files.core.output import Output
1616
from slips_files.core.flows.zeek import Conn
17-
17+
import logging
1818

1919
# add parent dir to path for imports to work
2020
current_dir = os.path.dirname(
@@ -24,6 +24,19 @@
2424
sys.path.insert(0, parent_dir)
2525

2626

27+
# Suppress TensorFlow logs from C++ backend
28+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # 3 = ERROR
29+
# TensorFlow logs oneDNN messages even with TF_CPP_MIN_LOG_LEVEL=3.
30+
os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
31+
32+
import tensorflow as tf
33+
34+
35+
# Suppress Python-based TensorFlow logs
36+
tf.get_logger().setLevel(logging.ERROR)
37+
logging.getLogger("tensorflow").setLevel(logging.ERROR)
38+
39+
2740
@pytest.fixture
2841
def mock_db():
2942
# Create a mock version of the database object

dataset/test15-malicious-zeek-dir/ssl.log

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
{"ts":95.036038,"uid":"CmjEJ14q2fMkVjIrjh","id.orig_h":"10.0.2.15","id.orig_p":49194,"id.resp_h":"52.0.131.132","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp384r1","server_name":"netflix.com","resumed":false,"established":true,"cert_chain_fuids":["FKMTO94tQEsBTFbPgc","FiN0Qh1UtcWHK5OhI1"],"client_cert_chain_fuids":[],"subject":"CN=www.netflix.com","issuer":"CN=Google Internet Authority G2,O=Google Inc,C=US","validation_status":"certificate is not yet valid"}
1+
{"ts":95.036038,"uid":"CmjEJ14q2fMkVjIrjh","id.orig_h":"10.0.2.15","id.orig_p":49194,"id.resp_h":"52.0.131.132","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp384r1","server_name":"netflix.com","resumed":false,"established":true,"cert_chain_fuids":["FKMTO94tQEsBTFbPgc","FiN0Qh1UtcWHK5OhI1"],"client_cert_chain_fuids":[],"subject":"CN=www.google.com","issuer":"CN=Google Internet Authority G2,O=Google Inc,C=US","validation_status":"certificate is not yet valid"}
22
{"ts":95.035658,"uid":"CofVUoGEO2KmtNRU8","id.orig_h":"10.0.2.15","id.orig_p":49193,"id.resp_h":"54.247.162.104","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA","curve":"secp256r1","server_name":"eu-west-1.dc.ads.linkedin.com","resumed":false,"established":true,"cert_chain_fuids":["Fz1tYe2XBbvuv8rdv5","FFhyEd4l0VxQ3oHQYg"],"client_cert_chain_fuids":[],"subject":"CN=ads.linkedin.com,O=LinkedIn Corporation,L=Mountain View,ST=California,C=US","issuer":"CN=DigiCert SHA2 Secure Server CA,O=DigiCert Inc,C=US","validation_status":"certificate is not yet valid"}
3-
{"ts":96.79553,"uid":"CS9zxQ7bqVG25o57h","id.orig_h":"10.0.2.15","id.orig_p":49201,"id.resp_h":"23.4.248.213","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"support.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["FGfeOO1SupRd8nH3a","FDqAH11L7j7Ha50flg"],"client_cert_chain_fuids":[],"subject":"CN=support.microsoft.com,OU=Microsoft Corporation,O=Microsoft Corporation,L=Redmond,ST=WA,C=US","issuer":"CN=Microsoft IT SSL SHA2,OU=Microsoft IT,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","validation_status":"certificate is not yet valid","ja3":"6734f37431670b3ab4292b8f60f29984"}
3+
{"ts":95.035658,"uid":"CofVUoGEO2KmtNRU8","id.orig_h":"10.0.2.15","id.orig_p":49193,"id.resp_h":"123.33.22.33","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA","curve":"secp256r1","server_name":"eu-west-1.dc.ads.linkedin.com","resumed":false,"established":true,"cert_chain_fuids":["Fz1tYe2XBbvuv8rdv5","FFhyEd4l0VxQ3oHQYg"],"client_cert_chain_fuids":[],"subject":"CN=ads.linkedin.com,O=LinkedIn Corporation,L=Mountain View,ST=California,C=US","issuer":"CN=DigiCert SHA2 Secure Server CA,O=DigiCert Inc,C=US","validation_status":"certificate is not yet valid"}
4+
{"ts":96.79553,"uid":"CS9zxQ7bqVG25o57h","id.orig_h":"10.0.2.15","id.orig_p":49201,"id.resp_h":"23.4.248.213","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"netflix.com","resumed":false,"established":true,"cert_chain_fuids":["FGfeOO1SupRd8nH3a","FDqAH11L7j7Ha50flg"],"client_cert_chain_fuids":[],"subject":"CN=whatever","issuer":"CN=netflix IT SSL SHA2,OU=netflix IT,O=netflix Corporation,L=Redmond,ST=Washington,C=US","validation_status":"certificate is not yet valid","ja3":"6734f37431670b3ab4292b8f60f29984"}
45
{"ts":96.918351,"uid":"CENVVlX3lQPg4mBcb","id.orig_h":"10.0.2.15","id.orig_p":49203,"id.resp_h":"54.247.162.104","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA","server_name":"eu-west-1.dc.ads.linkedin.com","resumed":true,"established":true}
56
{"ts":97.642593,"uid":"C8Yv0q4DKlhvcyneMi","id.orig_h":"10.0.2.15","id.orig_p":49208,"id.resp_h":"185.33.223.218","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"secure.adnxs.com","resumed":false,"established":true,"cert_chain_fuids":["FgAwAF16Y8bQmHTfSi","FB5esu1DguCF1WVOSe"],"client_cert_chain_fuids":[],"subject":"CN=*.adnxs.com,O=AppNexus\\, Inc.,L=New York,ST=New York,C=US","issuer":"CN=GeoTrust SSL CA - G3,O=GeoTrust Inc.,C=US","validation_status":"certificate is not yet valid"}
67
{"ts":97.79116,"uid":"CwzCf923y1FlDr18Ea","id.orig_h":"10.0.2.15","id.orig_p":49209,"id.resp_h":"185.33.223.218","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","server_name":"secure.adnxs.com","resumed":true,"established":true}

dataset/test9-mixed-zeek-dir/ssl.log

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{"ts":95.036038,"uid":"CmjEJ14q2fMkVjIrjh","id.orig_h":"10.0.2.15","id.orig_p":49194,"id.resp_h":"204.79.197.200","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp384r1","server_name":"ieonline.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["FKMTO94tQEsBTFbPgc","FiN0Qh1UtcWHK5OhI1"],"client_cert_chain_fuids":[],"subject":"CN=www.bing.com","issuer":"CN=Google Internet Authority G2,O=Google Inc,C=US","validation_status":"certificate is not yet valid"}
22
{"ts":95.035658,"uid":"CofVUoGEO2KmtNRU8","id.orig_h":"10.0.2.15","id.orig_p":49193,"id.resp_h":"54.247.162.104","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA","curve":"secp256r1","server_name":"eu-west-1.dc.ads.linkedin.com","resumed":false,"established":true,"cert_chain_fuids":["Fz1tYe2XBbvuv8rdv5","FFhyEd4l0VxQ3oHQYg"],"client_cert_chain_fuids":[],"subject":"CN=ads.linkedin.com,O=LinkedIn Corporation,L=Mountain View,ST=California,C=US","issuer":"CN=DigiCert SHA2 Secure Server CA,O=DigiCert Inc,C=US","validation_status":"certificate is not yet valid"}
3-
{"ts":96.79553,"uid":"CS9zxQ7bqVG25o57h","id.orig_h":"10.0.2.15","id.orig_p":49201,"id.resp_h":"23.4.248.213","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"support.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["FGfeOO1SupRd8nH3a","FDqAH11L7j7Ha50flg"],"client_cert_chain_fuids":[],"subject":"CN=support.microsoft.com,OU=Microsoft Corporation,O=Microsoft Corporation,L=Redmond,ST=WA,C=US","issuer":"CN=Microsoft IT SSL SHA2,OU=Microsoft IT,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","validation_status":"certificate is not yet valid","ja3":"6734f37431670b3ab4292b8f60f29984"}
3+
{"ts":96.79553,"uid":"CS9zxQ7bqVG25o57h","id.orig_h":"10.0.2.15","id.orig_p":49201,"id.resp_h":"23.4.248.213","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"netflix.com","resumed":false,"established":true,"cert_chain_fuids":["FGfeOO1SupRd8nH3a","FDqAH11L7j7Ha50flg"],"client_cert_chain_fuids":[],"subject":"CN=support.microsoft.com,OU=Microsoft Corporation,O=Microsoft Corporation,L=Redmond,ST=WA,C=US","issuer":"CN=Microsoft IT SSL SHA2,OU=Microsoft IT,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","validation_status":"certificate is not yet valid","ja3":"6734f37431670b3ab4292b8f60f29984"}
44
{"ts":96.918351,"uid":"CENVVlX3lQPg4mBcb","id.orig_h":"10.0.2.15","id.orig_p":49203,"id.resp_h":"54.247.162.104","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA","server_name":"eu-west-1.dc.ads.linkedin.com","resumed":true,"established":true}
55
{"ts":97.642593,"uid":"C8Yv0q4DKlhvcyneMi","id.orig_h":"10.0.2.15","id.orig_p":49208,"id.resp_h":"185.33.223.218","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"secure.adnxs.com","resumed":false,"established":true,"cert_chain_fuids":["FgAwAF16Y8bQmHTfSi","FB5esu1DguCF1WVOSe"],"client_cert_chain_fuids":[],"subject":"CN=*.adnxs.com,O=AppNexus\\, Inc.,L=New York,ST=New York,C=US","issuer":"CN=GeoTrust SSL CA - G3,O=GeoTrust Inc.,C=US","validation_status":"certificate is not yet valid"}
66
{"ts":97.79116,"uid":"CwzCf923y1FlDr18Ea","id.orig_h":"10.0.2.15","id.orig_p":49209,"id.resp_h":"185.33.223.218","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","server_name":"secure.adnxs.com","resumed":true,"established":true}
@@ -18,7 +18,7 @@
1818
{"ts":99.542318,"uid":"CVjEks28O5BxraAOSf","id.orig_h":"10.0.2.15","id.orig_p":49239,"id.resp_h":"104.96.160.12","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","server_name":"assets.onestore.ms","resumed":true,"established":true}
1919
{"ts":99.576663,"uid":"Cp7Ae73K73Mhl2Z9G1","id.orig_h":"10.0.2.15","id.orig_p":49244,"id.resp_h":"23.4.249.223","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"www.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["FK7Il41Zm9voJIkxjf","F7h8xp2aCQ6IUYlR88"],"client_cert_chain_fuids":[],"subject":"CN=www.microsoft.com,OU=MSCOM,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","issuer":"CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US","validation_status":"certificate is not yet valid"}
2020
{"ts":99.5769,"uid":"C0c0ib2kEJhhnLvxU9","id.orig_h":"10.0.2.15","id.orig_p":49242,"id.resp_h":"23.4.249.223","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"www.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["Fw96Zc2jRSqw7HfiV7","FYlNCX1Sxt86wQi623"],"client_cert_chain_fuids":[],"subject":"CN=www.microsoft.com,OU=MSCOM,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","issuer":"CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US","validation_status":"certificate is not yet valid"}
21-
{"ts":99.577159,"uid":"CCaRFW2mHr5QjSxnQk","id.orig_h":"10.0.2.15","id.orig_p":49243,"id.resp_h":"23.4.249.223","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"www.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["FAqZiovJiKx2hjVog","FjIi3A4UVoAkvFLRd6"],"client_cert_chain_fuids":[],"subject":"CN=www.microsoft.com,OU=MSCOM,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","issuer":"CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US","validation_status":"certificate is not yet valid","ja3s":"49ed2ef3f1321e5f044f1e71b0e6fdd5"}
21+
{"ts":99.577159,"uid":"CCaRFW2mHr5QjSxnQk","id.orig_h":"10.0.2.15","id.orig_p":49243,"id.resp_h":"123.33.22.11","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"www.netflix.com","resumed":false,"established":true,"cert_chain_fuids":["FAqZiovJiKx2hjVog","FjIi3A4UVoAkvFLRd6"],"client_cert_chain_fuids":[],"subject":"CN=www.microsoft.com,OU=MSCOM,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","issuer":"CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US","validation_status":"certificate is not yet valid","ja3s":"e7d705a3286e19ea42f587b344ee6865"}
2222
{"ts":99.654964,"uid":"C3c6el2LWkagjE1CUa","id.orig_h":"10.0.2.15","id.orig_p":49246,"id.resp_h":"104.96.160.12","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","server_name":"assets.onestore.ms","resumed":true,"established":true}
2323
{"ts":99.670901,"uid":"CiKTJDJ4jjLKfMzRb","id.orig_h":"10.0.2.15","id.orig_p":49247,"id.resp_h":"23.4.249.223","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","server_name":"www.microsoft.com","resumed":true,"established":true}
2424
{"ts":99.578387,"uid":"CP1gyt4jNylMd0zbye","id.orig_h":"10.0.2.15","id.orig_p":49245,"id.resp_h":"23.4.249.223","id.resp_p":443,"version":"TLSv10","cipher":"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA","curve":"secp256r1","server_name":"www.microsoft.com","resumed":false,"established":true,"cert_chain_fuids":["FPunt91J4UyxyE4zg5","FhnwZz4XtL2KsygJ1b"],"client_cert_chain_fuids":[],"subject":"CN=www.microsoft.com,OU=MSCOM,O=Microsoft Corporation,L=Redmond,ST=Washington,C=US","issuer":"CN=Symantec Class 3 Secure Server CA - G4,OU=Symantec Trust Network,O=Symantec Corporation,C=US","validation_status":"certificate is not yet valid"}

managers/process_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
)
3838

3939
from slips_files.common.style import green
40-
from slips_files.core.evidencehandler import EvidenceHandler
40+
from slips_files.core.evidence_handler import EvidenceHandler
4141
from slips_files.core.input import Input
4242
from slips_files.core.output import Output
4343
from slips_files.core.profiler import Profiler

modules/flowalerts/dns.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ def check_invalid_dns_answers(self, twid, flow):
451451
"""
452452
this function is used to check for private IPs in the answers of
453453
a dns queries.
454-
probably means the queries is being blocked
455-
(perhaps by ad blockers) and set to a private IP value
454+
Can be because of PI holes or DNS rebinding attacks
456455
"""
457456
if not flow.answers:
458457
return

modules/flowalerts/set_evidence.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,9 @@ def non_ssl_port_443_conn(self, twid, flow) -> None:
405405
def incompatible_cn(self, twid, flow, org: str) -> None:
406406
confidence: float = 0.9
407407
description: str = (
408-
f"Incompatible certificate CN to IP: {flow.daddr} "
409-
f"claiming to belong {org.capitalize()}."
408+
f"Incompatible certificate CN to IP: {flow.daddr} domain: "
409+
f"{flow.server_name}. The certificate is "
410+
f"claiming to belong to {org.capitalize()}."
410411
)
411412

412413
twid_number: int = int(twid.replace("timewindow", ""))
@@ -1142,11 +1143,12 @@ def suspicious_dns_answer(
11421143
self.db.set_evidence(evidence)
11431144

11441145
def invalid_dns_answer(self, twid, flow, invalid_answer) -> None:
1145-
confidence: float = 0.7
1146+
confidence: float = 0.8
11461147
twid: int = int(twid.replace("timewindow", ""))
11471148

11481149
description: str = (
1149-
f"The DNS query {flow.query} was resolved to {invalid_answer}"
1150+
f"Invalid DNS answer. The DNS query {flow.query} was resolved to "
1151+
f"the private IP: {invalid_answer}"
11501152
)
11511153

11521154
evidence: Evidence = Evidence(
@@ -1156,6 +1158,11 @@ def invalid_dns_answer(self, twid, flow, invalid_answer) -> None:
11561158
attacker_type=IoCType.IP,
11571159
value=flow.saddr,
11581160
),
1161+
victim=Victim(
1162+
direction=Direction.DST,
1163+
victim_type=IoCType.DOMAIN,
1164+
value=flow.query,
1165+
),
11591166
threat_level=ThreatLevel.INFO,
11601167
confidence=confidence,
11611168
description=description,
@@ -1164,7 +1171,6 @@ def invalid_dns_answer(self, twid, flow, invalid_answer) -> None:
11641171
uid=[flow.uid],
11651172
timestamp=flow.starttime,
11661173
)
1167-
11681174
self.db.set_evidence(evidence)
11691175

11701176
def port_0_connection(
@@ -1223,11 +1229,13 @@ def malicious_ja3s(self, twid, flow, malicious_ja3_dict: dict) -> None:
12231229

12241230
description = (
12251231
f"Malicious JA3s: (possible C&C server): {flow.ja3s} "
1226-
f"to server {flow.daddr}"
1232+
f"to server {flow.daddr}."
12271233
)
12281234
if ja3_description != "None":
1229-
description += f"description: {ja3_description} "
1230-
description += f"tags: {tags}"
1235+
description += f" description: {ja3_description}."
1236+
if tags:
1237+
description += f" tags: {tags}"
1238+
12311239
confidence: float = 1
12321240
twid_number: int = int(twid.replace("timewindow", ""))
12331241
# to add a correlation between the 2 evidence in alerts.json
@@ -1278,19 +1286,19 @@ def malicious_ja3s(self, twid, flow, malicious_ja3_dict: dict) -> None:
12781286

12791287
def malicious_ja3(self, twid, flow, malicious_ja3_dict: dict) -> None:
12801288
ja3_info: dict = json.loads(malicious_ja3_dict[flow.ja3])
1281-
12821289
threat_level: str = ja3_info["threat_level"].upper()
12831290
threat_level: ThreatLevel = ThreatLevel[threat_level]
12841291

12851292
tags: str = ja3_info.get("tags", "")
12861293
ja3_description: str = ja3_info["description"]
12871294

12881295
description = (
1289-
f"Malicious JA3: {flow.ja3} from source address {flow.saddr}"
1296+
f"Malicious JA3: {flow.ja3} from source address {flow.saddr}."
12901297
)
12911298
if ja3_description != "None":
1292-
description += f" description: {ja3_description} "
1293-
description += f" tags: {tags}"
1299+
description += f" description: {ja3_description}."
1300+
if tags:
1301+
description += f" tags: {tags}"
12941302

12951303
evidence: Evidence = Evidence(
12961304
evidence_type=EvidenceType.MALICIOUS_JA3,

modules/flowalerts/ssl.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ def detect_incompatible_cn(self, twid, flow):
9090
Detects if a certificate claims that it's CN (common name) belongs
9191
to an org that the domain doesn't belong to
9292
"""
93-
if not flow.issuer:
93+
if not flow.subject:
9494
return False
9595

96-
found_org_in_cn = ""
96+
org_found_in_cn = ""
9797
for org in utils.supported_orgs:
98-
if org not in flow.issuer.lower():
98+
if org not in flow.subject.lower():
9999
continue
100100

101101
# save the org this domain/ip is claiming to belong to,
102102
# to use it to set evidence later
103-
found_org_in_cn = org
103+
org_found_in_cn = org
104104

105105
# check that the ip belongs to that same org
106106
if self.whitelist.org_analyzer.is_ip_in_org(flow.daddr, org):
@@ -115,13 +115,15 @@ def detect_incompatible_cn(self, twid, flow):
115115
):
116116
return False
117117

118-
if not found_org_in_cn:
118+
if not org_found_in_cn:
119+
# the certificate doesn't claim to belong to any of slips known
120+
# orgs
119121
return False
120122

121123
# found one of our supported orgs in the cn but
122124
# it doesn't belong to any of this org's
123125
# domains or ips
124-
self.set_evidence.incompatible_cn(twid, flow, found_org_in_cn)
126+
self.set_evidence.incompatible_cn(twid, flow, org_found_in_cn)
125127

126128
def check_non_ssl_port_443_conns(self, twid, flow):
127129
"""

0 commit comments

Comments
 (0)