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() ps.arpListenerChanMtx.RLock()
defer ps.arpListenerChanMtx.RUnlock() defer ps.arpListenerChanMtx.RUnlock()
if ps.arpListenerChans != nil {
arpLayer := packet.Layer(layers.LayerTypeARP) arpLayer := packet.Layer(layers.LayerTypeARP)
arp := arpLayer.(*layers.ARP) arp := arpLayer.(*layers.ARP)
@ -63,7 +62,6 @@ func handlePacketARP(ps *pCapScan, packet gopacket.Packet) {
ch <- arp ch <- arp
} }
} }
}
func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) { func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) {
ipLayer := packet.Layer(layers.LayerTypeIPv4) ipLayer := packet.Layer(layers.LayerTypeIPv4)

View File

@ -62,10 +62,14 @@ func scanHost(zone *model.Zone, dh *model.DiscoveryHost, resultChan chan interfa
return 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 { 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)) // logging.Logger().Debug(fmt.Sprintf("Discovery: arp packet %v", packet))
ip := net.IP(packet.SourceProtAddress) ip := net.IP(packet.SourceProtAddress)
@ -93,17 +97,18 @@ func sendARP(ps pcap.PCapScanner, zone *model.Zone, hostRanges []net.IP) error {
} }
ethPacket := makePacketEthernet(hwAddr) ethPacket := makePacketEthernet(hwAddr)
arpPacket := makePacketARP(hwAddr, ip) arpPacket := makePacketARP(hwAddr, ip.To4())
opts := gopacket.SerializeOptions{FixLengths: true, ComputeChecksums: true} opts := gopacket.SerializeOptions{FixLengths: true, ComputeChecksums: true}
buf := gopacket.NewSerializeBuffer() buf := gopacket.NewSerializeBuffer()
for _, targetHost := range hostRanges { for _, targetHost := range hostRanges {
arpPacket.DstProtAddress = []byte(targetHost) 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 { if err := ps.WritePacketData(buf.Bytes()); err != nil {
return err return err
} }
time.Sleep(time.Microsecond * 500) time.Sleep(time.Microsecond * 100)
} }
return nil return nil
} }
@ -123,16 +128,16 @@ func getTargetHostRange(dh *model.DiscoveryHost, cr cidr.CIDRRanger) ([]net.IP,
return ranges, nil return ranges, nil
} }
func makePacketEthernet(hw net.HardwareAddr) *layers.Ethernet { func makePacketEthernet(hw net.HardwareAddr) layers.Ethernet {
return &layers.Ethernet{ return layers.Ethernet{
SrcMAC: hw, SrcMAC: hw,
DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, DstMAC: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
EthernetType: layers.EthernetTypeARP, EthernetType: layers.EthernetTypeARP,
} }
} }
func makePacketARP(hw net.HardwareAddr, ip net.IP) *layers.ARP { func makePacketARP(hw net.HardwareAddr, ip net.IP) layers.ARP {
return &layers.ARP{ return layers.ARP{
AddrType: layers.LinkTypeEthernet, AddrType: layers.LinkTypeEthernet,
Protocol: layers.EthernetTypeIPv4, Protocol: layers.EthernetTypeIPv4,
HwAddressSize: 6, HwAddressSize: 6,