-
Notifications
You must be signed in to change notification settings - Fork 4
/
cartoon.cpp
46 lines (38 loc) · 946 Bytes
/
cartoon.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
/*
cartoon.cpp - victim program example 1
DLL hijacking with exported functions example
author: @cocomelonc
*/
#include <windows.h>
#include <cstdio>
typedef VOID (__cdecl *CatProc)(); // cat
typedef VOID (__cdecl *BirdProc)(); // bird
typedef VOID (__cdecl *MouseProc)(); // mouse
int main(void) {
// main dll with exported functions
HINSTANCE petDll;
// pets
CatProc catFunc;
BirdProc birdFunc;
MouseProc mouseFunc;
// free memory
BOOL freeRes;
// load pet.dll
petDll = LoadLibrary(TEXT("pet.dll"));
if (petDll != NULL) {
catFunc = (CatProc) GetProcAddress(petDll, "Cat");
birdFunc = (BirdProc) GetProcAddress(petDll, "Bird");
mouseFunc = (MouseProc) GetProcAddress(petDll, "Mouse");
if (catFunc != NULL) {
(catFunc) ();
}
if (birdFunc != NULL) {
(birdFunc) ();
}
if (mouseFunc != NULL) {
(mouseFunc) ();
}
freeRes = FreeLibrary(petDll);
}
return 0;
}