forked from WKL-Sec/LayeredSyscall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.cpp
61 lines (48 loc) · 2.06 KB
/
demo.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
#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string>
#include <iostream>
#include <Windows.h>
#include "HookModule.h"
#include "FuncWrappers.h"
#include "imports.h"
#pragma comment(lib, "ntdll.lib")
///////////////////////////////////////////////
// Macro Definitions //
/////////////////////////////////////////////
#define NT_SUCCESS(Status) ((NTSTATUS)(Status) >= 0)
int main(int argc, char* argv[]) {
printf("[*] Program Started\n");
IntializeHooks();
WCHAR image_path[] = L"\\??\\C:\\Windows\\System32\\calc.exe";
UNICODE_STRING NtImagePath;
RtlInitUnicodeString(&NtImagePath, (PWSTR)L"\\??\\C:\\Windows\\System32\\calc.exe");
// Create the process parameters
PRTL_USER_PROCESS_PARAMETERS ProcessParameters = NULL;
RtlCreateProcessParametersEx(&ProcessParameters, &NtImagePath, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, RTL_USER_PROCESS_PARAMETERS_NORMALIZED);
// Initialize the PS_CREATE_INFO structure
PS_CREATE_INFO CreateInfo = { 0 };
CreateInfo.Size = sizeof(CreateInfo);
CreateInfo.State = PsCreateInitialState;
// Initialize the PS_ATTRIBUTE_LIST structure
PPS_ATTRIBUTE_LIST AttributeList = (PS_ATTRIBUTE_LIST*)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PS_ATTRIBUTE));
AttributeList->TotalLength = sizeof(PS_ATTRIBUTE_LIST) - sizeof(PS_ATTRIBUTE);
AttributeList->Attributes[0].Attribute = PS_ATTRIBUTE_IMAGE_NAME;
AttributeList->Attributes[0].Size = NtImagePath.Length;
AttributeList->Attributes[0].Value = (ULONG_PTR)NtImagePath.Buffer;
HANDLE hProcess, hThread = NULL;
BOOL success = FALSE;
LPVOID remote_base_addr = NULL;
CONTEXT thread_context = { 0 };
// create the target process in a suspended state so we can modify its memory and the context of its main thread
if (wrpNtCreateUserProcess(&hProcess, &hThread, PROCESS_ALL_ACCESS, THREAD_ALL_ACCESS, NULL, NULL,
NULL, NULL, ProcessParameters, &CreateInfo, AttributeList))
{
printf("CreateProcessA() Failed with error: %d\n", GetLastError());
return -1;
}
DestroyHooks();
printf("[*] Program Ended\n");
return 1;
}