我正在使用scapy进行三向握手,并发送get请求和接收响应.但是我得到一个带有FIN标志的TCP数据包.我期望带有请求页面的HTTP数据包.我要去哪里错了?
import sys
import socket
from scapy.all import *
# 3 way handshake
ip=IP(dst="webs.com")
SYN=TCP(sport=80, flags="S", seq=100, dport=80)
SYNACK=sr1(ip/SYN)
my_ack = SYNACK.seq + 1
ACK=TCP(sport=80, flags="A", seq=101, ack=my_ack, dport=80)
send(ip/ACK)
# request
PUSH = TCP(sport=80, dport=80, flags='PA', seq=102, ack=my_ack)
payload = "GET / HTTP/1.1\r\nHost: webs.com\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nUpgrade-Insecure-Requests: 1\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/58.0.3029.110 Chrome/58.0.3029.110 Safari/537.36\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8\r\nAccept-Language: en-US,en;q=0.8\r\n\r\n"
reply= sr1(ip/PUSH/payload, timeout=10)
Wireshark结果
解决方法:
您的机器正在发送RST数据包. RST数据包正在由内核发送.
http://www.packetlevel.ch/html/scapy/scapy3way.html.
尝试通过iptables丢弃RST数据包.
iptables -A输出-p tcp –tcp-flags RST RST -s 192.168.43.119 -j DROP