-
Notifications
You must be signed in to change notification settings - Fork 5
/
tsr.cpp
54 lines (42 loc) · 1.43 KB
/
tsr.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
#include <windows.h>
#include <stdio.h>
VOID NTAPI TerminateAndStayResidentProc(PVOID, BOOLEAN)
{
printf("hi!\n");
OutputDebugStringA("Still here!\n");
// obvious things to do here:
// - check for existance of a file in a hardcoded path and, if present, execute it
// - check for existance of a section object and, if present, map it in and execute it
// - check for pending incoming connection on a pre-created SOCKET and accept the connection...
// - check for event being set and, if so, self-terminate the timer queue
// - check for registry value and, if present, read file or shellcode and execute it
// - check for system shutdown notification and, if shutting down, persist to disk
}
int wmain(int argc, WCHAR **argv)
{
HRESULT hr = E_UNEXPECTED;
HANDLE hTimerQueue = NULL,
hTimer = NULL;
hTimerQueue = CreateTimerQueue();
if (NULL == hTimerQueue)
{
goto ErrorExit;
}
if (!CreateTimerQueueTimer(&hTimer, hTimerQueue, TerminateAndStayResidentProc, NULL, 1000, 1000, 0))
{
hr = HRESULT_FROM_WIN32(GetLastError());
goto ErrorExit;
}
Sleep(INFINITE);
hr = S_OK;
ErrorExit:
if (NULL != hTimer)
{
(void)DeleteTimerQueueTimer(hTimerQueue, hTimer, INVALID_HANDLE_VALUE);
}
if (NULL != hTimerQueue)
{
(void)DeleteTimerQueueEx(hTimerQueue, INVALID_HANDLE_VALUE);
}
return 0;
}