mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
0d03264ea5
commit
da48a0fa69
1 changed files with 12 additions and 27 deletions
|
@ -142,39 +142,24 @@ func (p *ArpSpoofer) unSpoof() error {
|
||||||
func (p *ArpSpoofer) pktRouter(eth *layers.Ethernet, ip4 *layers.IPv4, pkt gopacket.Packet) {
|
func (p *ArpSpoofer) pktRouter(eth *layers.Ethernet, ip4 *layers.IPv4, pkt gopacket.Packet) {
|
||||||
if eth == nil || ip4 == nil {
|
if eth == nil || ip4 == nil {
|
||||||
return
|
return
|
||||||
|
} else if ip4.DstIP.Equal(p.Session.Gateway.IP) {
|
||||||
|
return
|
||||||
|
} else if bytes.Compare(eth.DstMAC, p.Session.Interface.HW) != 0 {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if this packet is from or to one of the spoofing targets
|
log.Info("Got packet to route: %s\n", pkt.String())
|
||||||
// and therefore needs patching and forwarding.
|
|
||||||
for _, target := range p.addresses {
|
|
||||||
// we're only interested in packets:
|
|
||||||
//
|
|
||||||
// 1. generated from one of our targets.
|
|
||||||
// 2. going to the router IP
|
|
||||||
// 3. but with our mac addresses as destination
|
|
||||||
|
|
||||||
if ip4.SrcIP.Equal(target) == false {
|
copy(eth.DstMAC, p.Session.Gateway.HW)
|
||||||
continue
|
|
||||||
} else if ip4.DstIP.Equal(p.Session.Gateway.IP) == false {
|
|
||||||
continue
|
|
||||||
} else if bytes.Compare(eth.DstMAC, p.Session.Interface.HW) != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("Got packet to route: %s\n", pkt.String())
|
log.Info("After: %s\n", pkt.String())
|
||||||
|
|
||||||
copy(eth.DstMAC, p.Session.Gateway.HW)
|
data := pkt.Data()
|
||||||
|
if err := p.Session.Queue.Send(data); err != nil {
|
||||||
log.Info("After: %s\n", pkt.String())
|
log.Error("Could not reinject packet: %s", err)
|
||||||
|
} else {
|
||||||
data := pkt.Data()
|
log.Info("Reinjected %d bytes.", len(data))
|
||||||
if err := p.Session.Queue.Send(data); err != nil {
|
|
||||||
log.Error("Could not reinject packet: %s", err)
|
|
||||||
} else {
|
|
||||||
log.Info("Reinjected %d bytes.", len(data))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ArpSpoofer) Configure() error {
|
func (p *ArpSpoofer) Configure() error {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue