forked from bcoles/kasld
-
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.
Read kernel messages from both klogctl() and /var/log/dmesg
- Loading branch information
Showing
19 changed files
with
686 additions
and
231 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ | |
// that looks like a kernel pointer. | ||
// | ||
// Requires: | ||
// - kernel.dmesg_restrict = 0; or CAP_SYSLOG capabilities. | ||
// - kernel.dmesg_restrict = 0; or CAP_SYSLOG capabilities; or | ||
// readable /var/log/dmesg. | ||
// - kernel.panic_on_oops = 0 (Default on most systems). | ||
// --- | ||
// <[email protected]> | ||
|
@@ -49,8 +50,51 @@ unsigned long search_dmesg_kernel_pointers() { | |
return addr; | ||
} | ||
|
||
unsigned long search_dmesg_log_file_kernel_pointers() { | ||
FILE *f; | ||
char *ptr; | ||
char *endptr; | ||
char *line = 0; | ||
size_t size = 0; | ||
const char *path = "/var/log/dmesg"; | ||
unsigned long leaked_addr = 0; | ||
unsigned long addr = 0; | ||
|
||
printf("[.] searching %s for call trace kernel pointers ...\n", path); | ||
|
||
f = fopen(path, "rb"); | ||
|
||
if (f == NULL) { | ||
perror("[-] fopen"); | ||
return 0; | ||
} | ||
|
||
while ((getline(&line, &size, f)) != -1) { | ||
ptr = strtok(line, "[<"); | ||
while ((ptr = strtok(NULL, "[<")) != NULL) { | ||
leaked_addr = strtoul(&ptr[0], &endptr, 16); | ||
|
||
if (!leaked_addr) | ||
continue; | ||
|
||
if (leaked_addr >= KERNEL_BASE_MIN && leaked_addr <= KERNEL_BASE_MAX) { | ||
// printf("Found kernel pointer: %lx\n", leaked_addr); | ||
if (!addr || leaked_addr < addr) | ||
addr = leaked_addr; | ||
} | ||
} | ||
} | ||
|
||
fclose(f); | ||
|
||
return addr; | ||
} | ||
|
||
int main() { | ||
unsigned long addr = search_dmesg_kernel_pointers(); | ||
if (!addr) | ||
addr = search_dmesg_log_file_kernel_pointers(); | ||
|
||
if (!addr) | ||
return 1; | ||
|
||
|
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
Oops, something went wrong.