Python Exploits – Generate all hex chars to find badchars

While preparing for my OSCP exam, I’m reviewing the buffer overflow lessons and needed an easy way to generate all hex characters to test for bad characters in my exploit. Using “print(“\x” + format(x, ‘x’))” results in a character on each line, and adding a comma after the print statement keeps it all on the same line, but the output has spaces between characters. You can generate the output you need, all on the same line and without spaces using “sys.stdout.write”.

Here’s a simple python snippet to do that:

(Visited 574 times, 1 visits today)

One thought on “Python Exploits – Generate all hex chars to find badchars”

  1. Thanks, that was very useful.

    It is also possible to use python3 in combination with specifying what the end for each print
    will be such as :
    for x in range(1,256):
    print(“\\x” + ‘{:02x}’.format(x),end=””)

    Then no imports are needed.

Leave a Reply

Your email address will not be published. Required fields are marked *