In "Learning Linux Binary Analysis" by Ryan "elfmaster" O'Neill.
Another neat trick that I just recently discovered during the construction of the Skeksi virus for 64-bit Linux is to merge the text and data segment into a single segment, that is, read+write+execute (RWX), by using the
-N
option with gcc.
I don't see an -N
option in man gcc
nor in gcc --help | grep '\-N'
? Was this option renamed?
-N
appears to be an option to (gnu)ld, the linker("loader")
From man ld
:
-N
--omagic
Set the text and data sections to be readable and writable. Also, do not page-align the data segment, and disable linking against shared libraries. If the output format supports Unix style magic numbers, mark the output as "OMAGIC". Note: Although a writable text section is allowed for PE-COFF targets, it does not conform to the format specification published by Microsoft.
Thegcc
compiler-driver will pass options prepended with -Wl,
to the loader, so your gcc-commandline will be something like:
gcc -Wl,-N -oher_options...`