C'est scripts vous sont offert par AuxiNux.
DirtyFrag - mitigation temporaire
Fichier : dirtyfrag.sh
Applique une mitigation temporaire contre DirtyFrag en bloquant les modules noyau associés à IPsec/RxRPC: esp4, esp6, ipcomp4, ipcomp6 et rxrpc. Le script ne corrige pas le noyau: il réduit l’exposition en attendant un kernel corrigé.
Copié!
CVE-2026-31431 - mitigation algif_aead
Fichier : mitigation.sh
Applique une mitigation temporaire en bloquant le module noyau algif_aead via /etc/modprobe.d/disable-algif_aead.conf, tente de le décharger immédiatement, régénère l’initramfs ou dracut si disponible, puis journalise les actions dans /var/log/cve-2026-31431-mitigation.log. Ne remplace pas les mises à jour kernel officielles; un redémarrage peut être requis.
Copié!
Contenu de dirtyfrag.sh
#!/usr/bin/env bash
# Name=DirtyFrag - mitigation temporaire
# DESC=Applique une mitigation temporaire contre DirtyFrag en bloquant les modules noyau associés à IPsec/RxRPC: esp4, esp6, ipcomp4, ipcomp6 et rxrpc. Le script ne corrige pas le noyau: il réduit l’exposition en attendant un kernel corrigé.
set -u
set -o pipefail
CONF="/etc/modprobe.d/dirtyfrag.conf"
SYSCTL_CONF="/etc/sysctl.d/99-dirtyfrag-hardening.conf"
STATE_DIR="/var/lib/dirtyfrag"
LOG="/var/log/dirtyfrag-mitigation.log"
MODS=("esp4" "esp6" "ipcomp4" "ipcomp6" "rxrpc")
ACTION="${1:-apply}"
RED="\033[0;31m"
GREEN="\033[0;32m"
YELLOW="\033[1;33m"
BLUE="\033[0;34m"
NC="\033[0m"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG"
}
ok() {
echo -e "${GREEN}[OK]${NC} $*"
log "OK: $*"
}
warn() {
echo -e "${YELLOW}[WARN]${NC} $*"
log "WARN: $*"
}
fail() {
echo -e "${RED}[FAIL]${NC} $*"
log "FAIL: $*"
}
info() {
echo -e "${BLUE}[INFO]${NC} $*"
log "INFO: $*"
}
need_root() {
if [[ "${EUID}" -ne 0 ]]; then
echo "ERREUR: lance ce script en root."
echo "Exemple: sudo bash dirtyfrag.sh apply"
exit 1
fi
}
show_usage() {
cat <<EOF
Usage:
sudo bash dirtyfrag.sh check Vérifie si la mitigation semble nécessaire
sudo bash dirtyfrag.sh apply Applique la mitigation et valide après
sudo bash dirtyfrag.sh status Affiche l'état actuel
sudo bash dirtyfrag.sh strict Applique mitigation + désactive user namespaces
sudo bash dirtyfrag.sh drop-cache Vide le page cache
sudo bash dirtyfrag.sh revert Retire la mitigation
sudo bash dirtyfrag.sh help Affiche cette aide
Pour curl | bash:
curl -fsSL https://TON-DOMAINE/dirtyfrag.sh | sudo bash -s -- apply
curl -fsSL https://TON-DOMAINE/dirtyfrag.sh | sudo bash -s -- check
EOF
}
detect_os() {
info "=== Dirty Frag mitigation ==="
if [[ -r /etc/os-release ]]; then
# shellcheck disable=SC1091
. /etc/os-release
info "OS détecté: ${PRETTY_NAME:-inconnu}"
info "ID: ${ID:-inconnu} ${VERSION_ID:-}"
else
warn "/etc/os-release introuvable."
fi
info "Kernel actif: $(uname -r)"
info "Architecture: $(uname -m)"
}
module_exists() {
local m="$1"
if modinfo "$m" >/dev/null 2>&1; then
return 0
fi
if grep -qE "/${m}\.ko(\.xz|\.zst|\.gz)?$" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null; then
return 0
fi
return 1
}
module_builtin() {
local m="$1"
grep -qE "/${m}\.ko(\.xz|\.zst|\.gz)?$" "/lib/modules/$(uname -r)/modules.builtin" 2>/dev/null
}
module_loaded() {
local m="$1"
lsmod | awk '{print $1}' | grep -qx "$m"
}
module_blocked_by_modprobe() {
local m="$1"
local out
out="$(modprobe -n -v "$m" 2>/dev/null || true)"
echo "$out" | grep -Eq "install[[:space:]]+(/bin/false|/bin/true|/usr/bin/false|/usr/bin/true)"
}
target_modules_existing() {
local found=0
for m in "${MODS[@]}"; do
if module_exists "$m"; then
echo "$m"
found=1
fi
done
return "$found"
}
loaded_modules() {
lsmod | awk '{print $1}' | grep -E '^(esp4|esp6|ipcomp4|ipcomp6|rxrpc)$' || true
}
warn_services() {
info "Vérification rapide des services pouvant dépendre de IPsec/RxRPC..."
local found=0
for svc in strongswan strongswan-starter ipsec libreswan xl2tpd charon; do
if systemctl list-unit-files 2>/dev/null | grep -q "^${svc}\.service"; then
warn "Service détecté: ${svc}. Vérifie avant de continuer sur un serveur VPN/IPsec."
found=1
fi
done
if command -v ipsec >/dev/null 2>&1; then
warn "Commande 'ipsec' détectée. Ce serveur utilise peut-être IPsec."
found=1
fi
if command -v wg >/dev/null 2>&1; then
info "WireGuard détecté. WireGuard n'est pas IPsec ESP, donc pas le même problème."
fi
if ip xfrm state 2>/dev/null | grep -q .; then
warn "Des états IPsec/XFRM sont actifs:"
ip xfrm state 2>/dev/null | head -n 20
found=1
fi
if ip xfrm policy 2>/dev/null | grep -q .; then
warn "Des politiques IPsec/XFRM sont actives:"
ip xfrm policy 2>/dev/null | head -n 20
found=1
fi
if [[ "$found" -eq 1 ]]; then
warn "Cette mitigation peut couper IPsec/VPN sur ce serveur."
else
ok "Aucun usage IPsec évident détecté."
fi
}
check_kernel_updates_hint() {
if command -v apt-get >/dev/null 2>&1; then
info "Vérification rapide des mises à jour kernel disponibles via APT..."
apt-get update -qq >/dev/null 2>&1 || true
local upgradable
upgradable="$(apt list --upgradable 2>/dev/null | grep -E '^linux-image|^linux-generic|^linux-headers' || true)"
if [[ -n "$upgradable" ]]; then
warn "Des paquets kernel semblent disponibles. Installe les mises à jour dès que possible."
echo "$upgradable"
else
info "Aucune mise à jour kernel évidente dans APT actuellement."
fi
fi
}
check_vulnerability_state() {
need_root
detect_os
echo
info "Analyse Dirty Frag locale..."
local existing=()
local loaded=()
local unblocked=()
local builtins=()
for m in "${MODS[@]}"; do
if module_exists "$m"; then
existing+=("$m")
if module_builtin "$m"; then
builtins+=("$m")
fi
if module_loaded "$m"; then
loaded+=("$m")
fi
if ! module_blocked_by_modprobe "$m"; then
unblocked+=("$m")
fi
fi
done
echo
if [[ "${#existing[@]}" -eq 0 ]]; then
ok "Aucun des modules ciblés n'existe pour ce kernel. Risque Dirty Frag via ces modules: probablement faible."
else
warn "Modules ciblés présents sur ce kernel: ${existing[*]}"
fi
if [[ "${#builtins[@]}" -gt 0 ]]; then
fail "Modules compilés directement dans le kernel: ${builtins[*]}"
fail "Un blacklist modprobe ne peut PAS bloquer un module intégré au kernel. Il faut un kernel corrigé."
fi
if [[ "${#loaded[@]}" -gt 0 ]]; then
fail "Modules actuellement chargés: ${loaded[*]}"
else
ok "Aucun module ciblé n'est actuellement chargé."
fi
if [[ "${#unblocked[@]}" -gt 0 ]]; then
warn "Modules présents et pas encore bloqués par modprobe: ${unblocked[*]}"
else
ok "Tous les modules présents semblent bloqués par modprobe."
fi
echo
if [[ "${#existing[@]}" -gt 0 && "${#unblocked[@]}" -gt 0 ]]; then
fail "État: POTENTIELLEMENT VULNÉRABLE ou non mitigé."
return 2
elif [[ "${#loaded[@]}" -gt 0 ]]; then
fail "État: NON OK. Des modules ciblés sont encore chargés."
return 3
elif [[ "${#builtins[@]}" -gt 0 ]]; then
fail "État: NON OK. Module intégré au kernel, mitigation modprobe insuffisante."
return 4
else
ok "État: MITIGATION OK selon les vérifications locales."
return 0
fi
}
write_modprobe_conf() {
info "Écriture de ${CONF}..."
cat > "$CONF" <<EOF
# Dirty Frag temporary mitigation
# CVE-2026-43284 / CVE-2026-43500
# Blocks affected kernel modules from being loaded.
# Remove after installing a patched kernel and rebooting.
install esp4 /bin/false
install esp6 /bin/false
install ipcomp4 /bin/false
install ipcomp6 /bin/false
install rxrpc /bin/false
blacklist esp4
blacklist esp6
blacklist ipcomp4
blacklist ipcomp6
blacklist rxrpc
EOF
chmod 0644 "$CONF"
ok "Fichier modprobe créé: $CONF"
}
unload_modules() {
info "Tentative de déchargement des modules ciblés..."
local before
before="$(loaded_modules || true)"
if [[ -z "$before" ]]; then
ok "Aucun module ciblé chargé."
return 0
fi
echo "$before" | while read -r m; do
[[ -z "$m" ]] && continue
info "Déchargement du module: $m"
if modprobe -r "$m" 2>/dev/null; then
ok "$m déchargé avec modprobe -r."
elif rmmod "$m" 2>/dev/null; then
ok "$m déchargé avec rmmod."
else
fail "Impossible de décharger $m. Il est probablement en utilisation. Redémarrage requis."
fi
done
}
update_initramfs_if_present() {
if command -v update-initramfs >/dev/null 2>&1; then
info "Mise à jour initramfs..."
if update-initramfs -u >>"$LOG" 2>&1; then
ok "initramfs mis à jour."
else
warn "update-initramfs a échoué. Voir $LOG."
fi
else
info "update-initramfs non disponible, ignoré."
fi
}
apply_mitigation() {
need_root
detect_os
warn_services
echo
info "Pré-validation avant mitigation..."
check_vulnerability_state || true
echo
info "Application de la mitigation..."
write_modprobe_conf
unload_modules
update_initramfs_if_present
echo
info "Validation après mitigation..."
if check_vulnerability_state; then
ok "Mitigation Dirty Frag appliquée et validée."
echo
ok "Résultat final: OK"
exit 0
else
echo
fail "Résultat final: attention, mitigation incomplète."
warn "Si des modules restent chargés, planifie un redémarrage."
warn "Si un module est built-in, il faut un kernel corrigé."
exit 10
fi
}
apply_strict() {
apply_mitigation || true
mkdir -p "$STATE_DIR"
if [[ -r /proc/sys/user/max_user_namespaces ]]; then
if [[ ! -f "$STATE_DIR/user.max_user_namespaces.orig" ]]; then
cat /proc/sys/user/max_user_namespaces > "$STATE_DIR/user.max_user_namespaces.orig"
fi
warn "Mode strict: désactivation de user.max_user_namespaces."
warn "Peut casser Docker rootless, Snap, Flatpak, sandbox Chrome/Chromium."
cat > "$SYSCTL_CONF" <<EOF
# Dirty Frag defense-in-depth
# WARNING: can break rootless containers, Snap, Flatpak, and browser sandboxing.
user.max_user_namespaces = 0
EOF
sysctl -w user.max_user_namespaces=0 | tee -a "$LOG"
ok "Mode strict appliqué."
else
warn "user.max_user_namespaces non disponible sur ce système."
fi
}
drop_cache() {
need_root
detect_os
info "sync avant drop_caches..."
sync
info "Vidage du page cache..."
echo 3 > /proc/sys/vm/drop_caches
ok "Page cache vidé."
}
status() {
need_root
detect_os
echo
echo "Fichier mitigation:"
if [[ -f "$CONF" ]]; then
echo " OK: $CONF existe"
else
echo " NON: $CONF absent"
fi
echo
echo "Modules ciblés chargés:"
local mods
mods="$(loaded_modules || true)"
if [[ -z "$mods" ]]; then
echo " OK: aucun"
else
echo "$mods" | sed 's/^/ ATTENTION: /'
fi
echo
echo "Vérification modprobe:"
for m in "${MODS[@]}"; do
if module_exists "$m"; then
if module_blocked_by_modprobe "$m"; then
echo " OK: $m bloqué"
else
echo " WARN: $m présent mais non bloqué"
fi
else
echo " INFO: $m absent de ce kernel"
fi
done
echo
echo "user.max_user_namespaces:"
if [[ -r /proc/sys/user/max_user_namespaces ]]; then
echo " $(cat /proc/sys/user/max_user_namespaces)"
else
echo " Non disponible"
fi
echo
echo "Config modprobe:"
if [[ -f "$CONF" ]]; then
sed 's/^/ /' "$CONF"
fi
}
revert() {
need_root
detect_os
warn "Retrait de la mitigation Dirty Frag..."
if [[ -f "$CONF" ]]; then
rm -f "$CONF"
ok "Supprimé: $CONF"
else
info "$CONF déjà absent."
fi
if [[ -f "$SYSCTL_CONF" ]]; then
rm -f "$SYSCTL_CONF"
ok "Supprimé: $SYSCTL_CONF"
fi
if [[ -f "$STATE_DIR/user.max_user_namespaces.orig" && -r /proc/sys/user/max_user_namespaces ]]; then
old_value="$(cat "$STATE_DIR/user.max_user_namespaces.orig")"
info "Restauration user.max_user_namespaces=${old_value}"
sysctl -w "user.max_user_namespaces=${old_value}" | tee -a "$LOG"
fi
update_initramfs_if_present
warn "Mitigation retirée. Redémarrage recommandé après installation d'un kernel corrigé."
}
case "$ACTION" in
check)
check_vulnerability_state
;;
apply)
apply_mitigation
;;
strict)
apply_strict
;;
status)
status
;;
drop-cache)
drop_cache
;;
revert)
revert
;;
help|-h|--help)
show_usage
;;
*)
echo "Action inconnue: $ACTION"
show_usage
exit 1
;;
esac