GrepBoard/Manuals
605 manuals ·

Find setuid files and file capabilities: why ping has no setuid

·Tested on Ubuntu 24.04.5, Rocky Linux 9 (Docker) · 2026-10·Test scope ↓·6 steps

List setuid binaries with find -perm -4000 and file capabilities with getcap -r /. Ubuntu 24.04 vs Rocky 9, and two ways ping works without setuid.

A setuid file runs with the privileges of its owner (usually root), not of the user who started it. To audit them, list them with find / -xdev -perm -4000 and check which package each one belongs to. Current distributions replaced some setuid programs with file capabilities, so check getcap -r / as well.

[1] Find setuid files. -xdev keeps find off other file systems (/proc, network mounts). This is an Ubuntu 24.04 container with iputils-ping, sudo and openssh-client added.

console
$ find / -xdev -perm -4000 -type f 2>/dev/null | sort/usr/bin/chfn/usr/bin/chsh/usr/bin/gpasswd/usr/bin/mount/usr/bin/newgrp/usr/bin/passwd/usr/bin/su/usr/bin/sudo/usr/bin/umount/usr/lib/openssh/ssh-keysign

Find setgid files the same way with -perm -2000; on Ubuntu there were five, including chage, expiry, ssh-agent and unix_chkpwd.

-xdev also skips local disks if they are a different file system from /. On a real server with separate /usr, /opt, /var or /home mounts, scanning / alone misses every setuid file inside them. List the local file systems first and repeat the search from each mount point:

console
$ findmnt -rn -o TARGET -t ext4,xfs,btrfs$ for m in $(findmnt -rn -o TARGET -t ext4,xfs,btrfs); do find "$m" -xdev -perm -4000 -type f 2>/dev/null; done | sort -u

Add other types (zfs and so on) to -t if you use them. Run the later find / -xdev … commands per mount point the same way.

[2] Map each file to its package. A setuid file that belongs to no package deserves the first look.

console
$ find / -xdev -perm -4000 -type f -exec dpkg -S {} + 2>&1 | sortlogin: /usr/bin/newgrpmount: /usr/bin/mountmount: /usr/bin/umountopenssh-client: /usr/lib/openssh/ssh-keysignpasswd: /usr/bin/chfnpasswd: /usr/bin/chshpasswd: /usr/bin/gpasswdpasswd: /usr/bin/passwdsudo: /usr/bin/sudoutil-linux: /usr/bin/su

Every file belonged to a package in this test. If a line shows an error instead of a package name, start there. On Rocky 9 use -exec rpm -qf {} +. To check whether packaged files were modified, continue with debsums and rpm -V.

[3] Find file capabilities. On Ubuntu 24.04 only ping had one:

console
$ getcap -r / 2>/dev/null/usr/bin/ping cap_net_raw=ep

cap_net_raw grants only the right to open raw sockets, a much narrower scope than setuid root (capabilities(7)). In the same test Rocky 9 had cap_net_raw=p on arping and clockdiff, not on ping.

ItemUbuntu 24.04.5Rocky Linux 9
setuid files1011
setuid only on Rockychage, pam_timestamp_check, unix_chkpwd, userhelper
setuid only on Ubuntuchfn, chsh, ssh-keysign
pingcap_net_raw=epNo capability, no setuid

[4] See how Rocky's ping works without privileges. The kernel's ICMP datagram sockets let groups inside net.ipv4.ping_group_range ping without raw-socket rights. Docker sets this to 0 2147483647 in containers, so both images could ping as nobody. Starting the container with the kernel default 1 0 (nobody allowed) separates them:

console
$ setpriv --reuid=65534 --regid=65534 --clear-groups ping -c1 -W1 127.0.0.1 | head -2ping: socket: Operation not permitted

That is Rocky 9 started with --sysctl "net.ipv4.ping_group_range=1 0". Ubuntu under the same condition still got a reply as nobody thanks to cap_net_raw. Ubuntu relies on the file capability, Rocky on ping_group_range.

[5] Check your own server. If cat /proc/sys/net/ipv4/ping_group_range prints 1 0, no group may use ICMP datagram sockets, and regular users can ping only if getcap /usr/bin/ping shows cap_net_raw.

console
$ cat /proc/sys/net/ipv4/ping_group_range$ getcap /usr/bin/ping

If ping fails for regular users on a Rocky 9 server with socket: Operation not permitted, check ping_group_range. Installing systemd in a Rocky 9 container showed no file under /usr/lib/sysctl.d/ that sets this value; where a real Rocky server gets its value was not verified.

[6] Keep a baseline. With the list saved, the next audit only needs the difference.

console
$ find / -xdev -perm /6000 -type f 2>/dev/null | sort > /root/suid-baseline.txt$ find / -xdev -perm /6000 -type f 2>/dev/null | sort | diff /root/suid-baseline.txt -

If a new file did not come from a package update, check its owner and time with ls -l. Remove an unneeded setuid bit with chmod u-s <file>. Removing it from a packaged file takes that feature away from regular users (for example changing shells with chsh); to undo, use chmod u+s <file> or reinstall the package.

#setuid#capabilities#getcap#ping#security