Last active
July 27, 2026 22:34
-
-
Save henri/2ca35e523461d5c5dff26c20879e7dbd to your computer and use it in GitHub Desktop.
linux detect activated strace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Detect processes being ptraced via /proc/<pid>/status | |
| # I am sure there are better ways! | |
| while true; do | |
| for pid in /proc/[0-9]*/status; do | |
| tracer=$(grep -m1 "^TracerPid:" "$pid" 2>/dev/null | awk '{print $2}') | |
| if [[ -n "$tracer" && "$tracer" != "0" ]]; then | |
| target_pid=$(echo "$pid" | grep -oP '\d+') | |
| tracer_comm=$(cat /proc/${tracer}/comm 2>/dev/null) | |
| target_comm=$(cat /proc/${target_pid}/comm 2>/dev/null) | |
| echo "[!] $(date): '$tracer_comm' (PID $tracer) is tracing '$target_comm' (PID $target_pid)" | |
| fi | |
| done | |
| sleep 1 | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment