#include "libkdump.h" #include #include #include #include #include #include #include #include const char *strings[] = { "If you can read this, this is really bad", "Burn after reading this string, it is a secret string", "Congratulations, you just spied on an application", "Wow, you broke the security boundary between user space and kernel", "Welcome to the wonderful world of microarchitectural attacks", "Please wait while we steal your secrets...", "Don't panic... But your CPU is broken and your data is not safe", "How can you read this? You should not read this!"}; int main(int argc, char *argv[]) { libkdump_config_t config; int fd; char *p, *q; config = libkdump_get_autoconfig(); libkdump_init(config); srand(time(NULL)); const char *secret = strings[rand() % (sizeof(strings) / sizeof(strings[0]))]; int len = strlen(secret); fd = open("/home/aaron/test", O_RDWR); if (fd == -1) { perror("open"); return -1; } ftruncate(fd, 0x1000); p = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (p == MAP_FAILED) { perror("mmap"); close(fd); return -1; } memcpy(p, secret, len); printf("\x1b[32;1m[+]\x1b[0m Secret: \x1b[33;1m%s\x1b[0m\n", p); size_t paddr = libkdump_virt_to_phys((size_t)p); if (!paddr) { printf("\x1b[31;1m[!]\x1b[0m Program requires root privileges (or read access to /proc//pagemap)!\n"); libkdump_cleanup(); exit(1); } printf("\x1b[32;1m[+]\x1b[0m Physical address of secret: \x1b[32;1m0x%zx\x1b[0m\n", paddr); printf("\x1b[32;1m[+]\x1b[0m Exit with \x1b[37;1mCtrl+C\x1b[0m if you are done reading the secret\n"); while (1) { // keeps doing write(2) such that the direct map will stay in TLB write(fd, secret, len); sched_yield(); lseek(fd, 0, SEEK_SET); } libkdump_cleanup(); return 0; }