客户端在接收到 [SYN, ACK] 后发送 [RST]。

huangapple go评论87阅读模式
英文:

Client sends [RST] after receive [SYN, ACK]

问题

我正在尝试与从互联网下载的服务器进行握手。但是当客户端接收到[SYN,ACK]时,它会发送[RST]。不知道发生了什么。已经检查了确认和序列号,但一切似乎都正常。

在Wireshark中,我得到了这个:

客户端在接收到 [SYN, ACK] 后发送 [RST]。

这是客户端握手源代码:

from scapy.all import *

src_ip   = "192.168.43.34"
dst_ip   = "192.168.43.115"
src_port = random.randint(1024, 65535)
dst_port = 502

seq_nr   = random.randint(444, 8765432)
ack_nr   = 0

# 创建SYN数据包
ip       = IP (src   = src_ip, dst = dst_ip)
syn      = TCP(sport = src_port, dport = dst_port, flags='S', seq = seq_nr, ack = ack_nr)
pkt_syn  = ip / syn 

pkt_syn.show()

# 发送SYN数据包并接收SYN/ACK数据包
print('发送SYN')
pkt_syn_ack = sr1(pkt_syn)
print('接收到ACK')
pkt_syn_ack.show()

# 创建ACK数据包
ack_nr   = pkt_syn_ack.seq + 1
seq_nr   = seq_nr + 1

ack = TCP(sport = src_port, dport = dst_port, flags = 'A', seq = seq_nr, ack = ack_nr)
send(ip / ack)

...

如您所要求,这是源代码的翻译部分,不包含其他内容。

英文:

I am trying to do a handshake with a server I downloaded from the internet. But when the client receives [SYN, ACK] it sends back a [RST]. Have no idea what is happening. Already checked the acknowledge and sequence number but everything seems ok.

In wireshark I got this:

客户端在接收到 [SYN, ACK] 后发送 [RST]。

Here is the handshake client source code:

from scapy.all import *

src_ip   = "192.168.43.34"
dst_ip   = "192.168.43.115"
src_port = random.randint(1024, 65535)
dst_port = 502

seq_nr   = random.randint(444, 8765432)
ack_nr   = 0



# Create SYN packet
ip       = IP (src   = src_ip, dst = dst_ip)
syn      = TCP(sport = src_port, dport = dst_port, flags='S', seq = seq_nr, ack = ack_nr)
pkt_syn  = ip / syn 

pkt_syn.show()

# send SYN packet and receive SYN/ACK packet
print('Sending SYN')
pkt_syn_ack = sr1(pkt_syn)
print('ACK received')
pkt_syn_ack.show()


# Create the ACK packet
ack_nr   = pkt_syn_ack.seq + 1
seq_nr   = seq_nr + 1

ack = TCP(sport = src_port, dport = dst_port, flags = 'A', seq = seq_nr, ack = ack_nr)
send(ip / ack)

...

答案1

得分: 3

问题在于您的操作系统接收到了SYN-ACK数据包,但不知道为什么发送该数据包(因为操作系统本身没有启动握手),所以重置了连接。

您可以在这里找到一些解决方案(适用于Linux)-
https://stackoverflow.com/questions/9058052/unwanted-rst-tcp-packet-with-scapy

另一个选择是使用与操作系统不同的IP地址,或者在Windows中关闭所使用接口的IP协议栈(仅当该接口仅用于此用途时)。

英文:

The problem is that your OS is receiving the SYN-ACK packet, has no idea why it was sent (as the OS itself didn't start a handshake) and reset the connection.

You can find some solutions here (for Linux)-
https://stackoverflow.com/questions/9058052/unwanted-rst-tcp-packet-with-scapy

Another option is to use a different IP than the OS's, or in Windows turn off the IP stack of the used interface (only if this is the only thing that you use this interface for!)

huangapple
  • 本文由 发表于 2020年1月6日 20:38:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定