ing
This commit is contained in:
parent
547a82574f
commit
bc3790375a
|
@ -55,14 +55,12 @@ func handlePacketARP(ps *pCapScan, packet gopacket.Packet) {
|
|||
ps.arpListenerChanMtx.RLock()
|
||||
defer ps.arpListenerChanMtx.RUnlock()
|
||||
|
||||
if ps.arpListenerChans != nil {
|
||||
arpLayer := packet.Layer(layers.LayerTypeARP)
|
||||
arp := arpLayer.(*layers.ARP)
|
||||
|
||||
for _, ch := range ps.arpListenerChans {
|
||||
ch <- arp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) {
|
||||
|
|
|
@ -62,10 +62,14 @@ func scanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interfa
|
|||
return
|
||||
}
|
||||
|
||||
time.Sleep(30 * time.Second)
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
|
||||
func handlePacketARP(zone *model.Zone, cr cidr.CIDRRanger, hosts map[string]*model.Host, packet *layers.ARP) *model.Host {
|
||||
if packet.Operation != layers.ARPReply {
|
||||
return nil
|
||||
}
|
||||
|
||||
// logging.Logger().Debug(fmt.Sprintf("Discovery: arp packet %v", packet))
|
||||
|
||||
ip := net.IP(packet.SourceProtAddress)
|
||||
|
@ -93,17 +97,18 @@ func sendARP(ps pcap.PCapScanner, zone *model.Zone, hostRanges []net.IP) error {
|
|||
}
|
||||
|
||||
ethPacket := makePacketEthernet(hwAddr)
|
||||
arpPacket := makePacketARP(hwAddr, ip)
|
||||
arpPacket := makePacketARP(hwAddr, ip.To4())
|
||||
opts := gopacket.SerializeOptions{FixLengths: true, ComputeChecksums: true}
|
||||
buf := gopacket.NewSerializeBuffer()
|
||||
|
||||
for _, targetHost := range hostRanges {
|
||||
arpPacket.DstProtAddress = []byte(targetHost)
|
||||
gopacket.SerializeLayers(buf, opts, ethPacket, arpPacket)
|
||||
// log.Printf("ARP:%v", arpPacket)
|
||||
gopacket.SerializeLayers(buf, opts, ðPacket, &arpPacket)
|
||||
if err := ps.WritePacketData(buf.Bytes()); err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(time.Microsecond * 500)
|
||||
time.Sleep(time.Microsecond * 100)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -123,16 +128,16 @@ func getTargetHostRange(dh *model.DiscoveryHost, cr cidr.CIDRRanger) ([]net.IP,
|
|||
return ranges, nil
|
||||
}
|
||||
|
||||
func makePacketEthernet(hw net.HardwareAddr) *layers.Ethernet {
|
||||
return &layers.Ethernet{
|
||||
func makePacketEthernet(hw net.HardwareAddr) layers.Ethernet {
|
||||
return layers.Ethernet{
|
||||
SrcMAC: hw,
|
||||
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
||||
EthernetType: layers.EthernetTypeARP,
|
||||
}
|
||||
}
|
||||
|
||||
func makePacketARP(hw net.HardwareAddr, ip net.IP) *layers.ARP {
|
||||
return &layers.ARP{
|
||||
func makePacketARP(hw net.HardwareAddr, ip net.IP) layers.ARP {
|
||||
return layers.ARP{
|
||||
AddrType: layers.LinkTypeEthernet,
|
||||
Protocol: layers.EthernetTypeIPv4,
|
||||
HwAddressSize: 6,
|
||||
|
|
Loading…
Reference in New Issue
Block a user