【发布时间】:2020-09-30 14:41:21
【问题描述】:
是否可以将字节连接到 str?
>>> b = b'this is bytes'
>>> s = 'this is string'
>>> b + s
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't concat str to bytes
>>>
根据上面的简单代码是不可能的。
我之所以问这个问题是因为我看到了一个将字节连接到 str 的代码? 这是代码片段。
buf = ""
buf += "\xdb\xd1\xd9\x74\x24\xf4\x5a\x2b\xc9\xbd\x0e\x55\xbd"
buffer = "TRUN /.:/" + "A" * 2003 + "\xcd\x73\xa3\x77" + "\x90" * 16 + buf + "C" * (5060 - 2003 - 4 - 16 - len(buf))
您可以在此处查看完整代码。
http://sh3llc0d3r.com/vulnserver-trun-command-buffer-overflow-exploit/
【问题讨论】:
-
请注意,第二个代码只使用字符串...
-
正如错误消息所暗示的那样,这是不可能的。您所展示的不是将字节连接到 str,而是连接两个 str。检查
type("\xdb\xd1\xd9\x74\x24\xf4\x5a\x2b\xc9\xbd\x0e\x55\xbd")。 -
@juanpa.arrivillaga 他看到的代码完全有可能是为 Python 2.7 编写的,其中
bytes只是str的同义词。也就是说,他发布的代码 sn-p 中没有字节。 -
Gosh .. b'' 字符串,其中 str 在 python2 中输入。 Op 的链接,其中他显示的代码来自 2015 年,很可能打算在 python2 上运行,这非常好..