-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathReflectiveDll.cpp
More file actions
65 lines (54 loc) · 3.3 KB
/
Copy pathReflectiveDll.cpp
File metadata and controls
65 lines (54 loc) · 3.3 KB
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
//===============================================================================================//
// This is a stub for the actuall functionality of the DLL.
//===============================================================================================//
#include "stdafx.h"
#include "ReflectiveLoader.h"
#include "PowerShellRunnerDll.h"
#include "UnmanagedPowerShell.h"
// Note: REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR and REFLECTIVEDLLINJECTION_CUSTOM_DLLMAIN are
// defined in the project properties (Properties->C++->Preprocessor) so as we can specify our own
// DllMain and use the LoadRemoteLibraryR() API to inject this DLL.
// You can use this value as a pseudo hinstDLL value (defined and set via ReflectiveLoader.c)
extern HINSTANCE hAppInstance;
void DoStuff(LPVOID lpParam)
{
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
_Type* PsRuntime = NULL;
HRESULT hr = NULL;
wchar_t* argument = L"Invoke-Replace ";
hr = SetupPSRuntime(&PsRuntime);
if (SUCCEEDED(hr) && PsRuntime != NULL) {
InvokeMethod(PsRuntime, L"InvokePS", argument);
CoUninitialize();
//return 0;
}
else {
//return -1;
}
}
// Currently called by Invoke-ReflectivePEInjection. This export will be removed once we're using Invoke-ShellCode instead.
extern "C" __declspec(dllexport) void VoidFunc()
{
DoStuff(NULL);
}
//===============================================================================================//
BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved )
{
BOOL bReturnValue = TRUE;
switch( dwReason )
{
case DLL_QUERY_HMODULE:
if( lpReserved != NULL )
*(HMODULE *)lpReserved = hAppInstance;
break;
case DLL_PROCESS_ATTACH:
hAppInstance = hinstDLL;
//DoStuff(NULL);
break;
case DLL_PROCESS_DETACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
}
return bReturnValue;
}