mirror of
https://github.com/maride/pancap.git
synced 2026-04-13 18:45:46 +00:00
Move common code into new package, 'common'
This commit is contained in:
@@ -2,6 +2,7 @@ package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.darknebu.la/maride/pancap/common"
|
||||
"github.com/google/gopacket/layers"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
"log"
|
||||
@@ -37,16 +38,16 @@ func processDNSAnswer(answers []layers.DNSResourceRecord) {
|
||||
processType(answerType, answer.Type)
|
||||
|
||||
// Append full domain and base domain
|
||||
answerDomains = appendIfUnique(name, answerDomains)
|
||||
answerDomains = common.AppendIfUnique(name, answerDomains)
|
||||
|
||||
// Check if we need to add the base name to the private list
|
||||
_, icannManaged := publicsuffix.PublicSuffix(name)
|
||||
if icannManaged {
|
||||
// TLD is managed by ICANN, add to the base list
|
||||
answerBaseDomains = appendIfUnique(basename, answerBaseDomains)
|
||||
answerBaseDomains = common.AppendIfUnique(basename, answerBaseDomains)
|
||||
} else {
|
||||
// it's not managed by ICANN, so it's private - add it to the private list
|
||||
answerPrivateDomains = appendIfUnique(name, answerPrivateDomains)
|
||||
answerPrivateDomains = common.AppendIfUnique(name, answerPrivateDomains)
|
||||
}
|
||||
|
||||
// Check if we got an A record answer
|
||||
@@ -71,19 +72,19 @@ func printDNSAnswerSummary() {
|
||||
// Output base domains answered with
|
||||
if len(answerBaseDomains) > 0 {
|
||||
fmt.Println("Answered with these base domains:")
|
||||
printTree(answerBaseDomains)
|
||||
common.PrintTree(answerBaseDomains)
|
||||
}
|
||||
|
||||
// Output private domains
|
||||
if len(answerPrivateDomains) > 0 {
|
||||
fmt.Println("Answered with these private (non-ICANN managed) domains:")
|
||||
printTree(answerPrivateDomains)
|
||||
common.PrintTree(answerPrivateDomains)
|
||||
}
|
||||
|
||||
// Check for public and private IPs
|
||||
fmt.Printf("Answered with %d public IP addresses and %d private IP addresses\n", len(answerPublicIPv4), len(answerPrivateIPv4))
|
||||
if len(answerPrivateIPv4) > 0 {
|
||||
fmt.Println("Private IP addresses in answer:")
|
||||
printTree(answerPrivateIPv4)
|
||||
common.PrintTree(answerPrivateIPv4)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,20 +21,6 @@ func processType(typearr map[layers.DNSType]int, dnstype layers.DNSType) {
|
||||
typearr[dnstype]++
|
||||
}
|
||||
|
||||
// Appends the appendee to the array if it does not contain appendee yet
|
||||
func appendIfUnique(appendee string, array []string) []string {
|
||||
// Iterate over all elements and check values
|
||||
for _, elem := range array {
|
||||
if elem == appendee {
|
||||
// ... found. Stop here
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
// None found, append
|
||||
return append(array, appendee)
|
||||
}
|
||||
|
||||
// Checks if the given IP is in a private range or not
|
||||
func ipIsPrivate(ip net.IP) bool {
|
||||
// check every private IP block for our IP
|
||||
@@ -49,19 +35,6 @@ func ipIsPrivate(ip net.IP) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Prints each element, along with a small ASCII tree
|
||||
func printTree(strarr []string) {
|
||||
// iterate over each element
|
||||
for iter, elem := range strarr {
|
||||
// check if we got the last element
|
||||
if iter < len(strarr) - 1 {
|
||||
fmt.Printf("|- %s\n", elem)
|
||||
} else {
|
||||
fmt.Printf("'- %s\n\n", elem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a summary string for DNS types in the given array
|
||||
func generateDNSTypeSummary(typearr map[layers.DNSType]int) string {
|
||||
var answerarr []string
|
||||
|
||||
@@ -2,6 +2,7 @@ package dns
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.darknebu.la/maride/pancap/common"
|
||||
"github.com/google/gopacket/layers"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
"log"
|
||||
@@ -36,16 +37,16 @@ func processDNSQuestion(questions []layers.DNSQuestion) {
|
||||
processType(questionType, question.Type)
|
||||
|
||||
// Append full domain and base domain
|
||||
questionDomains = appendIfUnique(name, questionDomains)
|
||||
questionDomains = common.AppendIfUnique(name, questionDomains)
|
||||
|
||||
// Check if we need to add the base name to the private list
|
||||
_, icannManaged := publicsuffix.PublicSuffix(name)
|
||||
if icannManaged {
|
||||
// TLD is managed by ICANN, add to the base list
|
||||
questionBaseDomains = appendIfUnique(basename, questionBaseDomains)
|
||||
questionBaseDomains = common.AppendIfUnique(basename, questionBaseDomains)
|
||||
} else {
|
||||
// it's not managed by ICANN, so it's private - add it to the private list
|
||||
questionPrivateDomains = appendIfUnique(name, questionPrivateDomains)
|
||||
questionPrivateDomains = common.AppendIfUnique(name, questionPrivateDomains)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,12 +61,12 @@ func printDNSQuestionSummary() {
|
||||
// Output base domains asked for
|
||||
if len(questionBaseDomains) > 0 {
|
||||
fmt.Println("Asked for these base domains:")
|
||||
printTree(questionBaseDomains)
|
||||
common.PrintTree(questionBaseDomains)
|
||||
}
|
||||
|
||||
// Output private domains
|
||||
if len(questionPrivateDomains) > 0 {
|
||||
fmt.Println("Asked for these private (non-ICANN managed) domains:")
|
||||
printTree(questionPrivateDomains)
|
||||
common.PrintTree(questionPrivateDomains)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user