我有这个python脚本,我用它来改变TCP数据包的内容,使用nfqueue拦截数据包并scapy来修改它。但是当我尝试接受数据包后更改数据包后,我收到此错误。
callback failure !
Traceback (most recent call last):
File "MITMAttack.py", line 47, in callback
payload.set_verdict_modified(nfqueue.NF_ACCEPT, str(r), len(r))
File "/home/robertocp25/.local/lib/python2.7/site-packages/scapy/packet.py", line 277, in __str__
return self.build()
File "/home/robertocp25/.local/lib/python2.7/site-packages/scapy/packet.py", line 355, in build
p += self.build_padding()
File "/home/robertocp25/.local/lib/python2.7/site-packages/scapy/packet.py", line 351, in build_padding
return self.payload.build_padding()
File "/home/robertocp25/.local/lib/python2.7/site-packages/scapy/packet.py", line 351, in build_padding
return self.payload.build_padding()
AttributeError: 'str' object has no attribute 'build_padding'
这是python脚本代码:
#print payload
data = payload.get_data()
pkt = IP(data)
if pkt.src == "127.0.0.1" and pkt[IP].dport == 8080:
r = pkt.copy()
payload_before = len(r[TCP].payload)
regex = r"(?<=<d:resume xmlns:d=\"http://demo\">)(.*)(?=</d:resume)"
matches = re.search(regex, str(r[TCP].payload), re.MULTILINE)
if matches:
print matches.group(0)
print len(matches.group(0))
result = ''.join(choice(ascii_uppercase) for i in range(len(matches.group(0))))
print len(result)
r[TCP].payload = re.sub(regex, result, str(pkt[TCP].payload), 1, re.MULTILINE)
print r[TCP].payload
payload_after = len(r[TCP].payload)
#print "AFTER: " + str(payload_after)
payload_dif = payload_after - payload_before
r[IP].len = pkt[IP].len + payload_dif
payload.set_verdict_modified(nfqueue.NF_ACCEPT, str(r), len(r))
任何人都有可能提出错误的想法和想法? 谢谢, 罗伯托P.