net_sniff_upnp.go 763 Bytes
Newer Older
Sophie Brun's avatar
Sophie Brun committed
1
package net_sniff
Sophie Brun's avatar
Sophie Brun committed
2 3 4 5 6 7 8 9

import (
	"fmt"

	"github.com/bettercap/bettercap/packets"

	"github.com/google/gopacket"
	"github.com/google/gopacket/layers"
Sophie Brun's avatar
Sophie Brun committed
10 11 12

	"github.com/evilsocket/islazy/str"
	"github.com/evilsocket/islazy/tui"
Sophie Brun's avatar
Sophie Brun committed
13 14 15 16 17 18
)

func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
	if data := packets.UPNPGetMeta(pkt); data != nil && len(data) > 0 {
		s := ""
		for name, value := range data {
Sophie Brun's avatar
Sophie Brun committed
19
			s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value))
Sophie Brun's avatar
Sophie Brun committed
20 21 22 23 24 25 26 27 28
		}

		NewSnifferEvent(
			pkt.Metadata().Timestamp,
			"upnp",
			ip.SrcIP.String(),
			ip.DstIP.String(),
			nil,
			"%s %s -> %s : %s",
Sophie Brun's avatar
Sophie Brun committed
29
			tui.Wrap(tui.BACKRED+tui.FOREBLACK, "upnp"),
Sophie Brun's avatar
Sophie Brun committed
30 31
			vIP(ip.SrcIP),
			vIP(ip.DstIP),
Sophie Brun's avatar
Sophie Brun committed
32
			str.Trim(s),
Sophie Brun's avatar
Sophie Brun committed
33 34 35 36 37 38 39
		).Push()

		return true
	}

	return false
}