Skip to content

Instantly share code, notes, and snippets.

@stowell
Last active February 20, 2016 02:30
Show Gist options
  • Save stowell/6ec85172115263632600 to your computer and use it in GitHub Desktop.
Save stowell/6ec85172115263632600 to your computer and use it in GitHub Desktop.
raw.c
#include <sys/mman.h>
typedef unsigned int uintf();
int main(int argc, char* argv[]) {
unsigned char* f = mmap(
0, 4096, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (MAP_FAILED == f) {
return 1;
}
f[0] = 0x55;
f[1] = 0x48;
f[2] = 0x89;
f[3] = 0xe5;
f[4] = 0xb8;
f[5] = 0xf3;
f[6] = 0x00;
f[7] = 0x00;
f[8] = 0x00;
f[9] = 0x5d;
f[10] = 0xc3;
int protect_result = mprotect(f, 4096, PROT_READ | PROT_EXEC);
if (-1 == protect_result) {
return 2;
}
uintf* justreturn = (uintf*) f;
unsigned int result = justreturn();
if (243 == result) {
return 0;
} else {
return 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment