Skip to content

Instantly share code, notes, and snippets.

@AXDOOMER
Created August 31, 2020 02:40
Show Gist options
  • Save AXDOOMER/41ace7c726a67afcdfd12af723cd13d7 to your computer and use it in GitHub Desktop.
Save AXDOOMER/41ace7c726a67afcdfd12af723cd13d7 to your computer and use it in GitHub Desktop.
// Shellcode executor
// Expects hex as a command line parameter
//
// Compile with: gcc -fno-stack-protector -z execstack main.c
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
if (argc == 2)
{
char code[32000] = { 0 }; // may overflow
int codeindex = 0;
char temp[3] = { 0 };
int length = strlen(argv[1]);
for (int i = 0; i < length; i += 2)
{
strncpy(temp, argv[1] + i, 2);
code[codeindex] = strtol(temp, NULL, 16);
codeindex++;
}
int (*foo)() = (int(*)())code;
foo();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment