Friday, April 3, 2015

Convert any string into HEX \x41\x41 bytes array

A little add-on to previous blogpost, here is a short script in python that will convert your input string to \x00\x00 bytes array:

#!/usr/bin/python

from struct import pack
import sys

W  = '\033[0m'  # white (normal)
G  = '\033[32m' # green
if not len(sys.argv[1:]):
  print '\n\t%sUsage: string2hex "alert()"%s\n\n\t\tWill output \'\\x61\\x6C\\x65\\x72\\x74\\x28\\x29\'\n' % (G,W)
  exit()

b = sys.argv[1]

print '%s%s%s' % (G,''.join(["\\x%02X" % ord( x ) for x in b]),W)

Example:
root@nopernik:~#
root@nopernik:~# string2hex "<script>alert()</script>" 
\x3C\x73\x63\x72\x69\x70\x74\x3E\x61\x6C\x65\x72\x74\x28\x29\x3C\x2F\x73\x63\x72\x69\x70\x74\x3E

No comments:

Post a Comment