working on NBNS probe

This commit is contained in:
evilsocket 2018-09-06 18:03:26 +03:00
commit 36999813c4
No known key found for this signature in database
GPG key ID: 1564D7F30393A456

View file

@ -7,8 +7,21 @@ import (
"github.com/bettercap/bettercap/log"
)
// NBNS port
const NBNSPort = 137
// NBNS hostname resolution request buffer.
var NBNSRequest = []byte{
0x82, 0x28, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x20, 0x43, 0x4B, 0x41, 0x41, 0x41, 0x41,
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x0,
0x0, 0x21, 0x0, 0x1,
}
func (p *Prober) sendProbeUDP(from net.IP, from_hw net.HardwareAddr, ip net.IP) {
name := fmt.Sprintf("%s:137", ip)
name := fmt.Sprintf("%s:%d", ip, NBNSPort)
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 {
@ -16,13 +29,24 @@ func (p *Prober) sendProbeUDP(from net.IP, from_hw net.HardwareAddr, ip net.IP)
} else {
log.Debug("udp connection to %s enstablished.", name)
buffer := make([]byte, 0xff)
defer con.Close()
wrote, _ := con.Write([]byte{0x00})
wrote, _ := con.Write(NBNSRequest)
log.Info("wrote %d bytes", len(NBNSRequest))
read, _, _ := con.ReadFrom(buffer)
log.Info("got %d bytes of buffer", len(buffer))
if wrote > 0 {
p.Session.Queue.TrackSent(uint64(wrote))
} else {
p.Session.Queue.TrackError()
}
if read > 0 {
p.Session.Queue.TrackPacket(uint64(read))
}
}
}