Skip to content

Commit 2a77e0d

Browse files
committed
Some Improvements
1 parent 3016177 commit 2a77e0d

6 files changed

Lines changed: 70 additions & 37 deletions

File tree

Process.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include "injection.h"
2+
3+
int GetPIDByName(const char* ProcName) {
4+
PROCESSENTRY32 PE32{ 0 };
5+
PE32.dwSize = sizeof(PE32);
6+
7+
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
8+
if (hSnap == INVALID_HANDLE_VALUE) {
9+
printf("[-] CreateToolhelp32Snapshot error: 0x%X\n", GetLastError());
10+
system("pause");
11+
return 0;
12+
}
13+
14+
DWORD PID = 0;
15+
BOOL bRet = Process32FirstW(hSnap, &PE32);
16+
while (bRet) {
17+
if (!strcmp(ProcName, _bstr_t(PE32.szExeFile))) {
18+
PID = PE32.th32ProcessID;
19+
break;
20+
}
21+
22+
bRet = Process32NextW(hSnap, &PE32);
23+
}
24+
25+
CloseHandle(hSnap);
26+
27+
return PID;
28+
}
29+
30+
HANDLE OpenProc(const char* ProcName) {
31+
int PID = GetPIDByName(ProcName);
32+
if (PID == 0) {
33+
printf("[-] Can't get %s PID\n", ProcName);
34+
system("pause");
35+
return nullptr;
36+
}
37+
38+
printf("[+] %s PID: %d\n", ProcName, PID);
39+
40+
HANDLE hProc = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, FALSE, PID);
41+
if (!hProc) {
42+
printf("[-] OpenProcess error: 0x%X\n", GetLastError());
43+
system("pause");
44+
return nullptr;
45+
}
46+
47+
return hProc;
48+
}

ShellJector.vcxproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<UseDebugLibraries>false</UseDebugLibraries>
2020
<PlatformToolset>v143</PlatformToolset>
2121
<WholeProgramOptimization>true</WholeProgramOptimization>
22-
<CharacterSet>MultiByte</CharacterSet>
22+
<CharacterSet>Unicode</CharacterSet>
2323
</PropertyGroup>
2424
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
2525
<ImportGroup Label="ExtensionSettings">
@@ -35,7 +35,7 @@
3535
</LinkIncremental>
3636
<IncludePath>$(SolutionDir)Deps\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
3737
<LibraryPath>$(SolutionDir)Deps\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64)</LibraryPath>
38-
<OutDir>$(MSBuildStartupDirectory)\Build\</OutDir>
38+
<OutDir>Build\</OutDir>
3939
<IntDir>PB\</IntDir>
4040
</PropertyGroup>
4141
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -62,6 +62,7 @@
6262
<ItemGroup>
6363
<ClCompile Include="injection.cpp" />
6464
<ClCompile Include="main.cpp" />
65+
<ClCompile Include="Process.cpp" />
6566
</ItemGroup>
6667
<ItemGroup>
6768
<ClInclude Include="injection.h" />

ShellJector.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<ClCompile Include="injection.cpp">
1818
<Filter>Исходные файлы</Filter>
1919
</ClCompile>
20+
<ClCompile Include="Process.cpp">
21+
<Filter>Исходные файлы</Filter>
22+
</ClCompile>
2023
</ItemGroup>
2124
<ItemGroup>
2225
<ClInclude Include="injection.h">

injection.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#include "injection.h"
22

3-
struct MemoryStruct {
4-
char* memory;
5-
size_t size;
6-
};
7-
83
static size_t
94
WriteMemoryCallback(void* contents, size_t size, size_t nmemb, void* userp) {
105
size_t realsize = size * nmemb;
@@ -44,7 +39,7 @@ static int ProgressBar(void* ptr, double TotalToDownload, double NowDownloaded,
4439
bool ManualMap(HANDLE hProc, const char* DllURL) {
4540
printf("[DEBUG] Downloading library...\n");
4641

47-
struct MemoryStruct chunk;
42+
struct MemoryStruct chunk {};
4843
chunk.memory = (char*)malloc(1);
4944
chunk.size = 0;
5045

injection.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <Windows.h>
44
#include <iostream>
55
#include <fstream>
6+
#include <filesystem>
67
#include <TlHelp32.h>
8+
#include <comdef.h>
79
#include <curl/curl.h>
810

911
using f_LoadLibraryA = HINSTANCE(WINAPI*)(const char* lpLibFilename);
@@ -22,5 +24,12 @@ struct MANUAL_MAPPING_DATA {
2224
BOOL SEHSupport;
2325
};
2426

27+
struct MemoryStruct {
28+
char* memory;
29+
size_t size;
30+
};
31+
2532
bool ManualMap(HANDLE hProc, const char* DllURL);
33+
int GetPIDByName(const char* ProcName);
34+
HANDLE OpenProc(const char* ProcName);
2635
void __stdcall Shellcode(MANUAL_MAPPING_DATA* pData);

main.cpp

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,23 @@ int main(int argc, char* argv[]) {
1717
}
1818
}
1919

20-
PROCESSENTRY32 PE32{ 0 };
21-
PE32.dwSize = sizeof(PE32);
22-
23-
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
24-
if (hSnap == INVALID_HANDLE_VALUE) {
25-
printf("[-] CreateToolhelp32Snapshot error: 0x%X\n", GetLastError());
26-
system("PAUSE");
20+
HANDLE hProc = OpenProc(ProcName);
21+
if (!hProc)
2722
return 0;
28-
}
29-
30-
DWORD PID = 0;
31-
BOOL bRet = Process32First(hSnap, &PE32);
32-
while (bRet) {
33-
if (!strcmp(ProcName, PE32.szExeFile)) {
34-
PID = PE32.th32ProcessID;
35-
break;
36-
}
37-
bRet = Process32Next(hSnap, &PE32);
38-
}
39-
40-
CloseHandle(hSnap);
4123

42-
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
43-
if (!hProc) {
44-
printf("[-] OpenProcess error: 0x%X\n", GetLastError());
45-
system("PAUSE");
46-
return 0;
47-
}
24+
printf("[+] %s Handle: %p\n", ProcName, hProc);
4825

4926
if (!ManualMap(hProc, DllURL)) {
5027
printf("[-] Injection error\n");
5128
CloseHandle(hProc);
52-
system("PAUSE");
29+
system("pause");
5330
return 0;
5431
}
5532

5633
CloseHandle(hProc);
5734

58-
printf("\n[+] Injected!\n");
59-
system("PAUSE");
35+
printf("[+] Injected!\n");
36+
system("pause");
6037

6138
return 0;
6239
}

0 commit comments

Comments
 (0)