38
internal/fingerprint/packet.go
Normal file
38
internal/fingerprint/packet.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package fingerprint
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
||||
// BuildSYNPacket creates a minimal TCP SYN packet for the given source and destination ports.
|
||||
// The packet is not sent; it is used only to demonstrate integration with gopacket.
|
||||
func BuildSYNPacket(srcIP string, dstIP string, srcPort, dstPort uint16) ([]byte, error) {
|
||||
ip := &layers.IPv4{
|
||||
SrcIP: net.ParseIP(srcIP).To4(),
|
||||
DstIP: net.ParseIP(dstIP).To4(),
|
||||
Version: 4,
|
||||
Protocol: layers.IPProtocolTCP,
|
||||
}
|
||||
tcp := &layers.TCP{
|
||||
SrcPort: layers.TCPPort(srcPort),
|
||||
DstPort: layers.TCPPort(dstPort),
|
||||
SYN: true,
|
||||
Seq: 1105024978,
|
||||
Window: 14600,
|
||||
}
|
||||
if err := tcp.SetNetworkLayerForChecksum(ip); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
buf := gopacket.NewSerializeBuffer()
|
||||
opts := gopacket.SerializeOptions{
|
||||
FixLengths: true,
|
||||
ComputeChecksums: true,
|
||||
}
|
||||
if err := gopacket.SerializeLayers(buf, opts, ip, tcp); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
}
|
Reference in New Issue
Block a user