feat(backend): champs Anubis dans les détections, fix alias ClickHouse
- models.py: ajout anubis_bot_name, anubis_bot_action, anubis_bot_category dans le modèle Pydantic Detection - detections.py: fix ILLEGAL_AGGREGATION ClickHouse (argMin alias renommés en *_best), ajout des 3 champs Anubis dans les requêtes individuelle et groupée - ml_features.py: fix alias sum(hits) AS total_hits (évite nested aggregate), ajout missing_accept_enc_ratio et http_scheme_ratio dans b-features Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@ -97,15 +97,18 @@ async def get_detections(
|
||||
ip_data.unique_ja4s,
|
||||
ip_data.unique_hosts,
|
||||
ip_data.min_score AS anomaly_score,
|
||||
ip_data.threat_level,
|
||||
ip_data.model_name,
|
||||
ip_data.threat_level_best,
|
||||
ip_data.model_name_best,
|
||||
ip_data.country_code,
|
||||
ip_data.asn_number,
|
||||
ip_data.asn_org,
|
||||
ip_data.hit_velocity,
|
||||
ip_data.hits,
|
||||
ip_data.asn_label,
|
||||
ar.label AS asn_rep_label
|
||||
ar.label AS asn_rep_label,
|
||||
ip_data.anubis_bot_name_best,
|
||||
ip_data.anubis_bot_action_best,
|
||||
ip_data.anubis_bot_category_best
|
||||
FROM (
|
||||
SELECT
|
||||
src_ip,
|
||||
@ -115,14 +118,17 @@ async def get_detections(
|
||||
groupUniqArray(5)(ja4) AS unique_ja4s,
|
||||
groupUniqArray(5)(host) AS unique_hosts,
|
||||
min(anomaly_score) AS min_score,
|
||||
argMin(threat_level, anomaly_score) AS threat_level,
|
||||
argMin(model_name, anomaly_score) AS model_name,
|
||||
argMin(threat_level, anomaly_score) AS threat_level_best,
|
||||
argMin(model_name, anomaly_score) AS model_name_best,
|
||||
any(country_code) AS country_code,
|
||||
any(asn_number) AS asn_number,
|
||||
any(asn_org) AS asn_org,
|
||||
max(hit_velocity) AS hit_velocity,
|
||||
sum(hits) AS hits,
|
||||
any(asn_label) AS asn_label
|
||||
any(asn_label) AS asn_label,
|
||||
argMin(anubis_bot_name, anomaly_score) AS anubis_bot_name_best,
|
||||
argMin(anubis_bot_action, anomaly_score) AS anubis_bot_action_best,
|
||||
argMin(anubis_bot_category, anomaly_score) AS anubis_bot_category_best
|
||||
FROM ml_detected_anomalies
|
||||
WHERE {where_clause}
|
||||
GROUP BY src_ip
|
||||
@ -145,8 +151,9 @@ async def get_detections(
|
||||
detections = []
|
||||
for row in gresult.result_rows:
|
||||
# row: src_ip, first_seen, last_seen, detection_count, unique_ja4s, unique_hosts,
|
||||
# anomaly_score, threat_level, model_name, country_code, asn_number, asn_org,
|
||||
# hit_velocity, hits, asn_label, asn_rep_label
|
||||
# anomaly_score, threat_level_best, model_name_best, country_code, asn_number,
|
||||
# asn_org, hit_velocity, hits, asn_label, asn_rep_label,
|
||||
# anubis_bot_name, anubis_bot_action, anubis_bot_category
|
||||
ja4s = list(row[4]) if row[4] else []
|
||||
hosts = list(row[5]) if row[5] else []
|
||||
detections.append(Detection(
|
||||
@ -176,6 +183,9 @@ async def get_detections(
|
||||
last_seen=row[2],
|
||||
unique_ja4s=ja4s,
|
||||
unique_hosts=hosts,
|
||||
anubis_bot_name=row[16] or "",
|
||||
anubis_bot_action=row[17] or "",
|
||||
anubis_bot_category=row[18] or "",
|
||||
))
|
||||
|
||||
total_pages = (total + page_size - 1) // page_size
|
||||
@ -215,7 +225,10 @@ async def get_detections(
|
||||
fuzzing_index,
|
||||
post_ratio,
|
||||
reason,
|
||||
ar.label AS asn_rep_label
|
||||
ar.label AS asn_rep_label,
|
||||
anubis_bot_name,
|
||||
anubis_bot_action,
|
||||
anubis_bot_category
|
||||
FROM ml_detected_anomalies
|
||||
LEFT JOIN mabase_prod.asn_reputation ar ON ar.src_asn = toUInt32OrZero(asn_number)
|
||||
WHERE {where_clause}
|
||||
@ -267,6 +280,9 @@ async def get_detections(
|
||||
reason=row[19] or "",
|
||||
asn_rep_label=row[20] or "",
|
||||
asn_score=_label_to_score(row[20] or ""),
|
||||
anubis_bot_name=row[21] or "",
|
||||
anubis_bot_action=row[22] or "",
|
||||
anubis_bot_category=row[23] or "",
|
||||
)
|
||||
for row in result.result_rows
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user