When we test a shellcode, we add it to a small C program and execute it in order to see it does the actual job we expect. But most of the time, it crashes saying 'segmentation fault'. I got the same issue when I execute it on my Linux machine.
Here is what I got from an article.
It happened because the .code section is in read-only memory. So the program should copy to the stack itself before execution.
Then I compiled it adding
-z execstack and it worked perfectly.
So what is actually happening in memory when we execute a shellcode?