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 -fno-stack-protector and -z execstack and it worked perfectly.

So what is actually happening in memory when we execute a shellcode?

  • -fno-stack-protector disables canary (stackoverflow.com/questions/2340259/…). -z execstack makes stack executable. (stackoverflow.com/questions/29178445/…) Aug 17, 2019 at 17:13
  • stack canaries or stack cookies is a binary protection method where a special token is placed right before return address. If you overwrite it with your shellcode, then cookie will be damaged and program will crash. Aug 17, 2019 at 17:21
  • Can I get an explanation of the memory layout when we test a shellcode using C?? Cuz I really confused how stack involve when we execute a simple C program which includes a shellcode Aug 18, 2019 at 3:27


You must log in to answer this question.

Browse other questions tagged .