mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
fix: dns.spoof can now handle both ipv4 and ipv6
This commit is contained in:
parent
066214e94b
commit
cb57bf7dc2
1 changed files with 69 additions and 20 deletions
|
@ -102,6 +102,8 @@ func (s *DNSSpoofer) Configure() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *layers.UDP, domain string, req *layers.DNS, target net.HardwareAddr) {
|
func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *layers.UDP, domain string, req *layers.DNS, target net.HardwareAddr) {
|
||||||
|
var err error
|
||||||
|
|
||||||
redir := fmt.Sprintf("(->%s)", s.Address)
|
redir := fmt.Sprintf("(->%s)", s.Address)
|
||||||
if t, found := s.Session.Targets.Targets[target.String()]; found == true {
|
if t, found := s.Session.Targets.Targets[target.String()]; found == true {
|
||||||
log.Info("[%s] Sending spoofed DNS reply for %s %s to %s.", core.Green("dns"), core.Red(domain), core.Dim(redir), core.Bold(t.String()))
|
log.Info("[%s] Sending spoofed DNS reply for %s %s to %s.", core.Green("dns"), core.Red(domain), core.Dim(redir), core.Bold(t.String()))
|
||||||
|
@ -109,7 +111,28 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
|
||||||
log.Info("[%s] Sending spoofed DNS reply for %s %s to %s.", core.Green("dns"), core.Red(domain), core.Dim(redir), core.Bold(target.String()))
|
log.Info("[%s] Sending spoofed DNS reply for %s %s to %s.", core.Green("dns"), core.Red(domain), core.Dim(redir), core.Bold(target.String()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pip := pkt.Layer(layers.LayerTypeIPv6).(*layers.IPv6)
|
var src, dst net.IP
|
||||||
|
|
||||||
|
nlayer := pkt.NetworkLayer()
|
||||||
|
if nlayer == nil {
|
||||||
|
log.Error("Missing network layer skipping packet.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var ipv6 bool
|
||||||
|
|
||||||
|
if nlayer.LayerType() == layers.LayerTypeIPv4 {
|
||||||
|
pip := pkt.Layer(layers.LayerTypeIPv4).(*layers.IPv4)
|
||||||
|
src = pip.DstIP
|
||||||
|
dst = pip.SrcIP
|
||||||
|
ipv6 = false
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pip := pkt.Layer(layers.LayerTypeIPv6).(*layers.IPv6)
|
||||||
|
src = pip.DstIP
|
||||||
|
dst = pip.SrcIP
|
||||||
|
ipv6 = true
|
||||||
|
}
|
||||||
|
|
||||||
eth := layers.Ethernet{
|
eth := layers.Ethernet{
|
||||||
SrcMAC: peth.DstMAC,
|
SrcMAC: peth.DstMAC,
|
||||||
|
@ -117,21 +140,6 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
|
||||||
EthernetType: layers.EthernetTypeIPv6,
|
EthernetType: layers.EthernetTypeIPv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
ip6 := layers.IPv6{
|
|
||||||
Version: 6,
|
|
||||||
NextHeader: layers.IPProtocolUDP,
|
|
||||||
HopLimit: 64,
|
|
||||||
SrcIP: pip.DstIP,
|
|
||||||
DstIP: pip.SrcIP,
|
|
||||||
}
|
|
||||||
|
|
||||||
udp := layers.UDP{
|
|
||||||
SrcPort: pudp.DstPort,
|
|
||||||
DstPort: pudp.SrcPort,
|
|
||||||
}
|
|
||||||
|
|
||||||
udp.SetNetworkLayerForChecksum(&ip6)
|
|
||||||
|
|
||||||
answers := make([]layers.DNSResourceRecord, 0)
|
answers := make([]layers.DNSResourceRecord, 0)
|
||||||
for _, q := range req.Questions {
|
for _, q := range req.Questions {
|
||||||
answers = append(answers,
|
answers = append(answers,
|
||||||
|
@ -153,10 +161,51 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
|
||||||
Answers: answers,
|
Answers: answers,
|
||||||
}
|
}
|
||||||
|
|
||||||
err, raw := packets.Serialize(ð, &ip6, &udp, &dns)
|
var raw []byte
|
||||||
if err != nil {
|
|
||||||
log.Error("Error serializing packet: %s.", err)
|
if ipv6 == true {
|
||||||
return
|
ip6 := layers.IPv6{
|
||||||
|
Version: 6,
|
||||||
|
NextHeader: layers.IPProtocolUDP,
|
||||||
|
HopLimit: 64,
|
||||||
|
SrcIP: src,
|
||||||
|
DstIP: dst,
|
||||||
|
}
|
||||||
|
|
||||||
|
udp := layers.UDP{
|
||||||
|
SrcPort: pudp.DstPort,
|
||||||
|
DstPort: pudp.SrcPort,
|
||||||
|
}
|
||||||
|
|
||||||
|
udp.SetNetworkLayerForChecksum(&ip6)
|
||||||
|
|
||||||
|
err, raw = packets.Serialize(ð, &ip6, &udp, &dns)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error serializing packet: %s.", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
ip4 := layers.IPv4{
|
||||||
|
Protocol: layers.IPProtocolUDP,
|
||||||
|
Version: 4,
|
||||||
|
TTL: 64,
|
||||||
|
SrcIP: src,
|
||||||
|
DstIP: dst,
|
||||||
|
}
|
||||||
|
|
||||||
|
udp := layers.UDP{
|
||||||
|
SrcPort: pudp.DstPort,
|
||||||
|
DstPort: pudp.SrcPort,
|
||||||
|
}
|
||||||
|
|
||||||
|
udp.SetNetworkLayerForChecksum(&ip4)
|
||||||
|
|
||||||
|
err, raw = packets.Serialize(ð, &ip4, &udp, &dns)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error serializing packet: %s.", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("Sending %d bytes of packet ...", len(raw))
|
log.Debug("Sending %d bytes of packet ...", len(raw))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue