Skip to content

Instantly share code, notes, and snippets.

@rubenhortas
Last active July 20, 2024 20:09
Show Gist options
  • Save rubenhortas/1bfe50673297c975d979060e0af97d49 to your computer and use it in GitHub Desktop.
Save rubenhortas/1bfe50673297c975d979060e0af97d49 to your computer and use it in GitHub Desktop.
/*
* Process arguments spoofing in GNU/Linux.
*
* Hide program arguments by overwriting them with null.
*
* You can read my full post here: https://rubenhortas.github.io/posts/process-argument-spoofing-gnu-linux/
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char *argv0 = argv[0];
char *argvi;
int i, len;
printf("PID: %d\n", getpid());
printf("argv[0] '%s', address '%p'\n", argv[0], argv);
for (i = 1; i < argc; i++) {
argvi = argv[i];
printf("argv[%d] '%s', address '%p'\n", i, argv[i], argvi);
len = strlen(argv[i]);
memset(argv[i], 0, len); // Overwrite everything with null
}
strcpy(argv0, "[kworker fake/1:1-events]"); // Overwrite the program name
while(1) { // Do some stuff
}
free(argv0);
free(argvi);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment