mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 05:53:20 -07:00
misc: each module now has its own tagged logging
This commit is contained in:
parent
9003be56ca
commit
9cd4e380fb
47 changed files with 343 additions and 349 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/bettercap/bettercap/log"
|
||||
"github.com/bettercap/bettercap/packets"
|
||||
"github.com/bettercap/bettercap/session"
|
||||
|
||||
|
@ -104,7 +103,7 @@ func (s *DHCP6Spoofer) Configure() error {
|
|||
}
|
||||
|
||||
if !s.Session.Firewall.IsForwardingEnabled() {
|
||||
log.Info("Enabling forwarding.")
|
||||
s.Info("Enabling forwarding.")
|
||||
s.Session.Firewall.EnableForwarding(true)
|
||||
}
|
||||
|
||||
|
@ -131,21 +130,21 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
fqdn = string(raw[0])
|
||||
}
|
||||
|
||||
log.Info("[%s] Got DHCPv6 Solicit request from %s (%s), sending spoofed advertisement for %d domains.", tui.Green("dhcp6"), tui.Bold(fqdn), target, len(s.Domains))
|
||||
s.Info("Got DHCPv6 Solicit request from %s (%s), sending spoofed advertisement for %d domains.", tui.Bold(fqdn), target, len(s.Domains))
|
||||
|
||||
err, adv := s.dhcp6For(dhcp6.MessageTypeAdvertise, solicit)
|
||||
if err != nil {
|
||||
log.Error("%s", err)
|
||||
s.Error("%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var solIANA dhcp6opts.IANA
|
||||
|
||||
if raw, found := solicit.Options[dhcp6.OptionIANA]; !found || len(raw) < 1 {
|
||||
log.Error("Unexpected DHCPv6 packet, could not find IANA.")
|
||||
s.Error("Unexpected DHCPv6 packet, could not find IANA.")
|
||||
return
|
||||
} else if err := solIANA.UnmarshalBinary(raw[0]); err != nil {
|
||||
log.Error("Unexpected DHCPv6 packet, could not deserialize IANA.")
|
||||
s.Error("Unexpected DHCPv6 packet, could not deserialize IANA.")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -153,7 +152,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
if h, found := s.Session.Lan.Get(target.String()); found {
|
||||
ip = h.IP
|
||||
} else {
|
||||
log.Warning("Address %s not known, using random identity association address.", target.String())
|
||||
s.Warning("Address %s not known, using random identity association address.", target.String())
|
||||
rand.Read(ip)
|
||||
}
|
||||
|
||||
|
@ -161,13 +160,13 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
|
||||
iaaddr, err := dhcp6opts.NewIAAddr(net.ParseIP(addr), 300*time.Second, 300*time.Second, nil)
|
||||
if err != nil {
|
||||
log.Error("Error creating IAAddr: %s", err)
|
||||
s.Error("Error creating IAAddr: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
iaaddrRaw, err := iaaddr.MarshalBinary()
|
||||
if err != nil {
|
||||
log.Error("Error serializing IAAddr: %s", err)
|
||||
s.Error("Error serializing IAAddr: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -175,7 +174,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
iana := dhcp6opts.NewIANA(solIANA.IAID, 200*time.Second, 250*time.Second, opts)
|
||||
ianaRaw, err := iana.MarshalBinary()
|
||||
if err != nil {
|
||||
log.Error("Error serializing IANA: %s", err)
|
||||
s.Error("Error serializing IANA: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -183,7 +182,7 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
|
||||
rawAdv, err := adv.MarshalBinary()
|
||||
if err != nil {
|
||||
log.Error("Error serializing advertisement packet: %s.", err)
|
||||
s.Error("Error serializing advertisement packet: %s.", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -214,31 +213,31 @@ func (s *DHCP6Spoofer) dhcpAdvertise(pkt gopacket.Packet, solicit dhcp6.Packet,
|
|||
|
||||
err, raw := packets.Serialize(ð, &ip6, &udp, &dhcp)
|
||||
if err != nil {
|
||||
log.Error("Error serializing packet: %s.", err)
|
||||
s.Error("Error serializing packet: %s.", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug("Sending %d bytes of packet ...", len(raw))
|
||||
s.Debug("Sending %d bytes of packet ...", len(raw))
|
||||
if err := s.Session.Queue.Send(raw); err != nil {
|
||||
log.Error("Error sending packet: %s", err)
|
||||
s.Error("Error sending packet: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.Packet, target net.HardwareAddr) {
|
||||
log.Debug("Sending spoofed DHCPv6 reply to %s after its %s packet.", tui.Bold(target.String()), toType)
|
||||
s.Debug("Sending spoofed DHCPv6 reply to %s after its %s packet.", tui.Bold(target.String()), toType)
|
||||
|
||||
err, reply := s.dhcp6For(dhcp6.MessageTypeReply, req)
|
||||
if err != nil {
|
||||
log.Error("%s", err)
|
||||
s.Error("%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var reqIANA dhcp6opts.IANA
|
||||
if raw, found := req.Options[dhcp6.OptionIANA]; !found || len(raw) < 1 {
|
||||
log.Error("Unexpected DHCPv6 packet, could not find IANA.")
|
||||
s.Error("Unexpected DHCPv6 packet, could not find IANA.")
|
||||
return
|
||||
} else if err := reqIANA.UnmarshalBinary(raw[0]); err != nil {
|
||||
log.Error("Unexpected DHCPv6 packet, could not deserialize IANA.")
|
||||
s.Error("Unexpected DHCPv6 packet, could not deserialize IANA.")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -246,7 +245,7 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
|
|||
if raw, found := reqIANA.Options[dhcp6.OptionIAAddr]; found {
|
||||
reqIAddr = raw[0]
|
||||
} else {
|
||||
log.Error("Unexpected DHCPv6 packet, could not deserialize request IANA IAAddr.")
|
||||
s.Error("Unexpected DHCPv6 packet, could not deserialize request IANA IAAddr.")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -254,14 +253,14 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
|
|||
iana := dhcp6opts.NewIANA(reqIANA.IAID, 200*time.Second, 250*time.Second, opts)
|
||||
ianaRaw, err := iana.MarshalBinary()
|
||||
if err != nil {
|
||||
log.Error("Error serializing IANA: %s", err)
|
||||
s.Error("Error serializing IANA: %s", err)
|
||||
return
|
||||
}
|
||||
reply.Options.AddRaw(dhcp6.OptionIANA, ianaRaw)
|
||||
|
||||
rawAdv, err := reply.MarshalBinary()
|
||||
if err != nil {
|
||||
log.Error("Error serializing advertisement packet: %s.", err)
|
||||
s.Error("Error serializing advertisement packet: %s.", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -293,13 +292,13 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
|
|||
|
||||
err, raw := packets.Serialize(ð, &ip6, &udp, &dhcp)
|
||||
if err != nil {
|
||||
log.Error("Error serializing packet: %s.", err)
|
||||
s.Error("Error serializing packet: %s.", err)
|
||||
return
|
||||
}
|
||||
|
||||
log.Debug("Sending %d bytes of packet ...", len(raw))
|
||||
s.Debug("Sending %d bytes of packet ...", len(raw))
|
||||
if err := s.Session.Queue.Send(raw); err != nil {
|
||||
log.Error("Error sending packet: %s", err)
|
||||
s.Error("Error sending packet: %s", err)
|
||||
}
|
||||
|
||||
if toType == "request" {
|
||||
|
@ -309,12 +308,12 @@ func (s *DHCP6Spoofer) dhcpReply(toType string, pkt gopacket.Packet, req dhcp6.P
|
|||
}
|
||||
|
||||
if h, found := s.Session.Lan.Get(target.String()); found {
|
||||
log.Info("[%s] IPv6 address %s is now assigned to %s", tui.Green("dhcp6"), addr.String(), h)
|
||||
s.Info("IPv6 address %s is now assigned to %s", addr.String(), h)
|
||||
} else {
|
||||
log.Info("[%s] IPv6 address %s is now assigned to %s", tui.Green("dhcp6"), addr.String(), target)
|
||||
s.Info("IPv6 address %s is now assigned to %s", addr.String(), target)
|
||||
}
|
||||
} else {
|
||||
log.Debug("DHCPv6 renew sent to %s", target)
|
||||
s.Debug("DHCPv6 renew sent to %s", target)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue