Skip to content

Instantly share code, notes, and snippets.

@mlen
Forked from anonymous/makefile
Last active December 17, 2015 12:09
Show Gist options
  • Save mlen/5607532 to your computer and use it in GitHub Desktop.
Save mlen/5607532 to your computer and use it in GitHub Desktop.
Shellcode testbed. Works on Debian 7
test: test.c test.h
gcc -o test test.c
test.h: test.bin
xxd -i test.bin > test.h
test.bin: test.s
nasm -f bin -o test.bin test.s
clean:
rm test.bin test.h test
.PHONY: clean
#include <sys/mman.h>
#include <unistd.h>
#include "test.h"
int main(void) {
int (*func)();
int *pageptr;
int pagesize;
pagesize = getpagesize();
pageptr = test_bin - ((int)test_bin % pagesize);
mprotect(pageptr, (test_bin_len/pagesize + 1)*pagesize, PROT_READ|PROT_EXEC);
func = (int (*)())test_bin;
(*func)();
return 0;
}
SECTION .text
BITS 64
mov rax, 1
mov rbx, 1
int 0x80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment