Last active
August 28, 2018 18:05
-
-
Save rekkusu/a4203888d96b80937001 to your computer and use it in GitHub Desktop.
Run shellcode from Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mkmf' | |
create_makefile('shellcode') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'shellcode' | |
"\x48\x31\xd2\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xeb\x08\x53\x48\x89\xe7\x50\x57\x48\x89\xe6\xb0\x3b\x0f\x05".exec | |
# http://shell-storm.org/shellcode/files/shellcode-603.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ruby/ruby.h" | |
#ifdef unix | |
#include <sys/mman.h> | |
#endif | |
VALUE exec_s_m(VALUE self) ; | |
void Init_shellcode(void) { | |
VALUE cString = rb_define_class("String", rb_cObject); | |
rb_define_method(cString, "exec", exec_s_m, 0); | |
} | |
VALUE exec_s_m(VALUE self) { | |
#ifdef unix | |
char *sc = RSTRING_PTR(self); | |
intptr_t p = sc; | |
p = p ^ (p & 0xfff); | |
mprotect(p, 0x1000, PROT_READ | PROT_WRITE | PROT_EXEC); | |
(*(void (*)()) sc)(); | |
return Qtrue; | |
#else | |
return Qfalse; | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment