* '''libcap Library''': The core library that provides functions for managing capabilities. * '''capsh Utility''': A command-line tool for setting and querying capabilities. * '''Capabilities Header''': Defines the various capabilities that can be assigned to processes.
* '''Fine-Grained Privilege Control''': Allows granting specific capabilities to processes, reducing the need for full root privileges. * '''Compatibility''': Provides a standardized way to manage capabilities across different Linux distributions. * '''Security Enhancement''': Helps minimize the risk of privilege escalation by limiting the capabilities of processes.
```bash sudo setcap cap_net_bind_service=+ep /usr/bin/example ``` This command grants the `cap_net_bind_service` capability to the `example` executable, allowing it to bind to privileged ports.
```bash getcap /usr/bin/example ``` This command displays the capabilities assigned to the `example` executable.
```bash capsh --caps="cap_net_admin,cap_net_raw+ep" -- -c /bin/bash ``` This command opens a new shell with the `cap_net_admin` and `cap_net_raw` capabilities.
```bash sudo setcap -r /usr/bin/example ``` This command removes all capabilities from the `example` executable.
```c #include
int main() { cap_t caps; caps = cap_get_proc(); if (caps == NULL) { perror("cap_get_proc"); return 1; } cap_free(caps); return 0; } ```