mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 04:59:25 -07:00
new: new net.probe.upnp agent
This commit is contained in:
parent
03161b1a95
commit
42c71845ed
3 changed files with 83 additions and 0 deletions
|
@ -15,6 +15,7 @@ import (
|
||||||
type Probes struct {
|
type Probes struct {
|
||||||
NBNS bool
|
NBNS bool
|
||||||
MDNS bool
|
MDNS bool
|
||||||
|
UPNP bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Prober struct {
|
type Prober struct {
|
||||||
|
@ -38,6 +39,10 @@ func NewProber(s *session.Session) *Prober {
|
||||||
"true",
|
"true",
|
||||||
"Enable mDNS discovery probes."))
|
"Enable mDNS discovery probes."))
|
||||||
|
|
||||||
|
p.AddParam(session.NewBoolParameter("net.probe.upnp",
|
||||||
|
"true",
|
||||||
|
"Enable UPNP discovery probes."))
|
||||||
|
|
||||||
p.AddParam(session.NewIntParameter("net.probe.throttle",
|
p.AddParam(session.NewIntParameter("net.probe.throttle",
|
||||||
"10",
|
"10",
|
||||||
"If greater than 0, probe packets will be throttled by this value in milliseconds."))
|
"If greater than 0, probe packets will be throttled by this value in milliseconds."))
|
||||||
|
@ -89,6 +94,8 @@ func (p *Prober) Configure() error {
|
||||||
return err
|
return err
|
||||||
} else if err, p.probes.MDNS = p.BoolParam("net.probe.mdns"); err != nil {
|
} else if err, p.probes.MDNS = p.BoolParam("net.probe.mdns"); err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else if err, p.probes.UPNP = p.BoolParam("net.probe.upnp"); err != nil {
|
||||||
|
return err
|
||||||
} else {
|
} else {
|
||||||
log.Debug("Throttling packets of %d ms.", p.throttle)
|
log.Debug("Throttling packets of %d ms.", p.throttle)
|
||||||
}
|
}
|
||||||
|
@ -124,6 +131,10 @@ func (p *Prober) Start() error {
|
||||||
p.sendProbeMDNS(from, from_hw)
|
p.sendProbeMDNS(from, from_hw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.probes.UPNP {
|
||||||
|
p.sendProbeUPNP(from, from_hw)
|
||||||
|
}
|
||||||
|
|
||||||
for _, ip := range addresses {
|
for _, ip := range addresses {
|
||||||
if !p.Running() {
|
if !p.Running() {
|
||||||
return
|
return
|
||||||
|
|
20
modules/net_probe_upnp.go
Normal file
20
modules/net_probe_upnp.go
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package modules
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/bettercap/bettercap/log"
|
||||||
|
"github.com/bettercap/bettercap/packets"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p *Prober) sendProbeUPNP(from net.IP, from_hw net.HardwareAddr) {
|
||||||
|
err, raw := packets.NewUPNPProbe(from, from_hw)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("error while sending upnp probe: %v", err)
|
||||||
|
return
|
||||||
|
} else if err := p.Session.Queue.Send(raw); err != nil {
|
||||||
|
log.Error("error sending upnp packet: %s", err)
|
||||||
|
} else {
|
||||||
|
log.Debug("sent %d bytes of UPNP probe", len(raw))
|
||||||
|
}
|
||||||
|
}
|
52
packets/upnp.go
Normal file
52
packets/upnp.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package packets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
|
||||||
|
"github.com/google/gopacket"
|
||||||
|
"github.com/google/gopacket/layers"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
UPNPPort = 1900
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
UPNPDestMac = net.HardwareAddr{0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb}
|
||||||
|
UPNPDestIP = net.ParseIP("239.255.255.250")
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewUPNPProbe(from net.IP, from_hw net.HardwareAddr) (error, []byte) {
|
||||||
|
eth := layers.Ethernet{
|
||||||
|
SrcMAC: from_hw,
|
||||||
|
DstMAC: UPNPDestMac,
|
||||||
|
EthernetType: layers.EthernetTypeIPv4,
|
||||||
|
}
|
||||||
|
|
||||||
|
ip4 := layers.IPv4{
|
||||||
|
Protocol: layers.IPProtocolUDP,
|
||||||
|
Version: 4,
|
||||||
|
TTL: 64,
|
||||||
|
SrcIP: from,
|
||||||
|
DstIP: UPNPDestIP,
|
||||||
|
}
|
||||||
|
|
||||||
|
udp := layers.UDP{
|
||||||
|
SrcPort: layers.UDPPort(12345),
|
||||||
|
DstPort: layers.UDPPort(UPNPPort),
|
||||||
|
}
|
||||||
|
|
||||||
|
payload := []byte("M-SEARCH * HTTP/1.1\r\n" +
|
||||||
|
fmt.Sprintf("Host: %s:%d\r\n", UPNPDestIP, UPNPPort) +
|
||||||
|
"Man: ssdp:discover\r\n" +
|
||||||
|
"ST: ssdp:all\r\n" +
|
||||||
|
"MX: 2\r\n" +
|
||||||
|
"\r\n")
|
||||||
|
|
||||||
|
if err := udp.SetNetworkLayerForChecksum(&ip4); err != nil {
|
||||||
|
return err, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return Serialize(ð, &ip4, &udp, gopacket.Payload(payload))
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue