简体   繁体   English

在python3中输出十六进制值

[英]Outputting hex values in python3

I am writing shellcode exploits with python3.我正在用 python3 编写 shellcode 漏洞利用程序。 However, when I try and output some hex bytes.但是,当我尝试输出一些十六进制字节时。 eg using the line - python3 -c 'print("\\x8c")' | xxd例如使用该行 - python3 -c 'print("\\x8c")' | xxd python3 -c 'print("\\x8c")' | xxd

The value in xxd is c28c , rather than the expected 8c xxd的值是c28c ,而不是预期的8c

This issue does not occur in python2.这个问题在python2中不会发生。

Your issue arises because Python 3 handles strings as Unicode, and print expects Unicode to encode some output for your terminal.您的问题出现是因为 Python 3 将字符串作为 Unicode 处理,而print期望 Unicode 为您的终端编码一些输出。 Try the following to bypass this:尝试以下方法绕过这个:

python3 -c "import sys; sys.stdout.buffer.write(b'\x8c')" | xxd

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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