Skip to content

Commit

Permalink
fix: syn模式在少量数据下wait逻辑异常
Browse files Browse the repository at this point in the history
  • Loading branch information
XinRoom committed Mar 24, 2023
1 parent 1dad2c3 commit b413b3e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions core/port/syn/syn.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,19 @@ func (ss *SynScanner) Scan(dstIp net.IP, dst uint16) (err error) {
}

func (ss *SynScanner) Wait() {
ss.portProbeWg.Wait()
// Delay 2s for a reply from the last packet
for i := 0; i < 20; i++ {
if ss.watchIpStatusT.IsEmpty() {
return
break
}
time.Sleep(time.Millisecond * 100)
}
// wait inside chan is empty
for len(ss.openPortChan) != 0 {
time.Sleep(time.Millisecond * 20)
}
// wait portProbe task
ss.portProbeWg.Wait()
}

// Close cleans up the handle and chan.
Expand Down Expand Up @@ -460,6 +465,10 @@ func (ss *SynScanner) recv() {
}

if tcpLayer.SYN && tcpLayer.ACK {
ss.openPortChan <- port.OpenIpPort{
Ip: ipLayer.SrcIP,
Port: _port,
}
// reply to target
eth.DstMAC = ethLayer.SrcMAC
ip4.DstIP = ipLayer.SrcIP
Expand All @@ -470,10 +479,6 @@ func (ss *SynScanner) recv() {
tcp.Seq = tcpLayer.Ack
tcp.SetNetworkLayerForChecksum(&ip4)
ss.send(&eth, &ip4, &tcp)
ss.openPortChan <- port.OpenIpPort{
Ip: ipLayer.SrcIP,
Port: _port,
}
}
tcpLayer.DstPort = 0 // clean tcp parse status
}
Expand Down

0 comments on commit b413b3e

Please sign in to comment.