mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
42c71845ed
commit
549fdc45af
2 changed files with 17 additions and 42 deletions
|
@ -1,6 +1,7 @@
|
||||||
package modules
|
package modules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/bettercap/bettercap/log"
|
"github.com/bettercap/bettercap/log"
|
||||||
|
@ -8,13 +9,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Prober) sendProbeUPNP(from net.IP, from_hw net.HardwareAddr) {
|
func (p *Prober) sendProbeUPNP(from net.IP, from_hw net.HardwareAddr) {
|
||||||
err, raw := packets.NewUPNPProbe(from, from_hw)
|
name := fmt.Sprintf("%s:%d", packets.UPNPDestIP, packets.UPNPPort)
|
||||||
if err != nil {
|
if addr, err := net.ResolveUDPAddr("udp", name); err != nil {
|
||||||
log.Error("error while sending upnp probe: %v", err)
|
log.Debug("could not resolve %s.", name)
|
||||||
return
|
} else if con, err := net.DialUDP("udp", nil, addr); err != nil {
|
||||||
} else if err := p.Session.Queue.Send(raw); err != nil {
|
log.Debug("could not dial %s.", name)
|
||||||
log.Error("error sending upnp packet: %s", err)
|
|
||||||
} else {
|
} else {
|
||||||
log.Debug("sent %d bytes of UPNP probe", len(raw))
|
defer con.Close()
|
||||||
|
if wrote, _ := con.Write(packets.UPNPDiscoveryPayload); wrote > 0 {
|
||||||
|
p.Session.Queue.TrackSent(uint64(wrote))
|
||||||
|
} else {
|
||||||
|
p.Session.Queue.TrackError()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,6 @@ package packets
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
"github.com/google/gopacket"
|
|
||||||
"github.com/google/gopacket/layers"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -13,40 +10,12 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
UPNPDestMac = net.HardwareAddr{0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb}
|
UPNPDestMac = net.HardwareAddr{0x01, 0x00, 0x5e, 0x00, 0x00, 0xfb}
|
||||||
UPNPDestIP = net.ParseIP("239.255.255.250")
|
UPNPDestIP = net.ParseIP("239.255.255.250")
|
||||||
)
|
UPNPDiscoveryPayload = []byte("M-SEARCH * HTTP/1.1\r\n" +
|
||||||
|
|
||||||
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) +
|
fmt.Sprintf("Host: %s:%d\r\n", UPNPDestIP, UPNPPort) +
|
||||||
"Man: ssdp:discover\r\n" +
|
"Man: ssdp:discover\r\n" +
|
||||||
"ST: ssdp:all\r\n" +
|
"ST: ssdp:all\r\n" +
|
||||||
"MX: 2\r\n" +
|
"MX: 2\r\n" +
|
||||||
"\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