Govur University Logo
--> --> --> -->
...

After figuring out where to send your special code in a buffer overflow, what important step do you take next to make sure your code doesn't get messed up by bad symbols?



After determining the memory location for your special code, the next crucial step is to identify and handle "bad symbols" or "bad characters." These are specific byte values that, if present within your shellcode, can cause the vulnerable program's string handling functions to prematurely terminate or corrupt the data, preventing your complete shellcode from being written into memory or executing correctly. The most common bad symbol is the null byte (`0x00`), which often signifies the end of a string in C-style functions, but others like carriage return (`0x0D`), line feed (`0x0A`), or even space (`0x20`) can be problematic depending on the specific vulnerable function and its processing of input. To ensure your code doesn't get messed up, the shellcode must be "encoded." Encoding is a process of transforming the raw shellcode bytes into a different sequence of bytes that does not contain any of the identified bad symbols. For example, if `0x00` is a bad character, an encoder might transform all `0x00` bytes in the shellcode to a different value, such as `0xAA`, and adjust other bytes accordingly. When the program execution is redirected to the encoded shellcode's location, a small, specially crafted piece of code, known as a "decoder stub," is executed first. The decoder stub's sole purpose is to reverse the encoding process, transforming the encoded shellcode back into its original, executable form in memory, free of bad characters. Once the shellcode is decoded by this stub, it then executes as originally intended, ensuring its integrity and functionality.