| 1 | package dhcp6_spoofscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/ |
| 2 | |
| 3 | import ( |
| 4 | "bytesscip-go gomod github.com/golang/go/src go1.16 bytes/" |
| 5 | "crypto/randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/" |
| 6 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 7 | "netscip-go gomod github.com/golang/go/src go1.16 net/" |
| 8 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 9 | "syncscip-go gomod github.com/golang/go/src go1.16 sync/" |
| 10 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 11 | |
| 12 | "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/" |
| 13 | "github.com/bettercap/bettercap/packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/" |
| 14 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 15 | |
| 16 | "github.com/google/gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/" |
| 17 | "github.com/google/gopacket/layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/" |
| 18 | "github.com/google/gopacket/pcapscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/" |
| 19 | |
| 20 | // TODO: refactor to use gopacket when gopacket folks |
| 21 | // will fix this > https://github.com/google/gopacket/issues/334 |
| 22 | "github.com/mdlayher/dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/" |
| 23 | "github.com/mdlayher/dhcp6/dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/" |
| 24 | |
| 25 | "github.com/evilsocket/islazy/tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/" |
| 26 | ) |
| 27 | |
| 28 | type DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer# struct { |
| 29 | sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#SessionModule. |
| 30 | Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle. *pcapscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/.Handlescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle# |
| 31 | DUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUID. *dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.DUIDLLTscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/DUIDLLT# |
| 32 | DUIDRawscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUIDRaw. []byte |
| 33 | Domainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Domains. []string |
| 34 | RawDomainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#RawDomains. []byte |
| 35 | waitGroupscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#waitGroup. *syncscip-go gomod github.com/golang/go/src go1.16 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup# |
| 36 | pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#pktSourceChan. chan gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet# |
| 37 | } |
| 38 | |
| 39 | func NewDHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/NewDHCP6Spoofer().(s *sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer# { |
| 40 | mod := &DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#{ |
| 41 | SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#SessionModule.: sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewSessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewSessionModule().("dhcp6.spoof", s), |
| 42 | Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle.: nil, |
| 43 | waitGroupscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#waitGroup.: &syncscip-go gomod github.com/golang/go/src go1.16 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#{}, |
| 44 | } |
| 45 | |
| 46 | mod.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#SessionModule..Requiresscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Requires().("net.recon") |
| 47 | |
| 48 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("dhcp6.spoof.domains", |
| 49 | "microsoft.com, google.com, facebook.com, apple.com, twitter.com", |
| 50 | ``, |
| 51 | "Comma separated values of domain names to spoof.")) |
| 52 | |
| 53 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("dhcp6.spoof on", "", |
| 54 | "Start the DHCPv6 spoofer in the background.", |
| 55 | func(args []string) error { |
| 56 | return mod.Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Start().() |
| 57 | })) |
| 58 | |
| 59 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("dhcp6.spoof off", "", |
| 60 | "Stop the DHCPv6 spoofer in the background.", |
| 61 | func(args []string) error { |
| 62 | return mod.Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Stop().() |
| 63 | })) |
| 64 | |
| 65 | return mod |
| 66 | } |
| 67 | |
| 68 | func (mod DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Name().() string { |
| 69 | return "dhcp6.spoof" |
| 70 | } |
| 71 | |
| 72 | func (mod DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) Descriptionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Description().() string { |
| 73 | return "Replies to DHCPv6 messages, providing victims with a link-local IPv6 address and setting the attackers host as default DNS server (https://github.com/fox-it/mitm6/)." |
| 74 | } |
| 75 | |
| 76 | func (mod DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) Authorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Author().() string { |
| 77 | return "Simone Margaritelli <[email protected]>" |
| 78 | } |
| 79 | |
| 80 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Configure().() error { |
| 81 | var err error |
| 82 | |
| 83 | if mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 84 | return sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.ErrAlreadyStartedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ErrAlreadyStarted().(mod.Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Name().()) |
| 85 | } |
| 86 | |
| 87 | if mod.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle., err = networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.Capturescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Capture().(mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#Name().()); err != nil { |
| 88 | return err |
| 89 | } |
| 90 | |
| 91 | err = mod.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle..SetBPFFilterscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#SetBPFFilter().("ip6 and udp") |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | |
| 96 | if err, mod.Domainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Domains. = mod.ListParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#ListParam().("dhcp6.spoof.domains"); err != nil { |
| 97 | return err |
| 98 | } |
| 99 | |
| 100 | mod.RawDomainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#RawDomains. = packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCP6EncodeListscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCP6EncodeList().(mod.Domainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Domains.) |
| 101 | |
| 102 | if mod.DUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUID., err = dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.NewDUIDLLTscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/NewDUIDLLT().(1, timescip-go gomod github.com/golang/go/src go1.16 time/.Datescip-go gomod github.com/golang/go/src go1.16 time/Date().(2000, timescip-go gomod github.com/golang/go/src go1.16 time/.Januaryscip-go gomod github.com/golang/go/src go1.16 time/January., 1, 0, 0, 0, 0, timescip-go gomod github.com/golang/go/src go1.16 time/.UTCscip-go gomod github.com/golang/go/src go1.16 time/UTC.), mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..HWscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HW.); err != nil { |
| 103 | return err |
| 104 | } else if mod.DUIDRawscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUIDRaw., err = mod.DUIDscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUID..MarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/DUIDLLT#MarshalBinary().(); err != nil { |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | if !mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Firewallscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Firewall..IsForwardingEnabledscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/firewall`/FirewallManager#IsForwardingEnabled.() { |
| 109 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("Enabling forwarding.") |
| 110 | mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Firewallscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Firewall..EnableForwardingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/firewall`/FirewallManager#EnableForwarding.(true) |
| 111 | } |
| 112 | |
| 113 | return nil |
| 114 | } |
| 115 | |
| 116 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) dhcp6Forscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcp6For().(what dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.MessageTypescip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/MessageType#, to dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Packetscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#) (err error, p dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Packetscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#) { |
| 117 | err, p = packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCP6Forscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCP6For().(what, to, mod.DUIDRawscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUIDRaw.) |
| 118 | if err != nil { |
| 119 | return |
| 120 | } |
| 121 | |
| 122 | p.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options..AddRawscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Options#AddRaw().(packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCP6OptDNSServersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCP6OptDNSServers., mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..IPv6scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IPv6.) |
| 123 | p.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options..AddRawscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Options#AddRaw().(packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCP6OptDNSDomainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCP6OptDNSDomains., mod.RawDomainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#RawDomains.) |
| 124 | |
| 125 | return nil, p |
| 126 | } |
| 127 | |
| 128 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) dhcpAdvertisescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcpAdvertise().(pkt gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#, solicit dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Packetscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#, target netscip-go gomod github.com/golang/go/src go1.16 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#) { |
| 129 | pip6 := pkt.Layerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layer().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.LayerTypeIPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/LayerTypeIPv6.).(*layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#) |
| 130 | |
| 131 | fqdn := target.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().() |
| 132 | if raw, found := solicit.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options.[packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCP6OptClientFQDNscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCP6OptClientFQDN.]; found && len(raw) >= 1 { |
| 133 | fqdn = string(raw[0]) |
| 134 | } |
| 135 | |
| 136 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("Got DHCPv6 Solicit request from %s (%s), sending spoofed advertisement for %d domains.", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Boldscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Bold().(fqdn), target, len(mod.Domainsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Domains.)) |
| 137 | |
| 138 | err, adv := mod.dhcp6Forscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcp6For().(dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.MessageTypeAdvertisescip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/MessageTypeAdvertise., solicit) |
| 139 | if err != nil { |
| 140 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("%s", err) |
| 141 | return |
| 142 | } |
| 143 | |
| 144 | var solIANA dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.IANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA# |
| 145 | |
| 146 | if raw, found := solicit.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options.[dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIANA.]; !found || len(raw) < 1 { |
| 147 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Unexpected DHCPv6 packet, could not find IANA.") |
| 148 | return |
| 149 | } else if err := solIANA.UnmarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#UnmarshalBinary().(raw[0]); err != nil { |
| 150 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Unexpected DHCPv6 packet, could not deserialize IANA.") |
| 151 | return |
| 152 | } |
| 153 | |
| 154 | var ip netscip-go gomod github.com/golang/go/src go1.16 net/.IPscip-go gomod github.com/golang/go/src go1.16 net/IP# |
| 155 | if h, found := mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Lanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Lan..Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/LAN#Get().(target.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()); found { |
| 156 | ip = h.IPscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IP. |
| 157 | } else { |
| 158 | mod.Warningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Warning().("Address %s not known, using random identity association address.", target.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()) |
| 159 | randscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/.Readscip-go gomod github.com/golang/go/src go1.16 `crypto/rand`/Read().(ip) |
| 160 | } |
| 161 | |
| 162 | addr := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%s%s", packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.IPv6Prefixscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/IPv6Prefix., stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Replacescip-go gomod github.com/golang/go/src go1.16 strings/Replace().(ip.Stringscip-go gomod github.com/golang/go/src go1.16 net/IP#String().(), ".", ":", -1)) |
| 163 | |
| 164 | iaaddr, err := dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.NewIAAddrscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/NewIAAddr().(netscip-go gomod github.com/golang/go/src go1.16 net/.ParseIPscip-go gomod github.com/golang/go/src go1.16 net/ParseIP().(addr), 300*timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second., 300*timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second., nil) |
| 165 | if err != nil { |
| 166 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error creating IAAddr: %s", err) |
| 167 | return |
| 168 | } |
| 169 | |
| 170 | iaaddrRaw, err := iaaddr.MarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IAAddr#MarshalBinary().() |
| 171 | if err != nil { |
| 172 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing IAAddr: %s", err) |
| 173 | return |
| 174 | } |
| 175 | |
| 176 | opts := dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Options#{dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIAAddrscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIAAddr.: [][]byte{iaaddrRaw}} |
| 177 | iana := dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.NewIANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/NewIANA().(solIANA.IAIDscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#IAID., 200*timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second., 250*timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second., opts) |
| 178 | ianaRaw, err := iana.MarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#MarshalBinary().() |
| 179 | if err != nil { |
| 180 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing IANA: %s", err) |
| 181 | return |
| 182 | } |
| 183 | |
| 184 | adv.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options..AddRawscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Options#AddRaw().(dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIANA., ianaRaw) |
| 185 | |
| 186 | rawAdv, err := adv.MarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#MarshalBinary().() |
| 187 | if err != nil { |
| 188 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing advertisement packet: %s.", err) |
| 189 | return |
| 190 | } |
| 191 | |
| 192 | eth := layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.Ethernetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#{ |
| 193 | SrcMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#SrcMAC.: mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..HWscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HW., |
| 194 | DstMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#DstMAC.: target, |
| 195 | EthernetTypescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#EthernetType.: layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.EthernetTypeIPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/EthernetTypeIPv6., |
| 196 | } |
| 197 | |
| 198 | ip6 := layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#{ |
| 199 | Versionscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#Version.: 6, |
| 200 | NextHeaderscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#NextHeader.: layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPProtocolUDPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPProtocolUDP., |
| 201 | HopLimitscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#HopLimit.: 64, |
| 202 | SrcIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#SrcIP.: mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..IPv6scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IPv6., |
| 203 | DstIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#DstIP.: pip6.SrcIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#SrcIP., |
| 204 | } |
| 205 | |
| 206 | udp := layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.UDPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#{ |
| 207 | SrcPortscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#SrcPort.: 547, |
| 208 | DstPortscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#DstPort.: 546, |
| 209 | } |
| 210 | |
| 211 | udp.SetNetworkLayerForChecksumscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/tcpipchecksum#SetNetworkLayerForChecksum().(&ip6) |
| 212 | |
| 213 | dhcp := packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCPv6Layerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCPv6Layer#{ |
| 214 | Rawscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCPv6Layer#Raw.: rawAdv, |
| 215 | } |
| 216 | |
| 217 | err, raw := packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.Serializescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Serialize().(ð, &ip6, &udp, &dhcp) |
| 218 | if err != nil { |
| 219 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing packet: %s.", err) |
| 220 | return |
| 221 | } |
| 222 | |
| 223 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("Sending %d bytes of packet ...", len(raw)) |
| 224 | if err := mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Sendscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Send().(raw); err != nil { |
| 225 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error sending packet: %s", err) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) dhcpReplyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcpReply().(toType string, pkt gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#, req dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Packetscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#, target netscip-go gomod github.com/golang/go/src go1.16 net/.HardwareAddrscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#) { |
| 230 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("Sending spoofed DHCPv6 reply to %s after its %s packet.", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Boldscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Bold().(target.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()), toType) |
| 231 | |
| 232 | err, reply := mod.dhcp6Forscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcp6For().(dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.MessageTypeReplyscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/MessageTypeReply., req) |
| 233 | if err != nil { |
| 234 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("%s", err) |
| 235 | return |
| 236 | } |
| 237 | |
| 238 | var reqIANA dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.IANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA# |
| 239 | if raw, found := req.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options.[dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIANA.]; !found || len(raw) < 1 { |
| 240 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Unexpected DHCPv6 packet, could not find IANA.") |
| 241 | return |
| 242 | } else if err := reqIANA.UnmarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#UnmarshalBinary().(raw[0]); err != nil { |
| 243 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Unexpected DHCPv6 packet, could not deserialize IANA.") |
| 244 | return |
| 245 | } |
| 246 | |
| 247 | var reqIAddr []byte |
| 248 | if raw, found := reqIANA.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#Options.[dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIAAddrscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIAAddr.]; found { |
| 249 | reqIAddr = raw[0] |
| 250 | } else { |
| 251 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Unexpected DHCPv6 packet, could not deserialize request IANA IAAddr.") |
| 252 | return |
| 253 | } |
| 254 | |
| 255 | opts := dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Options#{dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIAAddrscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIAAddr.: [][]byte{reqIAddr}} |
| 256 | iana := dhcp6optsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/.NewIANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/NewIANA().(reqIANA.IAIDscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#IAID., 200*timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second., 250*timescip-go gomod github.com/golang/go/src go1.16 time/.Secondscip-go gomod github.com/golang/go/src go1.16 time/Second., opts) |
| 257 | ianaRaw, err := iana.MarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#MarshalBinary().() |
| 258 | if err != nil { |
| 259 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing IANA: %s", err) |
| 260 | return |
| 261 | } |
| 262 | reply.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options..AddRawscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Options#AddRaw().(dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIANAscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIANA., ianaRaw) |
| 263 | |
| 264 | rawAdv, err := reply.MarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#MarshalBinary().() |
| 265 | if err != nil { |
| 266 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing advertisement packet: %s.", err) |
| 267 | return |
| 268 | } |
| 269 | |
| 270 | pip6 := pkt.Layerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layer().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.LayerTypeIPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/LayerTypeIPv6.).(*layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#) |
| 271 | eth := layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.Ethernetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#{ |
| 272 | SrcMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#SrcMAC.: mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..HWscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#HW., |
| 273 | DstMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#DstMAC.: target, |
| 274 | EthernetTypescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#EthernetType.: layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.EthernetTypeIPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/EthernetTypeIPv6., |
| 275 | } |
| 276 | |
| 277 | ip6 := layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#{ |
| 278 | Versionscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#Version.: 6, |
| 279 | NextHeaderscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#NextHeader.: layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPProtocolUDPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPProtocolUDP., |
| 280 | HopLimitscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#HopLimit.: 64, |
| 281 | SrcIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#SrcIP.: mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..IPv6scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IPv6., |
| 282 | DstIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#DstIP.: pip6.SrcIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#SrcIP., |
| 283 | } |
| 284 | |
| 285 | udp := layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.UDPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#{ |
| 286 | SrcPortscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#SrcPort.: 547, |
| 287 | DstPortscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#DstPort.: 546, |
| 288 | } |
| 289 | |
| 290 | udp.SetNetworkLayerForChecksumscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/tcpipchecksum#SetNetworkLayerForChecksum().(&ip6) |
| 291 | |
| 292 | dhcp := packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.DHCPv6Layerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCPv6Layer#{ |
| 293 | Rawscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/DHCPv6Layer#Raw.: rawAdv, |
| 294 | } |
| 295 | |
| 296 | err, raw := packetsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/.Serializescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Serialize().(ð, &ip6, &udp, &dhcp) |
| 297 | if err != nil { |
| 298 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error serializing packet: %s.", err) |
| 299 | return |
| 300 | } |
| 301 | |
| 302 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("Sending %d bytes of packet ...", len(raw)) |
| 303 | if err := mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Sendscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Send().(raw); err != nil { |
| 304 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("Error sending packet: %s", err) |
| 305 | } |
| 306 | |
| 307 | if toType == "request" { |
| 308 | var addr netscip-go gomod github.com/golang/go/src go1.16 net/.IPscip-go gomod github.com/golang/go/src go1.16 net/IP# |
| 309 | if raw, found := reqIANA.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6/dhcp6opts`/IANA#Options.[dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionIAAddrscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionIAAddr.]; found { |
| 310 | addr = netscip-go gomod github.com/golang/go/src go1.16 net/.IPscip-go gomod github.com/golang/go/src go1.16 net/IP#(raw[0]) |
| 311 | } |
| 312 | |
| 313 | if h, found := mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Lanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Lan..Getscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/LAN#Get().(target.Stringscip-go gomod github.com/golang/go/src go1.16 net/HardwareAddr#String().()); found { |
| 314 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("IPv6 address %s is now assigned to %s", addr.Stringscip-go gomod github.com/golang/go/src go1.16 net/IP#String().(), h) |
| 315 | } else { |
| 316 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("IPv6 address %s is now assigned to %s", addr.Stringscip-go gomod github.com/golang/go/src go1.16 net/IP#String().(), target) |
| 317 | } |
| 318 | } else { |
| 319 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("DHCPv6 renew sent to %s", target) |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) duidMatchesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#duidMatches().(dhcp dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Packetscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#) bool { |
| 324 | if raw, found := dhcp.Optionsscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#Options.[dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.OptionServerIDscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/OptionServerID.]; found && len(raw) >= 1 { |
| 325 | if bytesscip-go gomod github.com/golang/go/src go1.16 bytes/.Equalscip-go gomod github.com/golang/go/src go1.16 bytes/Equal().(raw[0], mod.DUIDRawscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#DUIDRaw.) { |
| 326 | return true |
| 327 | } |
| 328 | } |
| 329 | return false |
| 330 | } |
| 331 | |
| 332 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) onPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#onPacket().(pkt gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#) { |
| 333 | var dhcp dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.Packetscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet# |
| 334 | var err error |
| 335 | |
| 336 | udp := pkt.Layerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layer().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.LayerTypeUDPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/LayerTypeUDP.).(*layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.UDPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/UDP#) |
| 337 | if udp == nil { |
| 338 | return |
| 339 | } |
| 340 | |
| 341 | // we just got a dhcp6 packet? |
| 342 | if err = dhcp.UnmarshalBinaryscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#UnmarshalBinary().(udp.Payloadscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/BaseLayer#Payload.); err == nil { |
| 343 | eth := pkt.Layerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layer().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.LayerTypeEthernetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/LayerTypeEthernet.).(*layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.Ethernetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#) |
| 344 | switch dhcp.MessageTypescip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/Packet#MessageType. { |
| 345 | case dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.MessageTypeSolicitscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/MessageTypeSolicit.: |
| 346 | |
| 347 | mod.dhcpAdvertisescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcpAdvertise().(pkt, dhcp, eth.SrcMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#SrcMAC.) |
| 348 | |
| 349 | case dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.MessageTypeRequestscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/MessageTypeRequest.: |
| 350 | if mod.duidMatchesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#duidMatches().(dhcp) { |
| 351 | mod.dhcpReplyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcpReply().("request", pkt, dhcp, eth.SrcMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#SrcMAC.) |
| 352 | } |
| 353 | |
| 354 | case dhcp6scip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/.MessageTypeRenewscip-go gomod github.com/mdlayher/dhcp6 2a67805d7d0b `github.com/mdlayher/dhcp6`/MessageTypeRenew.: |
| 355 | if mod.duidMatchesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#duidMatches().(dhcp) { |
| 356 | mod.dhcpReplyscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#dhcpReply().("renew", pkt, dhcp, eth.SrcMACscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/Ethernet#SrcMAC.) |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Start().() error { |
| 363 | if err := mod.Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Configure().(); err != nil { |
| 364 | return err |
| 365 | } |
| 366 | |
| 367 | return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(true, func() { |
| 368 | mod.waitGroupscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#waitGroup..Addscip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Add().(1) |
| 369 | defer mod.waitGroupscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#waitGroup..Donescip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Done().() |
| 370 | |
| 371 | src := gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.NewPacketSourcescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/NewPacketSource().(mod.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle., mod.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle..LinkTypescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#LinkType().()) |
| 372 | mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#pktSourceChan. = src.Packetsscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/PacketSource#Packets().() |
| 373 | for packet := range mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#pktSourceChan. { |
| 374 | if !mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 375 | break |
| 376 | } |
| 377 | |
| 378 | mod.onPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#onPacket().(packet) |
| 379 | } |
| 380 | }) |
| 381 | } |
| 382 | |
| 383 | func (mod *DHCP6Spooferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#) Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Stop().() error { |
| 384 | return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(false, func() { |
| 385 | mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#pktSourceChan. <- nil |
| 386 | mod.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#Handle..Closescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#Close().() |
| 387 | mod.waitGroupscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/dhcp6_spoof`/DHCP6Spoofer#waitGroup..Waitscip-go gomod github.com/golang/go/src go1.16 sync/WaitGroup#Wait().() |
| 388 | }) |
| 389 | } |