我试图将字符串发送到服务器上运行的另一个应用程序(我无权访问)。该字符串包含空字符。 现在我注意到,当我在脚本中运行以下代码时,
print('abc\x00\x91\x11\x01123')
输出为:abc\x00\x91\x11123。
当我在终端中运行相同的代码时的想法:
python -c 'print("abc\x00\x91\x11\x01123")'
我得到的输出:abc�123
这就是我的情况所需的输出。 为什么两个输出不同? 在脚本中运行 print 函数时如何获得第二个输出?
编辑: 我找出了造成差异的原因。 pwntools 导致了这种行为。 但我仍然无法真正弄清楚为什么。 代码如下:
#!/usr/env/python
import pwn
print('abc\x00\x91\x11\x01123')
结果
abc\x00\x91\x11123
当我不导入pwn时,结果如预期: abc�123。
最佳答案
我希望这符合 Stack Overflow 标准中的答案。
如果你玩手榴弹,对待就像手榴弹,而不是玩具。 PWN tools似乎是一些用于利用的脚本小子工具。如果您阅读文档的前几段,您会发现以下内容:
As stated, we would also like to have the ability to get a lot of these side-effects by default. That is the purpose of this module. It does the following:
[...]Calls pwnlib.term.init() to put your terminal in raw mode and implements functionality to make it appear like it isn’t.
您已被警告,但您还没有 RTFM。 😎
关于python - 为什么在终端和运行终端的程序中内联打印转义的十六进制字符之间存在差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55677519/