Question

I know that "start" is incorrect but I guess you understand what I want to do... I know there is a function called "bytes" but I don't know how to use it correctly. For example I have this bytearray

'\x54\x68\x69\x73\x20\x70\x72\x6F\x67\x72\x61\x6D\x20\x6D\x75\x73\x74\x20\x62\x65'

how can I read this and start it with the python script? What functions should I use and what should I import? Thank you for your answers (I'm a newbie btw)

Was it helpful?

Solution

Is this what you thought of?

>>> bytes('\x54\x68\x69\x73\x20\x70\x72\x6F\x67\x72\x61\x6D\x20\x6D\x75\x73\x74\x20\x62\x65')                                              
'This program must be'
>>> 

if you would wanted to use that in a script:

#!/usr/local/bin/python


# You can encode the python instructions on this webpage:
# http://www.string-functions.com/string-hex.aspx
#
#
# The following hex string encodes this:
# for i in xrage(0,10):
#     print i
thestring = "\x66\x6f\x72\x20\x69\x20\x69\x6e\x20\x78\x72\x61\x6e\x67\x65\x28\x30\x2c\x31\x30\x29\x3a\x0d\x0a\x20\x20\x20\x20\x70\x72\x69\x6e\x74\x20\x69"

# Demonstration of possible code injection
# in the function:
thehack = "import os;os.system('echo foobar')"


def hex2string(myhexstring):
    """be carefull with this function possible codeinjection"""
    myhexcmd = bytes("%s" % myhexstring)
    exec myhexcmd


hex2string(thestring)

kind regards,

Dirk

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top