kprobe log fix
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
All checks were successful
Build and Deploy MITM Webserver / build (push) Successful in 9s
This commit is contained in:
@@ -8,6 +8,7 @@ import ctypes as ct
|
|||||||
import hashlib
|
import hashlib
|
||||||
import ipaddress
|
import ipaddress
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import signal
|
import signal
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
@@ -395,13 +396,41 @@ def _emit_event(cpu: int, data: int, size: int) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def _attach_kprobe_first(bpf: BPF, symbols: list[str], fn_name: str) -> str:
|
def _attach_kprobe_first(bpf: BPF, symbols: list[str], fn_name: str) -> str:
|
||||||
for symbol in symbols:
|
supported = _supported_kprobe_symbols(symbols)
|
||||||
|
if not supported:
|
||||||
|
raise RuntimeError(f"No supported kprobe symbols found for {fn_name}: {symbols}")
|
||||||
|
|
||||||
|
for symbol in supported:
|
||||||
try:
|
try:
|
||||||
bpf.attach_kprobe(event=symbol, fn_name=fn_name)
|
bpf.attach_kprobe(event=symbol, fn_name=fn_name)
|
||||||
return symbol
|
return symbol
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
raise RuntimeError(f"Failed to attach {fn_name} to any of {symbols}")
|
raise RuntimeError(f"Failed to attach {fn_name} to any of {supported}")
|
||||||
|
|
||||||
|
|
||||||
|
def _supported_kprobe_symbols(symbols: list[str]) -> list[str]:
|
||||||
|
try:
|
||||||
|
available = set()
|
||||||
|
for symbol in symbols:
|
||||||
|
for candidate in BPF.get_kprobe_functions(symbol.encode()):
|
||||||
|
decoded = candidate.decode("utf-8", "replace")
|
||||||
|
if decoded == symbol:
|
||||||
|
available.add(symbol)
|
||||||
|
if available:
|
||||||
|
return [symbol for symbol in symbols if symbol in available]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if os.path.exists("/proc/kallsyms"):
|
||||||
|
try:
|
||||||
|
with open("/proc/kallsyms", "r", encoding="utf-8", errors="replace") as handle:
|
||||||
|
names = {line.rsplit(" ", 1)[-1].strip() for line in handle}
|
||||||
|
return [symbol for symbol in symbols if symbol in names]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return symbols
|
||||||
|
|
||||||
|
|
||||||
def _attach_egress_probe(bpf: BPF) -> str:
|
def _attach_egress_probe(bpf: BPF) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user