简体   繁体   中英

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"

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"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM