forked from trailofbits/clang-cfi-showcase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfi_vcall.cpp
48 lines (37 loc) · 891 Bytes
/
cfi_vcall.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
#include <iostream>
struct Base {
Base() {}
virtual ~Base() {}
virtual void printMe() {
std::cout << "Base::printMe\n";
}
};
struct Derived : Base {
Derived() {}
virtual ~Derived() {}
virtual void printMe() {
std::cout << "Derived::printMe\n";
}
};
// imagine this is an attacker-created structure
// in memory
struct Evil {
Evil() {}
virtual ~Evil() {}
virtual void makeAdmin() {
std::cout << "CFI Prevents this control flow\n";
std::cout << "Evil::makeAdmin\n";
}
};
int main(int argc, const char *argv[]) {
Evil *eptr = new Evil();
Derived* dptr = new Derived();
(void)(argc);
(void)(argv);
dptr->printMe();
// imagine a type confusion vulnerability
// that does something similar
dptr = reinterpret_cast<Derived*>(eptr);
dptr->printMe();
return 0;
}