Search code examples
pythonpython-3.xbyteshellcode

Storing string from stdin with backslashes into variable


How could I store strings in the format "\x00\xc1\xeb" into a variable encoded/converted into bytes?

It seems python has trouble parsing the backslashes correctly.

What I've tried:

bytes_input = bytes(input('enter byte string'), 'utf-8')

I'm trying to store shellcode into the variable 'bytes_input' I think the backslashes are causing issues because they're being interpreter as escape string.

When I print the variable 'bytes_input' the output is:

b'"\\x00\\xc1\\xeb"'

The intended output should be:

b"\x00\xc1\xeb"

Solution

  • Find the solution in this link

    Find my code also for reference.

    string_input = str(input('Enter string:'))
    string_value = string_input if string_input else '\\x00\\xc1\\xeb'
    
    print("Input String: {}".format(string_value))
    
    encoded_value = string_value.encode('utf-8')
    print(encoded_value.decode('unicode-escape').encode("ISO-8859-1"))