mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 13:09:49 -07:00
fix: fixed a bug in arp.spoof that caused targets not to be spoofed if not previously known to the attacker computer in terms of Mac address
This commit is contained in:
parent
badd13181d
commit
0e2fd008e4
1 changed files with 44 additions and 40 deletions
|
@ -175,7 +175,7 @@ func (mod *ArpSpoofer) Start() error {
|
||||||
gwIP := mod.Session.Gateway.IP
|
gwIP := mod.Session.Gateway.IP
|
||||||
myMAC := mod.Session.Interface.HW
|
myMAC := mod.Session.Interface.HW
|
||||||
for mod.Running() {
|
for mod.Running() {
|
||||||
mod.arpSpoofTargets(gwIP, myMAC, true, false)
|
mod.arpSpoofTargets(gwIP, myMAC, true, true)
|
||||||
for _, address := range neighbours {
|
for _, address := range neighbours {
|
||||||
if !mod.Session.Skip(address) {
|
if !mod.Session.Skip(address) {
|
||||||
mod.arpSpoofTargets(address, myMAC, true, false)
|
mod.arpSpoofTargets(address, myMAC, true, false)
|
||||||
|
@ -281,47 +281,51 @@ func (mod *ArpSpoofer) arpSpoofTargets(saddr net.IP, smac net.HardwareAddr, chec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ip, mac := range mod.getTargets(probe) {
|
if targets := mod.getTargets(probe); len(targets) == 0 {
|
||||||
if check_running && !mod.Running() {
|
mod.Warning("could not find spoof targets")
|
||||||
return
|
} else {
|
||||||
} else if mod.isWhitelisted(ip, mac) {
|
for ip, mac := range targets {
|
||||||
mod.Debug("%s (%s) is whitelisted, skipping from spoofing loop.", ip, mac)
|
if check_running && !mod.Running() {
|
||||||
continue
|
return
|
||||||
} else if saddr.String() == ip {
|
} else if mod.isWhitelisted(ip, mac) {
|
||||||
continue
|
mod.Debug("%s (%s) is whitelisted, skipping from spoofing loop.", ip, mac)
|
||||||
}
|
continue
|
||||||
|
} else if saddr.String() == ip {
|
||||||
rawIP := net.ParseIP(ip)
|
continue
|
||||||
if err, pkt := packets.NewARPReply(saddr, smac, rawIP, mac); err != nil {
|
|
||||||
mod.Error("error while creating ARP spoof packet for %s: %s", ip, err)
|
|
||||||
} else {
|
|
||||||
mod.Debug("sending %d bytes of ARP packet to %s:%s.", len(pkt), ip, mac.String())
|
|
||||||
mod.Session.Queue.Send(pkt)
|
|
||||||
}
|
|
||||||
|
|
||||||
if mod.fullDuplex && isGW {
|
|
||||||
err := error(nil)
|
|
||||||
gwPacket := []byte(nil)
|
|
||||||
|
|
||||||
if isSpoofing {
|
|
||||||
mod.Debug("telling the gw we are %s", ip)
|
|
||||||
// we told the target we're te gateway, not let's tell the
|
|
||||||
// gateway that we are the target
|
|
||||||
if err, gwPacket = packets.NewARPReply(rawIP, ourHW, gwIP, gwHW); err != nil {
|
|
||||||
mod.Error("error while creating ARP spoof packet: %s", err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mod.Debug("telling the gw %s is %s", ip, mac)
|
|
||||||
// send the gateway the original MAC of the target
|
|
||||||
if err, gwPacket = packets.NewARPReply(rawIP, mac, gwIP, gwHW); err != nil {
|
|
||||||
mod.Error("error while creating ARP spoof packet: %s", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if gwPacket != nil {
|
rawIP := net.ParseIP(ip)
|
||||||
mod.Debug("sending %d bytes of ARP packet to the gateway", len(gwPacket))
|
if err, pkt := packets.NewARPReply(saddr, smac, rawIP, mac); err != nil {
|
||||||
if err = mod.Session.Queue.Send(gwPacket); err != nil {
|
mod.Error("error while creating ARP spoof packet for %s: %s", ip, err)
|
||||||
mod.Error("error while sending packet: %v", err)
|
} else {
|
||||||
|
mod.Debug("sending %d bytes of ARP packet to %s:%s.", len(pkt), ip, mac.String())
|
||||||
|
mod.Session.Queue.Send(pkt)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mod.fullDuplex && isGW {
|
||||||
|
err := error(nil)
|
||||||
|
gwPacket := []byte(nil)
|
||||||
|
|
||||||
|
if isSpoofing {
|
||||||
|
mod.Debug("telling the gw we are %s", ip)
|
||||||
|
// we told the target we're te gateway, not let's tell the
|
||||||
|
// gateway that we are the target
|
||||||
|
if err, gwPacket = packets.NewARPReply(rawIP, ourHW, gwIP, gwHW); err != nil {
|
||||||
|
mod.Error("error while creating ARP spoof packet: %s", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mod.Debug("telling the gw %s is %s", ip, mac)
|
||||||
|
// send the gateway the original MAC of the target
|
||||||
|
if err, gwPacket = packets.NewARPReply(rawIP, mac, gwIP, gwHW); err != nil {
|
||||||
|
mod.Error("error while creating ARP spoof packet: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if gwPacket != nil {
|
||||||
|
mod.Debug("sending %d bytes of ARP packet to the gateway", len(gwPacket))
|
||||||
|
if err = mod.Session.Queue.Send(gwPacket); err != nil {
|
||||||
|
mod.Error("error while sending packet: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue