mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 21:43:18 -07:00
fix: protecting concurrent access to LAN hosts
This commit is contained in:
parent
3e8ae0339b
commit
241db0cc66
6 changed files with 43 additions and 23 deletions
|
@ -154,8 +154,8 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
}
|
||||
|
||||
var ip net.IP
|
||||
if t, found := s.Session.Lan.Hosts[target.String()]; found == true {
|
||||
ip = t.IP
|
||||
if h, found := s.Session.Lan.Get(target.String()); found == true {
|
||||
ip = h.IP
|
||||
} else {
|
||||
log.Warning("Address %s not known, using random identity association address.", target.String())
|
||||
rand.Read(ip)
|
||||
|
@ -312,8 +312,8 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
|
|||
addr = net.IP(raw[0])
|
||||
}
|
||||
|
||||
if t, found := s.Session.Lan.Hosts[target.String()]; found == true {
|
||||
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), t)
|
||||
if h, found := s.Session.Lan.Get(target.String()); found == true {
|
||||
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), h)
|
||||
} else {
|
||||
log.Info("[%s] IPv6 address %s is now assigned to %s", core.Green("dhcp6"), addr.String(), target)
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ func (s *DNSSpoofer) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp *
|
|||
redir := fmt.Sprintf("(->%s)", s.Address)
|
||||
who := target.String()
|
||||
|
||||
if t, found := s.Session.Lan.Hosts[target.String()]; found == true {
|
||||
if t, found := s.Session.Lan.Get(target.String()); found == true {
|
||||
who = t.String()
|
||||
}
|
||||
|
||||
|
|
|
@ -71,11 +71,12 @@ func (d Discovery) Author() string {
|
|||
func (d *Discovery) runDiff(cache network.ArpTable) {
|
||||
// check for endpoints who disappeared
|
||||
var rem network.ArpTable = make(network.ArpTable)
|
||||
for mac, t := range d.Session.Lan.Hosts {
|
||||
|
||||
d.Session.Lan.EachHost(func(mac string, e *network.Endpoint) {
|
||||
if _, found := cache[mac]; found == false {
|
||||
rem[mac] = t.IpAddress
|
||||
rem[mac] = e.IpAddress
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
for mac, ip := range rem {
|
||||
d.Session.Lan.Remove(ip, mac)
|
||||
|
|
|
@ -23,8 +23,7 @@ func vIP(ip net.IP) string {
|
|||
}
|
||||
|
||||
address := ip.String()
|
||||
host := session.I.Lan.Get(address)
|
||||
|
||||
host := session.I.Lan.GetByIp(address)
|
||||
if host != nil {
|
||||
if host.Hostname != "" {
|
||||
return host.Hostname
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue