Modern operating systems use memory protection. Memory pages have access rights, like files: readable, writable, executable. Your data segment of your program is usually located on an impossible page, and trying to execute it results in segfault.
If you want to execute dynamically written binary code from your program on linux, you first need to map the page using mmap() , which you can write, then put your code there, and then change it to read-only by executing using mprotect() . THEN you can jump there.
You can, for example, read this article for details.
EDIT . When it comes to security breaches, please note that the stack is also not being executed at this time ... so all of these old “hacker tutorials” will no longer work. If you're interested in new methods, read about result-oriented programming.
source share