This commit is contained in:
crusader 2017-11-17 20:48:34 +09:00
parent 547a82574f
commit bc3790375a
2 changed files with 17 additions and 14 deletions

View File

@ -55,7 +55,6 @@ 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)
@ -63,7 +62,6 @@ func handlePacketARP(ps *pCapScan, packet gopacket.Packet) {
ch <- arp
}
}
}
func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) {
ipLayer := packet.Layer(layers.LayerTypeIPv4)

View File

@ -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, &ethPacket, &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,