2019-11-27 16:10:55 +00:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
2019-12-03 22:51:03 +00:00
|
|
|
"git.darknebu.la/maride/pancap/output"
|
2019-11-27 16:10:55 +00:00
|
|
|
"github.com/google/gopacket"
|
|
|
|
"github.com/google/gopacket/layers"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Called on every DNS packet
|
|
|
|
func ProcessDNSPacket(packet gopacket.Packet) error {
|
|
|
|
var dnspacket layers.DNS
|
|
|
|
|
|
|
|
// Decode raw packet into DNS
|
|
|
|
decodeErr := dnspacket.DecodeFromBytes(packet.ApplicationLayer().LayerContents(), gopacket.NilDecodeFeedback)
|
|
|
|
if decodeErr != nil {
|
|
|
|
// Encountered an error during decoding, most likely a broken packet
|
|
|
|
return decodeErr
|
|
|
|
}
|
|
|
|
|
|
|
|
// Further process the packet
|
|
|
|
processDNSQuestion(dnspacket.Questions)
|
|
|
|
processDNSAnswer(dnspacket.Answers)
|
|
|
|
|
|
|
|
// No error encountered, return clean
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print a summary after all DNS packets were processed
|
|
|
|
func PrintDNSSummary() {
|
2019-12-03 22:51:03 +00:00
|
|
|
output.PrintBlock("DNS Request Summary", generateDNSQuestionSummary())
|
|
|
|
output.PrintBlock("DNS Response Summary", generateDNSAnswerSummary())
|
2019-11-27 16:10:55 +00:00
|
|
|
}
|