Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
banshee:~> ls -l `which ping`
-rwsr-xr-x 1 root root 31360 Окт 14 2010 /bin/ping
banshee:~> getcap `which ping`
getcap: Command not found.
banshee:~> uname -r
2.6.32-5-686
$ cat /etc/debian_version 7.2 $ uname -r 2.6.32-042stab076.8 $ ls -l `which ping` -rwsr-xr-x 1 root root 36136 Апр 12 2011 /bin/ping
$ ls -l /bin/ping
-rwsr-xr-x 1 root root 39928 May 15 2013 /bin/ping
$ getcap /bin/ping
$ cat /etc/debian_version
jessie/sid
$ uname -r
3.11-2-amd64ls -l `which ping`
getcap `which ping`
ps auxwww | grep ping | grep -v grep
enable_capability_raw();
icmp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
socket_errno = errno;
disable_capability_raw();
/* ... */
enable_capability_raw();
rc = setsockopt(probe_fd, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device)+1);
disable_capability_raw();
Версия iputils-ping в Debian Jessie (s20121221) способна работать как с использованием suid bit, так и с использованием capabilities.
Если препроцессор видит определённым макрос CAPABILITES, он использует версию с capabilites, иначе — с setuid
$ apt-cache show iputils-ping | egrep -e '^(Version|Depends)'
Version: 3:20121221-1
Depends: libc6 (>= 2.14), libcap2 (>= 2.10), libgnutls-openssl27[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP, CAP_CHOWN|CAP_DAC_OVERRIDE|CAP_DAC_READ_SEARCH|CAP_FOWNER|CAP_FSETID|CAP_KILL|CAP_SETGID|CAP_SETUID|CAP_SETPCAP|CAP_LINUX_IMMUTABLE|CAP_NET_BIND_SERVICE|CAP_NET_BROADCAST|CAP_NET_ADMIN|CAP_NET_RAW|CAP_IPC_LOCK|CAP_IPC_OWNER|CAP_SYS_MODULE|CAP_SYS_RAWIO|CAP_SYS_CHROOT|CAP_SYS_PTRACE|CAP_SYS_PACCT|CAP_SYS_ADMIN|CAP_SYS_BOOT|CAP_SYS_NICE|CAP_SYS_RESOURCE|CAP_SYS_TIME|CAP_SYS_TTY_CONFIG|CAP_MKNOD|CAP_LEASE|CAP_AUDIT_WRITE|CAP_AUDIT_CONTROL|CAP_SETFCAP, 0}) = 0
[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9707] capset({_LINUX_CAPABILITY_VERSION_3, 0}, {0, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9707] prctl(PR_SET_KEEPCAPS, 1) = 0
[pid 9707] getuid() = 1000
[pid 9707] setuid(1000) = 0
[pid 9707] prctl(PR_SET_KEEPCAPS, 0) = 0
[pid 9707] getuid() = 1000
[pid 9707] geteuid() = 1000
[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, {0, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9707] capset({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_NET_RAW, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9707] socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9707] capget({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_NET_RAW, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9707] capset({_LINUX_CAPABILITY_VERSION_3, 0}, {0, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9707] socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 4
[pid 9707] connect(4, {sa_family=AF_INET, sin_port=htons(1025), sin_addr=inet_addr("8.8.8.8")}, 16) = 0
[pid 9707] getsockname(4, {sa_family=AF_INET, sin_port=htons(61820), sin_addr=inet_addr("x.x.x.x")}, [16]) = 0
[pid 9707] close(4) = 0
[pid 9707] setsockopt(3, SOL_IP, IP_MTU_DISCOVER, [2], 4) = 0
[pid 9707] setsockopt(3, SOL_RAW, ICMP_FILTER, ~(ICMP_ECHOREPLY|ICMP_DEST_UNREACH|ICMP_SOURCE_QUENCH|ICMP_REDIRECT|ICMP_TIME_EXCEEDED|ICMP_PARAMETERPROB), 4) = 0
[pid 9707] setsockopt(3, SOL_IP, IP_RECVERR, [1], 4) = 0
[pid 9707] setsockopt(3, SOL_SOCKET, SO_SNDBUF, [268], 4) = 0
[pid 9707] setsockopt(3, SOL_SOCKET, SO_RCVBUF, [65536], 4) = 0
[pid 9707] getsockopt(3, SOL_SOCKET, SO_RCVBUF, [131072], [4]) = 0
[pid 9707] fstat(1, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
[pid 9707] ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff5cc2eff0) = -1 ENOTTY (Inappropriate ioctl for device)
[pid 9707] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3359eb2000
[pid 9707] setsockopt(3, SOL_SOCKET, SO_TIMESTAMP, [1], 4) = 0
[pid 9707] setsockopt(3, SOL_SOCKET, SO_SNDTIMEO, "\0\0\0\0\0\0\0\0\340\223\4\0\0\0\0\0", 16) = 0
[pid 9707] setsockopt(3, SOL_SOCKET, SO_RCVTIMEO, "\0\0\0\0\0\0\0\0\340\223\4\0\0\0\0\0", 16) = 0
[pid 9707] getpid() = 9707
[pid 9707] rt_sigaction(SIGINT, {0x404320, [], SA_RESTORER|SA_INTERRUPT, 0x7f3359719250}, NULL, 8) = 0
[pid 9707] rt_sigaction(SIGALRM, {0x404320, [], SA_RESTORER|SA_INTERRUPT, 0x7f3359719250}, NULL, 8) = 0
[pid 9707] rt_sigaction(SIGQUIT, {0x404310, [], SA_RESTORER|SA_INTERRUPT, 0x7f3359719250}, NULL, 8) = 0
[pid 9707] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 9707] ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff5cc2f510) = -1 ENOTTY (Inappropriate ioctl for device)
[pid 9707] sendmsg(3, {msg_name(16)={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("8.8.8.8")}, msg_iov(1)=[{"\10\0\322\23%\353\0\1", 8}], msg_controllen=0, msg_flags=0}, 0) = 8
[pid 9707] setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
[pid 9707] recvmsg(3, {msg_name(16)={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("8.8.8.8")}, msg_iov(1)=[{"E\0\0\34\0\0\0\0.\1\277\24\10\10\10\10Y\263d\n\0\0\332\23%\353\0\1", 136}], msg_controllen=32, {cmsg_len=32, cmsg_level=SOL_SOCKET, cmsg_type=0x1d /* SCM_??? */, ...}, msg_flags=0}, 0) = 28
[pid 9707] write(1, "PING 8.8.8.8 (8.8.8.8) 0(28) bytes of data.\n8 bytes from 8.8.8.8: icmp_seq=1 ttl=46\n", 84) = 84
[pid 9707] write(1, "\n", 1) = 1
[pid 9707] write(1, "--- 8.8.8.8 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\n\n", 93) = 93
[pid 9707] exit_group(0) = ?
[pid 9707] +++ exited with 0 +++[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_NET_ADMIN|CAP_NET_RAW, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9760] capset({_LINUX_CAPABILITY_VERSION_3, 0}, {0, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9760] prctl(PR_SET_KEEPCAPS, 1) = 0
[pid 9760] getuid() = 1000
[pid 9760] setuid(1000) = 0
[pid 9760] prctl(PR_SET_KEEPCAPS, 0) = 0
[pid 9760] getuid() = 1000
[pid 9760] geteuid() = 1000
[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, {0, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9760] capset({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_NET_RAW, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9760] socket(PF_INET, SOCK_RAW, IPPROTO_ICMP) = 3
[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, NULL) = 0
[pid 9760] capget({_LINUX_CAPABILITY_VERSION_3, 0}, {CAP_NET_RAW, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9760] capset({_LINUX_CAPABILITY_VERSION_3, 0}, {0, CAP_NET_ADMIN|CAP_NET_RAW, 0}) = 0
[pid 9760] socket(PF_INET, SOCK_DGRAM, IPPROTO_IP) = 4
[pid 9760] connect(4, {sa_family=AF_INET, sin_port=htons(1025), sin_addr=inet_addr("8.8.8.8")}, 16) = 0
[pid 9760] getsockname(4, {sa_family=AF_INET, sin_port=htons(51535), sin_addr=inet_addr("x.x.x.x")}, [16]) = 0
[pid 9760] close(4) = 0
[pid 9760] setsockopt(3, SOL_IP, IP_MTU_DISCOVER, [2], 4) = 0
[pid 9760] setsockopt(3, SOL_RAW, ICMP_FILTER, ~(ICMP_ECHOREPLY|ICMP_DEST_UNREACH|ICMP_SOURCE_QUENCH|ICMP_REDIRECT|ICMP_TIME_EXCEEDED|ICMP_PARAMETERPROB), 4) = 0
[pid 9760] setsockopt(3, SOL_IP, IP_RECVERR, [1], 4) = 0
[pid 9760] setsockopt(3, SOL_SOCKET, SO_SNDBUF, [268], 4) = 0
[pid 9760] setsockopt(3, SOL_SOCKET, SO_RCVBUF, [65536], 4) = 0
[pid 9760] getsockopt(3, SOL_SOCKET, SO_RCVBUF, [131072], [4]) = 0
[pid 9760] fstat(1, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
[pid 9760] ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff3956ed70) = -1 ENOTTY (Inappropriate ioctl for device)
[pid 9760] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb83f4d5000
[pid 9760] setsockopt(3, SOL_SOCKET, SO_TIMESTAMP, [1], 4) = 0
[pid 9760] setsockopt(3, SOL_SOCKET, SO_SNDTIMEO, "\0\0\0\0\0\0\0\0\340\223\4\0\0\0\0\0", 16) = 0
[pid 9760] setsockopt(3, SOL_SOCKET, SO_RCVTIMEO, "\0\0\0\0\0\0\0\0\340\223\4\0\0\0\0\0", 16) = 0
[pid 9760] getpid() = 9760
[pid 9760] rt_sigaction(SIGINT, {0x404320, [], SA_RESTORER|SA_INTERRUPT, 0x7fb83ed3c250}, NULL, 8) = 0
[pid 9760] rt_sigaction(SIGALRM, {0x404320, [], SA_RESTORER|SA_INTERRUPT, 0x7fb83ed3c250}, NULL, 8) = 0
[pid 9760] rt_sigaction(SIGQUIT, {0x404310, [], SA_RESTORER|SA_INTERRUPT, 0x7fb83ed3c250}, NULL, 8) = 0
[pid 9760] rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
[pid 9760] ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7fff3956f290) = -1 ENOTTY (Inappropriate ioctl for device)
[pid 9760] sendmsg(3, {msg_name(16)={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("8.8.8.8")}, msg_iov(1)=[{"\10\0\321\336& \0\1", 8}], msg_controllen=0, msg_flags=0}, 0) = 8
[pid 9760] setitimer(ITIMER_REAL, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
[pid 9760] recvmsg(3, {msg_name(16)={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("8.8.8.8")}, msg_iov(1)=[{"E\0\0\34\0\0\0\0.\1\277\24\10\10\10\10Y\263d\n\0\0\331\336& \0\1", 136}], msg_controllen=32, {cmsg_len=32, cmsg_level=SOL_SOCKET, cmsg_type=0x1d /* SCM_??? */, ...}, msg_flags=0}, 0) = 28
[pid 9760] write(1, "PING 8.8.8.8 (8.8.8.8) 0(28) bytes of data.\n8 bytes from 8.8.8.8: icmp_seq=1 ttl=46\n", 84) = 84
[pid 9760] write(1, "\n", 1) = 1
[pid 9760] write(1, "--- 8.8.8.8 ping statistics ---\n1 packets transmitted, 1 received, 0% packet loss, time 0ms\n\n", 93) = 93
[pid 9760] exit_group(0) = ?
[pid 9760] +++ exited with 0 +++Использовать backticks нехорошо.
test # ls -l `which ping`
-rws--x--x 1 root root 40464 янв. 31 2013 /bin/ping
test # getcap `which ping`
test # uname -anr
Linux test 3.9.7-gentoo #1 SMP PREEMPT Thu Jun 27 03:56:35 UTC 2013 i686 Pentium(R) Dual-Core CPU E5800 @ 3.20GHz GenuineIntel GNU/Linux
Re: Отчёт и задания со всероссийской олимпиады по администрированию Linux-систем