2
votes

I have a string of format : "&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29"

I use a dictionary(There is alot of other stuff in dictionary ) whose key is &#x and its corresponding value as \x Something like dict = {'&#x':'\\x'}

I then replaces the key with values : The string becomes like : \x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x3A\x61\x6C\x65\x72\x74\x28\x27\x58\x53\x53\x27\x29

Ideally this should be converted to its original ascii form which is javascript:alert('XSS') when I print.

I have to explicitly use unhexlify(hexstring) to get this converted to give converted form.

However if I manually write : a new variable with var1 = "\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x3A\x61\x6C\x65\x72\x74\x28\x27\x58\x53\x53\x27\x29"

And then print this var1 it gives me javascript:alert('XSS') as result.

Why is that extra step of conversion required? Is there any other way to get rid of that extra call of unhexlify.

1

1 Answers

0
votes

Why is that extra step of conversion required?

Because you haven't looked at the representation of the string; the backslashes will appear escaped.

Is there any other way to get rid of that extra call of unhexlify.

Sure, just decode with the right codec.

>>> r'\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x3A\x61\x6C\x65\x72\x74\x28\x27\x58\x53\x53\x27\x29'.decode('string-escape')
"javascript:alert('XSS')"