【发布时间】:2021-10-16 13:15:12
【问题描述】:
我在玩 scapy。我正在尝试按顺序伪造 JUST PSH/ACK 和 ACK 数据包
我编写了两个工具:A 发送 PSH/ACK 数据包,然后嗅探得到的 ACK,将序列写入文件以供以后使用
.....
bitack = random.randrange(1,656787969)
bitseq = random.randrange(1,4294967295)
if os.path.exists('test.txt'):
with open('test.txt','r') as f:
bitseq = int(f.read())
else:
with open('test.txt','w') as f:
f.write(str(bitseq))
.....
text = "Ok"
TSval = int(time.time())
TSecr = TSval
acker = IP(src="127.0.0.1",dst=destinazione"127.0.0.1")/TCP(sport=88,dport=8888,
flags="PA", seq=bitseq, ack=bitack, options=[('Timestamp', (TSval, TSecr))])/text
send(acker)
.....
rx = sniff(filter="host 127.0.0.1 and src port 8888", iface="lo", count=1)
seqcc = rx[0].getlayer(TCP).seq
ackcc = rx[0].getlayer(TCP).ack
with open('test.txt','w') as f:
f.write(str(ackcc))
print("SEQFINALE=", ackcc)
B:它在从 A 嗅探 PSH/ACK 数据包之后发送 ACK 数据包。我知道 ack 数据包包含文本(在本例中与 A 相同),但这就是我想要的
....
rx = sniff(filter="host 127.0.0.1 and dst port 8888", iface="lo", count=1)
seqcc = rx[0].getlayer(TCP).seq
print("seq:", seqcc)
ackcc = rx[0].getlayer(TCP).ack
print("ack:", ackcc)
var = rx[0][Raw].load.decode(encoding='utf-8', errors='ignore')
acker = IP(src="127.0.0.1",dst="127.0.0.1")/TCP(sport=8888,dport=88, flags="A",
seq=ackcc, ack=seqcc + int(len(var)), options=[('Timestamp', (TSval, TSecr))])/var
send(acker)
.....
一切正常,期待wireshark给出一些警告,我不明白为什么: “专家信息(注/序列):此帧是(疑似)重传”
前两个包很完美:
我如何处理序列号/确认号有什么问题吗? 这让我抓狂
【问题讨论】:
-
为什么? PSH 被普遍忽略。
-
@user207421 你是什么意思?啊
-
@user207421 你这么说的依据是什么?如果 PSH 被忽略,那么像 SSH 这样的交互式应用程序会出现非常高的延迟。
标签: python-3.x networking tcp network-programming