Guillaume Destuynder: Lesser-known tool of the day: getcap, setcap and file capabilities |
See also: `man capabilities’
Linux’s thread/process privilege checking is based on capabilities. They’re flags to the thread that indicate what kind of additional privileges they’re allowed to use. By default, root has all of these.
CAP_DAC_OVERRIDE: Override read/write/execute permission checks (full filesystem access).
CAP_DAC_READ_SEARCH: Only override reading files and opening/listing directories (full filesystem READ access).
CAP_KILL: Can send any signal to any process (such as sig kill).
CAP_SYS_CHROOT: Ability to call chroot().
And so on.
These are useful when you want to restrict your own processes after performing privileged operations. For example, after setting up chroot and binding to a socket. (However, it’s still more limited than seccomp or SELinux, which are based on system calls instead).
You can force capabilities upon programs using setcap, and query these using getcap.
For example, on many Linux distributions you’ll find ping with cap_net_raw (which allows ping to create raw sockets). This means ping doesn’t need to run as root (via setuid, in general) anymore:
getcap /sbin/ping /sbin/ping = cap_net_raw+ep
This has initially been set by a user with cap_setfcap (root has it by default), via this command:
setcap cap_net_raw+ep /sbin/ping
You can find the list of capabilities via:
man capabilities
The “+ep” means you’re adding the capability (“-” would remove it) as Effective and Permitted.
There are 3 modes:
More info:
man cap_from_text
While capabilities are relatively well known by Linux C programmers (generally used either in kernel for limiting access to resources, either in user space to drop capabilities while still running as root user) – they’re obscure to most non-programmers.
It’s important to know about their existence for forensic purposes, for example – since those programs have a subset of what’s available to a setuid(0) (i.e. root) program.
Here’s some more usage examples:
https://www.insecure.ws/2013/12/17/lesser-known-tool-of-the-day-getcap-setcap-and-file-capabilities/
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |