func randSeq() int {
seed := rand.NewSource(time.Now().UnixNano())
return rand.New(seed).Intn(4294967296)
}
func main() {
var ip string
var port int
flag.StringVar(&ip, "ip", "", "ip")
flag.IntVar(&port, "port", 0, "port")
flag.Parse()
if ip == "" || port == 0 {
flag.Usage()
return
}
synScan(ip, port)
}
func synScan(ip string, port int) {
var err error
var route routing.Router
var ifs net.Interface
var gateway net.IP
var src net.IP
var gatewayAddr netip.Addr
var c arp.Client
scanner := synScanner{
PortMap: make(map[string]string),
}
I used this code to send a tcp syn handshake packet to 192.168.7.131:8080, but when I used tcpdump to capture the packet, I captured two identical tcp syn handshake packets.
I am using centos7 operating system,and there is my code
`package main
import ( "flag" "fmt" "github.com/google/gopacket" "github.com/google/gopacket/layers" "github.com/google/gopacket/pcap" "github.com/google/gopacket/routing" "github.com/mdlayher/arp" "math/rand" "net" "net/netip" "time" "vulScan/common" )
func randSeq() int { seed := rand.NewSource(time.Now().UnixNano()) return rand.New(seed).Intn(4294967296) }
func main() { var ip string var port int flag.StringVar(&ip, "ip", "", "ip") flag.IntVar(&port, "port", 0, "port") flag.Parse() if ip == "" || port == 0 { flag.Usage() return } synScan(ip, port) }
type synScanner struct { Handle *pcap.Handle PortMap map[string]string LocalMac net.HardwareAddr LocalIp net.IP GatewayMac net.HardwareAddr }
func synScan(ip string, port int) { var err error var route routing.Router var ifs net.Interface var gateway net.IP var src net.IP var gatewayAddr netip.Addr var c arp.Client scanner := synScanner{ PortMap: make(map[string]string), }
}
func (s *synScanner) sendSyn(dstIp string, dstPort int) { fmt.Println("发送了syn") eth := layers.Ethernet{ SrcMAC: s.LocalMac, DstMAC: s.GatewayMac, EthernetType: layers.EthernetTypeIPv4, } ip4 := layers.IPv4{ SrcIP: s.LocalIp, DstIP: net.ParseIP(dstIp), Version: 4, TTL: 64, Protocol: layers.IPProtocolTCP, } tcp := layers.TCP{ SrcPort: layers.TCPPort(common.LocalPort), DstPort: layers.TCPPort(dstPort), // will trough ports slice SYN: true, Window: 29200, Seq: uint32(randSeq()), Options: []layers.TCPOption{ layers.TCPOption{layers.TCPOptionKindMSS, 4, []byte("\x05\xb4")}, layers.TCPOption{layers.TCPOptionKindSACKPermitted, 2, nil}, layers.TCPOption{layers.TCPOptionKindNop, 1, nil}, layers.TCPOption{layers.TCPOptionKindWindowScale, 3, []byte("\x07")}, }, } tcp.SetNetworkLayerForChecksum(&ip4) buffer := gopacket.NewSerializeBuffer() opts := gopacket.SerializeOptions{ FixLengths: true, ComputeChecksums: true, } gopacket.SerializeLayers(buffer, opts, ð, &ip4, &tcp) s.Handle.WritePacketData(buffer.Bytes()) }`