Skip to content

Commit a817d63

Browse files
committed
add user-agent and ja4 as report-fields
1 parent acac238 commit a817d63

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/riskdb/api/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from socket import gethostname
1111
from sys import path as sys_path
1212
from re import sub as regex_replace
13-
from re import compile as regex_compile
1413
from json import dumps as json_dumps
1514
from json import loads as json_loads
1615
from ipaddress import ip_address, ip_network
@@ -23,7 +22,7 @@
2322
from oxl_utils.valid.net import valid_public_ip, valid_asn, get_ipv
2423

2524
from riskdb.config import BUILD_DIR, KIND_FILES, REPORT_DIR, RISK_CATEGORIES, NET_SIZE, USER_TOKENS, \
26-
EXCLUDE_NETS_IP4, EXCLUDE_NETS_IP6
25+
EXCLUDE_NETS_IP4, EXCLUDE_NETS_IP6, JA4_REGEX
2726

2827
app = Flask('risk-db')
2928
RISKY_DB_FILE = {
@@ -35,7 +34,6 @@
3534
4: BUILD_DIR / 'risk_net4_med.json',
3635
6: BUILD_DIR / 'risk_net6_med.json',
3736
}
38-
JA4_REGEX = regex_compile(r'^[tqd](13|12|11|10|s3|s2|00)[di][a-f0-9]{4}[a-z0-9]{2}_[a-f0-9]{12}_[a-f0-9]{12}$')
3937

4038
report_lock = Lock()
4139

src/riskdb/builder/obj/report.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=R0801,R0902
22

3+
from riskdb.config import JA4_REGEX
34
from riskdb.builder.obj.reporter import Reporter, ANONYMOUS
45

56

@@ -10,9 +11,12 @@ def __init__(self, raw: dict, reporters: list[Reporter]):
1011
self.ip_anonymized = raw['an'] == 1 if 'an' in raw else False
1112
self.category = raw['cat']
1213
self.comment = raw['cmt']
14+
self.by_ip = raw['by']
1315
self.user_agent = raw.get('ua', '')
1416
self.fingerprint_ja4 = raw.get('ja4', '')
15-
self.by_ip = raw['by']
17+
18+
if JA4_REGEX.match(self.fingerprint_ja4) is None:
19+
self.fingerprint_ja4 = ''
1620

1721
self.reporter = self._init_reporter(token=raw['token'], reporters=reporters)
1822
self.legitimacy = self._init_legitimacy()
@@ -31,7 +35,7 @@ def _init_legitimacy(self) -> int:
3135
l += 5
3236
l += self.reporter.reputation
3337

34-
if len(self.comment) > 5:
38+
if len(self.comment) > 5 or len(self.user_agent) > 5 or self.fingerprint_ja4 != '':
3539
l += 1
3640

3741
# todo: extend logic

src/riskdb/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from os import environ
22
from pathlib import Path
33
from ipaddress import ip_network
4+
from re import compile as regex_compile
45

56
MODE_TEST = environ.get('RISKDB_TEST', '0')
67

@@ -36,3 +37,4 @@
3637
'2001:4860:4860::/64' # google dns
3738
]
3839
EXCLUDE_NETS_IP6 = [ip_network(n) for n in _EXCLUDE_NETS_IP6]
40+
JA4_REGEX = regex_compile(r'^[tqd](13|12|11|10|s3|s2|00)[di][a-f0-9]{4}[a-z0-9]{2}_[a-f0-9]{12}_[a-f0-9]{12}$')

0 commit comments

Comments
 (0)