Skip to content

Instantly share code, notes, and snippets.

@Mr-Un1k0d3r
Created August 11, 2021 18:07
Show Gist options
  • Save Mr-Un1k0d3r/f0ea9d3c298950f2c721646012f0213d to your computer and use it in GitHub Desktop.
Save Mr-Un1k0d3r/f0ea9d3c298950f2c721646012f0213d to your computer and use it in GitHub Desktop.
spawn an invisible process
// To compile: gcc64.exe run.c -o run.exe
// To run: run.exe cmd.exe "/c whoami"
#include <Windows.h>
#include <stdio.h>
int main(int argc, char **argv) {
CHAR cDesktop[] = "hiddendesktop";
HDESK hDesk = CreateDesktop(cDesktop, NULL, NULL, DF_ALLOWOTHERACCOUNTHOOK, GENERIC_ALL, NULL);
printf("Desktop HANDLE 0x%08x\n", hDesk);
CHAR *process = argv[0];
CHAR *args = argv[1];
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
si.lpDesktop = cDesktop;
// CREATE_NEW_CONSOLE is used on purpose to show that the process is not visible
if(CreateProcess(process, args, NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi)) {
printf("Process spawned.\n");
} else {
printf("Failed to spawn. Error %d\n", GetLastError());
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment