This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdllmain.cpp
69 lines (61 loc) · 2.71 KB
/
dllmain.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
#include <Windows.h>
//we are hijacking dll XmlLite so define where original one is located
#define ORIG_DLL ("C:\\Windows\\System32\\XmlLite.dll")
typedef void(*fnDummy)(); //return value or parameters are unimportant, we just want it to jump
fnDummy gCreateXmlReader;
fnDummy gCreateXmlReaderInputWithEncodingCodePage;
fnDummy gCreateXmlReaderInputWithEncodingName;
fnDummy gCreateXmlWriter;
fnDummy gCreateXmlWriterOutputWithEncodingCodePage;
fnDummy gCreateXmlWriterOutputWithEncodingName;
extern "C" __declspec(dllexport) void CreateXmlReader() //these all should compile as only single instruction functions: jmp qword ptr[...]
{
gCreateXmlReader();
}
extern "C" __declspec(dllexport) void CreateXmlReaderInputWithEncodingCodePage()
{
gCreateXmlReaderInputWithEncodingCodePage();
}
extern "C" __declspec(dllexport) void CreateXmlReaderInputWithEncodingName()
{
gCreateXmlReaderInputWithEncodingName();
}
extern "C" __declspec(dllexport) void CreateXmlWriter()
{
gCreateXmlWriter();
}
extern "C" __declspec(dllexport) void CreateXmlWriterOutputWithEncodingCodePage()
{
gCreateXmlWriterOutputWithEncodingCodePage();
}
extern "C" __declspec(dllexport) void CreateXmlWriterOutputWithEncodingName()
{
gCreateXmlWriterOutputWithEncodingName();
}
fnDummy GetDllExport(LPCSTR DllName, LPCSTR ExportName)
{
return (fnDummy)GetProcAddress(LoadLibraryA(DllName), ExportName);
}
BOOL WriteToReadOnly(PVOID Address, PVOID Buffer, SIZE_T Size)
{
return WriteProcessMemory(GetCurrentProcess(), Address, Buffer, Size, 0);
}
BYTE fixCertVerifyTimeValidity[] = {0x48, 0x31, 0xC0, 0xC3}; //xor rax,rax | ret
BYTE fixGetSystemTimeAsFileTime[] = {0x48, 0x83, 0x21, 0x00, 0xC3}; //and qword ptr[rcx],0x00 | ret
BOOL APIENTRY entry(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason != DLL_PROCESS_ATTACH)
return TRUE;
DisableThreadLibraryCalls(hModule);
if ((gCreateXmlReader = GetDllExport(ORIG_DLL, "CreateXmlReader")) &&
(gCreateXmlReaderInputWithEncodingCodePage = GetDllExport(ORIG_DLL, "CreateXmlReaderInputWithEncodingCodePage")) &&
(gCreateXmlReaderInputWithEncodingName = GetDllExport(ORIG_DLL, "CreateXmlReaderInputWithEncodingName")) &&
(gCreateXmlWriter = GetDllExport(ORIG_DLL, "CreateXmlWriter")) &&
(gCreateXmlWriterOutputWithEncodingCodePage = GetDllExport(ORIG_DLL, "CreateXmlWriterOutputWithEncodingCodePage")) &&
(gCreateXmlWriterOutputWithEncodingName = GetDllExport(ORIG_DLL, "CreateXmlWriterOutputWithEncodingName")))
{
return WriteToReadOnly(GetDllExport("crypt32.dll", "CertVerifyTimeValidity"), fixCertVerifyTimeValidity, sizeof fixCertVerifyTimeValidity) &&
WriteToReadOnly(GetDllExport("KernelBase.dll", "GetSystemTimeAsFileTime"), fixGetSystemTimeAsFileTime, sizeof fixGetSystemTimeAsFileTime);
}
return FALSE;
}