2019-11-08 01:38:26 +01:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
2020-12-09 18:18:42 +01:00
|
|
|
"github.com/evilsocket/opensnitch/daemon/netfilter"
|
2019-11-08 01:38:26 +01:00
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
)
|
|
|
|
|
2020-03-07 10:23:53 +01:00
|
|
|
// GetQuestions retrieves the domain names a process is trying to resolve.
|
2019-11-08 01:38:26 +01:00
|
|
|
func GetQuestions(nfp *netfilter.Packet) (questions []string) {
|
|
|
|
dnsLayer := nfp.Packet.Layer(layers.LayerTypeDNS)
|
2020-03-07 10:23:53 +01:00
|
|
|
if dnsLayer == nil {
|
|
|
|
return questions
|
|
|
|
}
|
2019-11-08 01:38:26 +01:00
|
|
|
|
|
|
|
dns, _ := dnsLayer.(*layers.DNS)
|
2020-03-07 10:23:53 +01:00
|
|
|
for _, dnsQuestion := range dns.Questions {
|
2019-11-08 01:38:26 +01:00
|
|
|
questions = append(questions, string(dnsQuestion.Name))
|
|
|
|
}
|
|
|
|
|
|
|
|
return questions
|
|
|
|
}
|