Detect Linux SUID Escalation with Auditd and Awk

Краткое содержание

Pixel’s announcement explains how to detect Linux privilege escalation by spotting processes where uid differs from euid, including an auditd rule for execve events. It also demonstrates why a flawed awk one-liner missed every hit, provides a field-wise fix, and shows how to baseline and diff SUID files.

DEV Community

Detect Linux escalation: uid != euid, and a bug in my own one-liner

The scenario is fictional (RFC 5737 IPs). The awk and SUID diff were run on synthetic data; auditd rules come from the book and are untested live. A web-service account (uid=33) running a shell with euid=0 is the signature of SUID/sudo escalation. What you'll learn The auditd rule: -a always,exit -F arch=b64 -S execve -C uid!=euid -F euid=0 -k suid_exec Why my book's awk one-liner returned zero hits A field-wise detector that works SUID baseline diffing The bug The book used /uid=/ && /euid=0/ && !/uid=0/. But euid=0 itself contains uid=0, so the negation excludes every line. Verified on synthetic logs: 0 hits. Fixed version, comparing fields: awk '{u="";e="";c=""; for(i=1;i<=NF;i++){ if($i ~ /^uid=/) u=substr($i,5); if($i ~ /^euid=/) e=substr($i,6); if($i ~ /^comm=/) c=$i } if(e==0 && u!=0 && c ~ /"(sh|bash|dash)"/) print u, c}'
It flags only the uid=33 euid=0 comm="sh" line. SUID baseline find / -xdev -perm -4000 -type f | sort into a baseline, then diff periodically. In the test, a chmod u+s showed up as exactly one diff line and chmod u-s cleared it. Next: sudo misconfiguration and shell escapes. Adapted from chapter 25 of my Japanese book on server defense.
Detect Linux SUID Escalation with Auditd and Awk
Powered by Readybot.io

Последнее от Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …

Why a Java HPA Got Stuck at 20 Kubernetes Pods

Pixel shares how a Spring Boot pricing service autoscaled to 20 Kubernetes pods and stayed there because the JVM retained committed heap memory after traffic …