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"
|
|
|
|
)
|
|
|
|
|
2019-12-09 11:14:01 +00:00
|
|
|
type Protocol struct {}
|
|
|
|
|
|
|
|
func (p *Protocol) CanAnalyze(packet gopacket.Packet) bool {
|
|
|
|
return packet.Layer(layers.LayerTypeDNS) != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Analyzes the given DHCP packet
|
|
|
|
func (p *Protocol) Analyze(packet gopacket.Packet) error {
|
2019-11-27 16:10:55 +00:00
|
|
|
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
|
2019-12-09 11:14:01 +00:00
|
|
|
p.processDNSQuestion(dnspacket.Questions)
|
|
|
|
p.processDNSAnswer(dnspacket.Answers)
|
2019-11-27 16:10:55 +00:00
|
|
|
|
|
|
|
// No error encountered, return clean
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print a summary after all DNS packets were processed
|
2019-12-09 11:14:01 +00:00
|
|
|
func (p *Protocol) PrintSummary() {
|
|
|
|
output.PrintBlock("DNS Request Summary", p.generateDNSQuestionSummary())
|
|
|
|
output.PrintBlock("DNS Response Summary", p.generateDNSAnswerSummary())
|
2019-11-27 16:10:55 +00:00
|
|
|
}
|