DLL means Dynamic-Link Library. It exposes functions to be used consumed by other binaries. These are called exports.
#define DLL_EXPORTextern"C" {
DECLDIR intAdd(int a, int b){
return(a + b);
}
typedefint(*addFunc)(int, int); // We define the function signature; takes 2 int, returns 1 int
addFunc _AddFunc;
HINSTANCE haModule = LoadLibrary("add.dll"); // Locate our DLL
_AddFunc = (AddFunc)GetProcAddress(hInstLibrary, "Add"); // Get a pointer to the function `Add`int res = _AddFunc(23, 43);
There's not much difference between PE files and DLL. A DLL will often expose a few functions meanwhile a PE file usually only exposes one.
Both have a main function. When a DLL is load, its main function is called.
You can call a DLL using rundll32.exe myDll,MyExport arg1 arg2, or regsvr32.exe myDll and more.
rundll32.exe add.dll,Add 1 2
Strings
Can we find interesting strings?
Imports
A binary will require functions to work, these must be imported.
In Linux, it would look like #include <string.h>.
It there's an import called CreateFile or ShellExecute, you can guess what the malware might do.
A malware will often try to hide what it can do; it will do dynamic imports resolution.
Dynamic analysis
Sometimes, dynamic analysis will be faster. xdbg is a free and open source for Windows. You can load and debug a DLL.
Useful shortcuts
F7: step into (goes into the function) F8: step over (if you don't want to debug a function called) bp Add: put a breakpoint to a specific function bpc Add: remove that breakpoint
IDA
Useful shortcuts
<x>: to get the cross references of variables/functions <n>: to rename a function/variable <y>: change the type of a function/variable <g>: goto some address <esc>: go back </>: add a comment in decompilation view <;>: add a comment in disassembly view
Your turn! (~30 minutes)
Now that we've seen basic concepts, time to put it into practice