new: WSD discovery agent for net.probe

This commit is contained in:
evilsocket 2018-09-09 14:10:24 +03:00
parent 632f7700bf
commit b6adb2b65f
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
3 changed files with 65 additions and 0 deletions

View file

@ -16,6 +16,7 @@ type Probes struct {
NBNS bool NBNS bool
MDNS bool MDNS bool
UPNP bool UPNP bool
WSD bool
} }
type Prober struct { type Prober struct {
@ -43,6 +44,10 @@ func NewProber(s *session.Session) *Prober {
"true", "true",
"Enable UPNP discovery probes.")) "Enable UPNP discovery probes."))
p.AddParam(session.NewBoolParameter("net.probe.wsd",
"true",
"Enable WSD 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."))
@ -96,6 +101,8 @@ func (p *Prober) Configure() error {
return err return err
} else if err, p.probes.UPNP = p.BoolParam("net.probe.upnp"); err != nil { } else if err, p.probes.UPNP = p.BoolParam("net.probe.upnp"); err != nil {
return err return err
} else if err, p.probes.WSD = p.BoolParam("net.probe.wsd"); err != nil {
return err
} else { } else {
log.Debug("Throttling packets of %d ms.", p.throttle) log.Debug("Throttling packets of %d ms.", p.throttle)
} }
@ -135,6 +142,10 @@ func (p *Prober) Start() error {
p.sendProbeUPNP(from, from_hw) p.sendProbeUPNP(from, from_hw)
} }
if p.probes.WSD {
p.sendProbeWSD(from, from_hw)
}
for _, ip := range addresses { for _, ip := range addresses {
if !p.Running() { if !p.Running() {
return return

26
modules/net_probe_wsd.go Normal file
View file

@ -0,0 +1,26 @@
package modules
import (
"fmt"
"net"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/packets"
)
func (p *Prober) sendProbeWSD(from net.IP, from_hw net.HardwareAddr) {
name := fmt.Sprintf("%s:%d", packets.WSDDestIP, packets.WSDPort)
if addr, err := net.ResolveUDPAddr("udp", name); err != nil {
log.Debug("could not resolve %s.", name)
} else if con, err := net.DialUDP("udp", nil, addr); err != nil {
log.Debug("could not dial %s.", name)
} else {
defer con.Close()
if wrote, _ := con.Write(packets.WSDDiscoveryPayload); wrote > 0 {
p.Session.Queue.TrackSent(uint64(wrote))
} else {
p.Session.Queue.TrackError()
}
}
}

28
packets/wsd.go Normal file
View file

@ -0,0 +1,28 @@
package packets
import (
"net"
)
const (
WSDPort = 3702
)
var (
WSDDestIP = net.ParseIP("239.255.255.250")
WSDDiscoveryPayload = []byte("<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<soap:Envelope" +
" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"" +
" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\"" +
" xmlns:wsd=\"http://schemas.xmlsoap.org/ws/2005/04/discovery\"" +
" xmlns:wsdp=\"http://schemas.xmlsoap.org/ws/2006/02/devprof\">" +
"<soap:Header>" +
"<wsa:To>urn:schemas-xmlsoap-org:ws:2005:04:discovery</wsa:To>" +
"<wsa:Action>http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe</wsa:Action>" +
"<wsa:MessageID>urn:uuid:05a0036e-dcc8-4db8-98b6-0ceeee60a6d9</wsa:MessageID>" +
"</soap:Header>" +
"<soap:Body>" +
"<wsd:Probe/>" +
"</soap:Body>" +
"</env:Envelope>")
)