fix: tests intégration matrix — procps-ng, varnish h2, hitch ALPN, pgrep→ps
- Ajout de procps-ng dans les 4 Dockerfiles runtime (ps/pgrep disponibles) - Remplacement de pgrep par ps -C dans tous les run-tests.sh - Correction entrypoint nginx-varnish : pgrep nginx → cat nginx.pid (exit 127) - Activation HTTP/2 dans Varnish : ajout de -p feature=+http2 dans les entrypoints nginx-varnish et hitch-varnish - Restauration ALPN h2,http/1.1 dans hitch.conf (varnish supporte maintenant h2) - Correction healthcheck hitch-varnish : curl sans --http1.1 (h2 fonctionnel) - Correction requêtes phase_verify : http_logs_raw → http_logs, colonnes correctes - Correction writer clickhouse.go : noms JSON alignés avec la MV (ip_meta_*, tls_sni…) - Fix toStartOfSecond(DateTime) → toStartOfSecond(toDateTime64(col, 3)) - Retrait du SKIP el8/nginx-varnish (varnish s'installe bien sur AlmaLinux 8) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@ -9,7 +9,9 @@
|
||||
FROM rockylinux:9 AS ebpf-builder
|
||||
|
||||
# Installation des outils de compilation eBPF
|
||||
RUN dnf install -y epel-release && \
|
||||
# libbpf-devel est dans le dépôt CRB (CodeReady Builder) de Rocky Linux 9
|
||||
RUN dnf install -y epel-release dnf-plugins-core && \
|
||||
dnf config-manager --enable crb && \
|
||||
dnf install -y \
|
||||
clang \
|
||||
llvm \
|
||||
@ -34,7 +36,9 @@ RUN mkdir -p bpf/headers && \
|
||||
FROM rockylinux:9 AS go-builder
|
||||
|
||||
# Installation de Go et des outils nécessaires
|
||||
RUN dnf install -y epel-release && \
|
||||
# libbpf-devel est dans le dépôt CRB (CodeReady Builder) de Rocky Linux 9
|
||||
RUN dnf install -y epel-release dnf-plugins-core && \
|
||||
dnf config-manager --enable crb && \
|
||||
dnf install -y \
|
||||
golang \
|
||||
clang \
|
||||
|
||||
@ -3,6 +3,13 @@
|
||||
*
|
||||
* Attaché sur l'interface réseau en ingress via TC (Traffic Control).
|
||||
* Émet des événements vers les ring buffers rb_tcp_syn et rb_tls_hello.
|
||||
*
|
||||
* Conventions vérificateur eBPF :
|
||||
* - Tous les offsets variables (ihl, doff) sont stockés en __u32 et bornés
|
||||
* explicitement avant tout usage en arithmétique de pointeur.
|
||||
* - Les lectures de longueur variable (options TCP, payload TLS/HTTP) sont
|
||||
* effectuées via bpf_skb_load_bytes() dans des tampons de pile locaux,
|
||||
* évitant ainsi toute arithmétique de pointeur sur des données paquet.
|
||||
* ============================================================================ */
|
||||
|
||||
#include "vmlinux.h"
|
||||
@ -22,6 +29,8 @@
|
||||
/* Constantes TCP */
|
||||
#define TH_SYN 0x02
|
||||
#define TH_ACK 0x10
|
||||
#define TH_FIN 0x01
|
||||
#define TH_RST 0x04
|
||||
|
||||
/* Port HTTPS standard */
|
||||
#define HTTPS_PORT 443
|
||||
@ -30,19 +39,15 @@
|
||||
#define HTTP_PORT 80
|
||||
#define HTTP_ALT_PORT 8080
|
||||
|
||||
/* Flags TCP */
|
||||
#define TH_FIN 0x01
|
||||
#define TH_RST 0x04
|
||||
|
||||
/* Type de contenu TLS : Handshake */
|
||||
#define TLS_CONTENT_HANDSHAKE 0x16
|
||||
/* Type de message TLS : ClientHello */
|
||||
#define TLS_MSG_CLIENT_HELLO 0x01
|
||||
|
||||
/* Taille maximale du payload TLS à copier */
|
||||
/* Taille maximale du payload TLS à copier (puissance de 2) */
|
||||
#define MAX_TLS_PAYLOAD 512
|
||||
|
||||
/* Longueur maximale des options TCP */
|
||||
/* Longueur maximale des options TCP en octets */
|
||||
#define MAX_TCP_OPTIONS 40
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
@ -63,7 +68,6 @@ struct ethhdr_local {
|
||||
SEC("tc/ingress")
|
||||
int capture_tc_ingress(struct __sk_buff *skb)
|
||||
{
|
||||
/* Pointeurs de début et fin du buffer paquet */
|
||||
void *data = (void *)(long)skb->data;
|
||||
void *data_end = (void *)(long)skb->data_end;
|
||||
|
||||
@ -72,118 +76,128 @@ int capture_tc_ingress(struct __sk_buff *skb)
|
||||
if ((void *)(eth + 1) > data_end)
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* Vérifier que c'est un paquet IPv4 */
|
||||
if (bpf_ntohs(eth->h_proto) != ETH_P_IP)
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* --- Parsing IPv4 --- */
|
||||
struct iphdr *ip = (struct iphdr *)((void *)eth + ETH_HLEN);
|
||||
struct iphdr *ip = data + ETH_HLEN;
|
||||
if ((void *)(ip + 1) > data_end)
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* Vérifier que c'est du TCP */
|
||||
if (ip->protocol != IPPROTO_TCP)
|
||||
return TC_ACT_OK;
|
||||
|
||||
__u8 ihl = ip->ihl & 0x0F; /* longueur en-tête IP en mots de 32 bits */
|
||||
__u32 src_ip = ip->saddr;
|
||||
__u32 dst_ip = ip->daddr;
|
||||
__u8 ttl = ip->ttl;
|
||||
__u16 ip_id = bpf_ntohs(ip->id);
|
||||
__u16 frag_off = bpf_ntohs(ip->frag_off);
|
||||
__u8 df_bit = (frag_off & IP_DF) ? 1 : 0;
|
||||
/* ihl stocké en u32 et borné explicitement : le vérificateur peut ainsi
|
||||
* prouver que ip_hlen ∈ [20, 60] sans risque d'overflow signé. */
|
||||
__u32 ihl = ip->ihl & 0x0F;
|
||||
if (ihl < 5)
|
||||
return TC_ACT_OK;
|
||||
__u32 ip_hlen = ihl << 2; /* ∈ [20, 60] */
|
||||
|
||||
__u32 src_ip = ip->saddr;
|
||||
__u32 dst_ip = ip->daddr;
|
||||
__u8 ttl = ip->ttl;
|
||||
__u16 ip_id = bpf_ntohs(ip->id);
|
||||
__u16 frag_off = bpf_ntohs(ip->frag_off);
|
||||
__u8 df_bit = (frag_off & IP_DF) ? 1 : 0;
|
||||
|
||||
/* --- Parsing TCP --- */
|
||||
struct tcphdr *tcp = (struct tcphdr *)((void *)ip + (ihl * 4));
|
||||
struct tcphdr *tcp = data + ETH_HLEN + ip_hlen;
|
||||
if ((void *)(tcp + 1) > data_end)
|
||||
return TC_ACT_OK;
|
||||
|
||||
__u16 src_port = bpf_ntohs(tcp->source);
|
||||
__u16 dst_port = bpf_ntohs(tcp->dest);
|
||||
__u16 window = bpf_ntohs(tcp->window);
|
||||
__u8 tcp_flags = ((__u8 *)tcp)[13]; /* octet des flags TCP */
|
||||
__u8 data_off = tcp->doff; /* longueur en-tête TCP en mots de 32 bits */
|
||||
__u16 src_port = bpf_ntohs(tcp->source);
|
||||
__u16 dst_port = bpf_ntohs(tcp->dest);
|
||||
__u16 window = bpf_ntohs(tcp->window);
|
||||
/* Lecture des flags via offset constant (octet 13 de l'en-tête TCP) */
|
||||
__u8 tcp_flags = ((__u8 *)tcp)[13];
|
||||
|
||||
/* doff stocké en u32 et borné : tcp_hlen ∈ [20, 60] */
|
||||
__u32 doff = tcp->doff;
|
||||
if (doff < 5)
|
||||
return TC_ACT_OK;
|
||||
__u32 tcp_hlen = doff << 2; /* ∈ [20, 60] */
|
||||
|
||||
/* Offset absolu du début du payload applicatif dans le paquet */
|
||||
__u32 payload_off = ETH_HLEN + ip_hlen + tcp_hlen;
|
||||
|
||||
/* --- Détection TCP SYN (SYN set, ACK clear) --- */
|
||||
if ((tcp_flags & TH_SYN) && !(tcp_flags & TH_ACK)) {
|
||||
/* Allouer un slot dans le ring buffer */
|
||||
struct tcp_syn_event *evt = bpf_ringbuf_reserve(&rb_tcp_syn, sizeof(*evt), 0);
|
||||
if (!evt)
|
||||
return TC_ACT_OK;
|
||||
|
||||
evt->src_ip = bpf_ntohl(src_ip);
|
||||
evt->dst_ip = bpf_ntohl(dst_ip);
|
||||
evt->src_port = src_port;
|
||||
evt->dst_port = dst_port;
|
||||
evt->ttl = ttl;
|
||||
evt->df_bit = df_bit;
|
||||
evt->ip_id = ip_id;
|
||||
evt->window_size = window;
|
||||
evt->window_scale = 0xFF; /* absent par défaut */
|
||||
evt->mss = 0; /* absent par défaut */
|
||||
evt->src_ip = bpf_ntohl(src_ip);
|
||||
evt->dst_ip = bpf_ntohl(dst_ip);
|
||||
evt->src_port = src_port;
|
||||
evt->dst_port = dst_port;
|
||||
evt->ttl = ttl;
|
||||
evt->df_bit = df_bit;
|
||||
evt->ip_id = ip_id;
|
||||
evt->window_size = window;
|
||||
evt->window_scale = 0xFF; /* absent par défaut */
|
||||
evt->mss = 0; /* absent par défaut */
|
||||
evt->timestamp_ns = bpf_ktime_get_ns();
|
||||
|
||||
/* --- Parsing des options TCP --- */
|
||||
__u8 *opts_start = (__u8 *)tcp + 20; /* options commencent après les 20 octets fixes */
|
||||
__u8 opts_len = (data_off * 4) - 20;
|
||||
if (opts_len > MAX_TCP_OPTIONS)
|
||||
opts_len = MAX_TCP_OPTIONS;
|
||||
|
||||
evt->tcp_options_len = 0;
|
||||
|
||||
/* Copier les options brutes avec vérification de bornes */
|
||||
__u8 *opts_ptr = opts_start;
|
||||
/* Lecture des options TCP dans un tampon de pile local (copie brute).
|
||||
* Le scan MSS/WS utilise bpf_skb_load_bytes avec offset variable plutôt
|
||||
* que opts_buf[j] : l'accès pile à index variable génère une erreur
|
||||
* vérificateur ("invalid variable-offset read from stack") car le tnum de
|
||||
* j accumule des bits carries au fil des incréments j += len (u8). */
|
||||
__u32 opts_off = ETH_HLEN + ip_hlen + 20;
|
||||
__u32 opts_bytes = tcp_hlen - 20; /* tcp_hlen >= 20, donc >= 0 */
|
||||
if (opts_bytes > MAX_TCP_OPTIONS)
|
||||
opts_bytes = MAX_TCP_OPTIONS;
|
||||
|
||||
/* Boucle bornée sur les options TCP (max 40 octets) */
|
||||
#pragma unroll
|
||||
for (int i = 0; i < MAX_TCP_OPTIONS; i++) {
|
||||
if (i >= opts_len)
|
||||
break;
|
||||
if ((void *)(opts_ptr + i + 1) > data_end)
|
||||
break;
|
||||
if (opts_bytes > 0) {
|
||||
__u8 opts_buf[MAX_TCP_OPTIONS] = {0};
|
||||
/* Lecture à taille constante : le vérificateur connaît la borne. */
|
||||
if (bpf_skb_load_bytes(skb, opts_off, opts_buf, MAX_TCP_OPTIONS) == 0) {
|
||||
/* Copie brute dans l'événement */
|
||||
__builtin_memcpy(evt->tcp_options_raw, opts_buf, MAX_TCP_OPTIONS);
|
||||
evt->tcp_options_len = (__u8)opts_bytes;
|
||||
|
||||
__u8 opt_kind;
|
||||
bpf_probe_read_kernel(&opt_kind, 1, opts_ptr + i);
|
||||
evt->tcp_options_raw[i] = opt_kind;
|
||||
evt->tcp_options_len = i + 1;
|
||||
/* Scan MSS et Window Scale via bpf_skb_load_bytes (offset variable
|
||||
* dans le paquet = autorisé ; index variable dans la pile = refusé). */
|
||||
__u32 j = 0;
|
||||
__u8 hdr2[2] = {0};
|
||||
__u8 one[1] = {0};
|
||||
#pragma unroll
|
||||
for (int iter = 0; iter < MAX_TCP_OPTIONS; iter++) {
|
||||
if (j + 1 >= opts_bytes)
|
||||
break;
|
||||
/* Lire kind et len d'un coup depuis le paquet */
|
||||
if (bpf_skb_load_bytes(skb, opts_off + j, hdr2, 2) < 0)
|
||||
break;
|
||||
__u8 kind = hdr2[0];
|
||||
if (kind == 0)
|
||||
break; /* EOL */
|
||||
if (kind == 1) {
|
||||
j++;
|
||||
continue; /* NOP : 1 octet */
|
||||
}
|
||||
__u8 len = hdr2[1];
|
||||
if (len < 2 || j + len > opts_bytes)
|
||||
break;
|
||||
|
||||
/* NOP : 1 octet */
|
||||
if (opt_kind == 1)
|
||||
continue;
|
||||
|
||||
/* EOL : fin des options */
|
||||
if (opt_kind == 0)
|
||||
break;
|
||||
|
||||
/* Option avec longueur */
|
||||
if ((void *)(opts_ptr + i + 2) > data_end)
|
||||
break;
|
||||
|
||||
__u8 opt_len;
|
||||
bpf_probe_read_kernel(&opt_len, 1, opts_ptr + i + 1);
|
||||
if (opt_len < 2)
|
||||
break;
|
||||
|
||||
/* MSS (option 2) : 4 octets au total */
|
||||
if (opt_kind == 2 && opt_len == 4) {
|
||||
if ((void *)(opts_ptr + i + 4) > data_end)
|
||||
break;
|
||||
__u16 mss_val;
|
||||
bpf_probe_read_kernel(&mss_val, 2, opts_ptr + i + 2);
|
||||
evt->mss = bpf_ntohs(mss_val);
|
||||
/* MSS (option 2) : 4 octets */
|
||||
if (kind == 2 && len == 4) {
|
||||
__u8 mss_buf[2] = {0};
|
||||
if (bpf_skb_load_bytes(skb, opts_off + j + 2, mss_buf, 2) == 0) {
|
||||
__u16 mss_val;
|
||||
__builtin_memcpy(&mss_val, mss_buf, 2);
|
||||
evt->mss = bpf_ntohs(mss_val);
|
||||
}
|
||||
}
|
||||
/* Window Scale (option 3) : 3 octets */
|
||||
if (kind == 3 && len == 3) {
|
||||
if (bpf_skb_load_bytes(skb, opts_off + j + 2, one, 1) == 0)
|
||||
evt->window_scale = one[0];
|
||||
}
|
||||
j += len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Window Scale (option 3) : 3 octets au total */
|
||||
if (opt_kind == 3 && opt_len == 3) {
|
||||
if ((void *)(opts_ptr + i + 3) > data_end)
|
||||
break;
|
||||
__u8 wscale;
|
||||
bpf_probe_read_kernel(&wscale, 1, opts_ptr + i + 2);
|
||||
evt->window_scale = wscale;
|
||||
}
|
||||
|
||||
/* Avancer au-delà de cette option */
|
||||
i += opt_len - 1;
|
||||
}
|
||||
|
||||
bpf_ringbuf_submit(evt, 0);
|
||||
@ -191,58 +205,67 @@ int capture_tc_ingress(struct __sk_buff *skb)
|
||||
|
||||
/* --- Détection TLS ClientHello (port 443) --- */
|
||||
if (dst_port == HTTPS_PORT) {
|
||||
__u8 *tcp_payload = (__u8 *)tcp + (data_off * 4);
|
||||
|
||||
/* Vérifier qu'il y a au moins 6 octets pour l'en-tête TLS record + type hello */
|
||||
if ((void *)(tcp_payload + 6) > data_end)
|
||||
/* Vérifier qu'il y a au moins 6 octets pour l'en-tête TLS record */
|
||||
if (payload_off + 6 > skb->len)
|
||||
return TC_ACT_OK;
|
||||
|
||||
__u8 content_type, msg_type;
|
||||
bpf_probe_read_kernel(&content_type, 1, tcp_payload);
|
||||
bpf_probe_read_kernel(&msg_type, 1, tcp_payload + 5);
|
||||
__u8 tls_hdr[6];
|
||||
if (bpf_skb_load_bytes(skb, payload_off, tls_hdr, sizeof(tls_hdr)) < 0)
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* Vérifier : Handshake (0x16) + ClientHello (0x01) */
|
||||
if (content_type == TLS_CONTENT_HANDSHAKE && msg_type == TLS_MSG_CLIENT_HELLO) {
|
||||
struct tls_hello_event *tls_evt = bpf_ringbuf_reserve(&rb_tls_hello, sizeof(*tls_evt), 0);
|
||||
if (!tls_evt)
|
||||
return TC_ACT_OK;
|
||||
/* Handshake (0x16) + ClientHello (0x01 au byte 5) */
|
||||
if (tls_hdr[0] != TLS_CONTENT_HANDSHAKE || tls_hdr[5] != TLS_MSG_CLIENT_HELLO)
|
||||
return TC_ACT_OK;
|
||||
|
||||
tls_evt->src_ip = bpf_ntohl(src_ip);
|
||||
tls_evt->src_port = src_port;
|
||||
tls_evt->timestamp_ns = bpf_ktime_get_ns();
|
||||
struct tls_hello_event *tls_evt =
|
||||
bpf_ringbuf_reserve(&rb_tls_hello, sizeof(*tls_evt), 0);
|
||||
if (!tls_evt)
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* Calculer la longueur de payload disponible */
|
||||
__u32 avail = (__u32)(data_end - (void *)tcp_payload);
|
||||
if (avail > MAX_TLS_PAYLOAD)
|
||||
avail = MAX_TLS_PAYLOAD;
|
||||
tls_evt->src_ip = bpf_ntohl(src_ip);
|
||||
tls_evt->src_port = src_port;
|
||||
tls_evt->timestamp_ns = bpf_ktime_get_ns();
|
||||
|
||||
tls_evt->payload_len = (__u16)avail;
|
||||
|
||||
/* Copier le payload TLS (borné à MAX_TLS_PAYLOAD) */
|
||||
bpf_probe_read_kernel(tls_evt->payload, avail & (MAX_TLS_PAYLOAD - 1), tcp_payload);
|
||||
|
||||
bpf_ringbuf_submit(tls_evt, 0);
|
||||
/* Calcul de la longueur disponible.
|
||||
* IMPORTANT : appliquer le masque SANS cap préalable. Si un cap
|
||||
* `if (avail > N) avail = N` précède le masque, le compilateur
|
||||
* supprime l'AND (semantically redundant). Sans cap, le compilateur
|
||||
* conserve l'AND et le vérificateur en déduit avail ∈ [0, 511].
|
||||
* Cas edge : avail exactement multiple de 512 → avail & 511 = 0. */
|
||||
__u32 avail = skb->len - payload_off;
|
||||
avail &= (MAX_TLS_PAYLOAD - 1); /* verifier : avail ∈ [0, 511] */
|
||||
if (avail == 0) {
|
||||
bpf_ringbuf_discard(tls_evt, 0);
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
|
||||
tls_evt->payload_len = (__u16)avail;
|
||||
|
||||
if (bpf_skb_load_bytes(skb, payload_off, tls_evt->payload, avail) < 0) {
|
||||
bpf_ringbuf_discard(tls_evt, 0);
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
|
||||
bpf_ringbuf_submit(tls_evt, 0);
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
|
||||
/* --- Détection payload HTTP en clair (port 80 / 8080) --- */
|
||||
if (dst_port == HTTP_PORT || dst_port == HTTP_ALT_PORT) {
|
||||
/* Ignorer SYN, FIN, RST : on ne veut que les segments de données */
|
||||
/* Ignorer SYN, FIN, RST : seuls les segments de données nous intéressent */
|
||||
if (tcp_flags & (TH_SYN | TH_FIN | TH_RST))
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* Calculer l'offset du payload TCP dans le paquet */
|
||||
__u32 payload_off = ETH_HLEN + (ihl * 4) + (data_off * 4);
|
||||
|
||||
/* Vérifier qu'il y a un payload non vide */
|
||||
if (skb->len <= payload_off)
|
||||
if (payload_off >= skb->len)
|
||||
return TC_ACT_OK;
|
||||
|
||||
__u32 avail = skb->len - payload_off;
|
||||
if (avail > 4096)
|
||||
avail = 4096;
|
||||
/* Même stratégie que pour TLS : masque SANS cap préalable.
|
||||
* Le compilateur conserve l'AND, le vérificateur déduit [0, 4095]. */
|
||||
avail &= 0xFFF; /* verifier : avail ∈ [0, 4095], smin ≥ 0 */
|
||||
if (avail == 0)
|
||||
return TC_ACT_OK;
|
||||
|
||||
/* Réserver une entrée dans le ring buffer HTTP en clair */
|
||||
struct http_plain_event *h_evt =
|
||||
bpf_ringbuf_reserve(&rb_http_plain, sizeof(*h_evt), 0);
|
||||
if (!h_evt)
|
||||
@ -252,15 +275,10 @@ int capture_tc_ingress(struct __sk_buff *skb)
|
||||
h_evt->dst_ip = bpf_ntohl(dst_ip);
|
||||
h_evt->src_port = src_port;
|
||||
h_evt->dst_port = dst_port;
|
||||
h_evt->payload_len = (__u16)avail;
|
||||
h_evt->timestamp_ns = bpf_ktime_get_ns();
|
||||
|
||||
/* Copier le payload depuis le skb linéaire via bpf_skb_load_bytes.
|
||||
* La longueur est masquée pour satisfaire le vérificateur eBPF. */
|
||||
__u32 copy_len = avail & (4096 - 1);
|
||||
if (copy_len == 0) copy_len = 1; /* cas avail == 4096 exactement */
|
||||
h_evt->payload_len = (__u16)avail;
|
||||
|
||||
if (bpf_skb_load_bytes(skb, payload_off, h_evt->payload, copy_len) < 0) {
|
||||
if (bpf_skb_load_bytes(skb, payload_off, h_evt->payload, avail) < 0) {
|
||||
bpf_ringbuf_discard(h_evt, 0);
|
||||
return TC_ACT_OK;
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ClickHouse/clickhouse-go/v2"
|
||||
@ -24,34 +25,41 @@ type ClickHouseWriter struct {
|
||||
}
|
||||
|
||||
// sessionRecord est la représentation JSON d'une session pour http_logs_raw.
|
||||
// Les noms de champs JSON correspondent exactement aux clés attendues par le MV mv_http_logs.
|
||||
type sessionRecord struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
SrcIP string `json:"src_ip"`
|
||||
SrcPort int `json:"src_port"`
|
||||
Correlated int `json:"correlated"`
|
||||
Time time.Time `json:"time"`
|
||||
SrcIP string `json:"src_ip"`
|
||||
SrcPort int `json:"src_port"`
|
||||
DstIP string `json:"dst_ip"`
|
||||
DstPort int `json:"dst_port"`
|
||||
Correlated int `json:"correlated"`
|
||||
|
||||
// L3/L4
|
||||
TTL *uint8 `json:"ttl,omitempty"`
|
||||
DFBit *bool `json:"df_bit,omitempty"`
|
||||
IPID *uint16 `json:"ip_id,omitempty"`
|
||||
WindowSize *uint16 `json:"window_size,omitempty"`
|
||||
WindowScale *uint8 `json:"window_scale,omitempty"`
|
||||
MSS *uint16 `json:"mss,omitempty"`
|
||||
// Métadonnées IP (noms attendus par le MV)
|
||||
IPMetaDF *bool `json:"ip_meta_df,omitempty"`
|
||||
IPMetaID *uint16 `json:"ip_meta_id,omitempty"`
|
||||
IPMetaTTL *uint8 `json:"ip_meta_ttl,omitempty"`
|
||||
IPMetaTotalLength *uint16 `json:"ip_meta_total_length,omitempty"`
|
||||
|
||||
// TLS
|
||||
JA4Hash string `json:"ja4,omitempty"`
|
||||
SNI string `json:"sni,omitempty"`
|
||||
ALPN []string `json:"alpn,omitempty"`
|
||||
TLSVersion *uint16 `json:"tls_version,omitempty"`
|
||||
// Métadonnées TCP (noms attendus par le MV)
|
||||
TCPMetaWindowSize *uint16 `json:"tcp_meta_window_size,omitempty"`
|
||||
TCPMetaWindowScale *uint8 `json:"tcp_meta_window_scale,omitempty"`
|
||||
TCPMetaMSS *uint16 `json:"tcp_meta_mss,omitempty"`
|
||||
TCPMetaOptions string `json:"tcp_meta_options,omitempty"`
|
||||
|
||||
// TLS (noms attendus par le MV)
|
||||
JA4Hash string `json:"ja4,omitempty"`
|
||||
TLSSNI string `json:"tls_sni,omitempty"`
|
||||
TLSALPN string `json:"tls_alpn,omitempty"`
|
||||
TLSVersion string `json:"tls_version,omitempty"`
|
||||
|
||||
// HTTP
|
||||
Method string `json:"method,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
QueryString string `json:"query_string,omitempty"`
|
||||
StatusCode *int `json:"status_code,omitempty"`
|
||||
ResponseSize *int64 `json:"response_size,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
QueryString string `json:"query_string,omitempty"`
|
||||
StatusCode *int `json:"status_code,omitempty"`
|
||||
ResponseSize *int64 `json:"response_size,omitempty"`
|
||||
DurationMS *float64 `json:"duration_ms,omitempty"`
|
||||
KeepAlives int `json:"keepalives,omitempty"`
|
||||
KeepAlives int `json:"keepalives,omitempty"`
|
||||
}
|
||||
|
||||
// NewClickHouseWriter crée un writer et établit la connexion ClickHouse.
|
||||
@ -179,41 +187,59 @@ func sessionToRecord(s *correlation.SessionState) sessionRecord {
|
||||
}
|
||||
|
||||
rec := sessionRecord{
|
||||
Timestamp: s.FirstSeen,
|
||||
Time: s.FirstSeen,
|
||||
SrcIP: srcIP,
|
||||
SrcPort: int(s.Key.SrcPort),
|
||||
DstIP: "0.0.0.0", // destination non capturée par les sondes eBPF actuelles
|
||||
DstPort: 0,
|
||||
Correlated: correlated,
|
||||
KeepAlives: len(s.Requests),
|
||||
}
|
||||
|
||||
// Champs L3/L4
|
||||
// Champs métadonnées IP/TCP
|
||||
if s.L3L4 != nil {
|
||||
rec.TTL = &s.L3L4.TTL
|
||||
rec.DFBit = &s.L3L4.DFBit
|
||||
rec.IPID = &s.L3L4.IPID
|
||||
rec.WindowSize = &s.L3L4.WindowSize
|
||||
rec.WindowScale = &s.L3L4.WindowScale
|
||||
rec.MSS = &s.L3L4.MSS
|
||||
rec.IPMetaDF = &s.L3L4.DFBit
|
||||
rec.IPMetaID = &s.L3L4.IPID
|
||||
rec.IPMetaTTL = &s.L3L4.TTL
|
||||
rec.TCPMetaWindowSize = &s.L3L4.WindowSize
|
||||
rec.TCPMetaWindowScale = &s.L3L4.WindowScale
|
||||
rec.TCPMetaMSS = &s.L3L4.MSS
|
||||
}
|
||||
|
||||
// Champs TLS
|
||||
if s.TLS != nil {
|
||||
rec.JA4Hash = s.TLS.JA4Hash
|
||||
rec.SNI = s.TLS.SNI
|
||||
rec.ALPN = s.TLS.ALPN
|
||||
rec.TLSVersion = &s.TLS.TLSVersion
|
||||
rec.TLSSNI = s.TLS.SNI
|
||||
rec.TLSALPN = strings.Join(s.TLS.ALPN, ",")
|
||||
rec.TLSVersion = formatTLSVersion(s.TLS.TLSVersion)
|
||||
}
|
||||
|
||||
// Champs HTTP (dernière requête)
|
||||
if len(s.Requests) > 0 {
|
||||
last := &s.Requests[len(s.Requests)-1]
|
||||
rec.Method = last.Method
|
||||
rec.Path = last.Path
|
||||
rec.QueryString = last.QueryString
|
||||
rec.StatusCode = &last.StatusCode
|
||||
rec.Method = last.Method
|
||||
rec.Path = last.Path
|
||||
rec.QueryString = last.QueryString
|
||||
rec.StatusCode = &last.StatusCode
|
||||
rec.ResponseSize = &last.ResponseSize
|
||||
rec.DurationMS = &last.DurationMS
|
||||
rec.DurationMS = &last.DurationMS
|
||||
}
|
||||
|
||||
return rec
|
||||
}
|
||||
|
||||
// formatTLSVersion convertit la valeur numérique TLS en chaîne lisible.
|
||||
func formatTLSVersion(v uint16) string {
|
||||
switch v {
|
||||
case 0x0301:
|
||||
return "TLSv1.0"
|
||||
case 0x0302:
|
||||
return "TLSv1.1"
|
||||
case 0x0303:
|
||||
return "TLSv1.2"
|
||||
case 0x0304:
|
||||
return "TLSv1.3"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user