SECURITY MECHANISMS REMOVED

32-BIT COMPILATION ON 64-BIT SYSTEMS

root@dev:~$ sudo apt install gcc-multilib
root@dev:~$ gcc -m32 bow.c -o bow32 -fno-stack-protector -z execstack
root@dev:~$ file bow32 | tr "," "\n"
 bow: ELF 32-bit LSB shared object
  Intel 80386
  version 1 (SYSV)
  dynamically linked
  interpreter /lib/ld-linux.so.2
  for GNU/Linux 3.2.0
  BuildID[sha1]=93dda6b77131deecaadf9d207fdd2e70f47e1071
  not stripped

 * gcc-multilib is a package that allows compiling 32-bit programs on a 64-bit system.
    - it includes the 32-bit versions of libraries, headers, and runtime 
      support (libc6-dev-i386, etc.) that GCC needs to produce 32-bit binaries.
    - on a 64-bit Linux system, the default GCC setup only has 64-bit libraries 
      and headers. without gcc-multilib, compiling with -m32 will fail because the 
      32-bit versions of libc, ld-linux.so, and other standard libraries 
      aren’t available.
       - installing gcc-multilib provides these, allowing GCC to link and produce 
         a 32-bit ELF binary.
         
 * -fno-stack-protector disables GCC’s stack protection mechanisms.
    - GCC normally inserts stack canaries to detect stack buffer overflows.
       - A stack canary is a small random value placed before the return address. 
         If a buffer overflow occurs, the canary is altered, and the program detects 
         the corruption and aborts.
       - -fno-stack-protector tells GCC not to insert stack canaries, which makes 
         the program more vulnerable to stack overflows.
          - this is needed on use cases such as exploit development or when you 
            want predictable stack behavior for testing/debugging.
            
 * the -z marks the program’s stack as executable.
    - Modern Linux systems mark the stack as non-executable by default (DEP/NX).
       - This prevents running code that’s injected onto the stack, like shellcode.
          - the -z execstack overrides this, allowing code on the stack to execute.
          - this is useful for security research or exploit testing, 
            especially for stack-based shellcode experiments.

64-BIT COMPILATION

student@nix-bow:~$ gcc bow.c -o bow64 -fno-stack-protector -z execstack -m64
student@nix-bow:~$ file bow64 | tr "," "\n"
 bow64: ELF 64-bit LSB shared object
  x86-64
  version 1 (SYSV)
  dynamically linked
  interpreter /lib64/ld-linux-x86-64.so.2
  for GNU/Linux 3.2.0
  BuildID[sha1]=9503477016e8604e808215b4babb250ed25a7b99
  not stripped

Last updated