From 4b0ead9f474fc70f8d5b77f68a950327d6afa997 Mon Sep 17 00:00:00 2001 From: Sam Therapy Date: Wed, 7 Dec 2022 22:05:57 +0100 Subject: [PATCH] make it functional Signed-off-by: Sam Therapy --- cmd/cli.go | 4 ++-- cmd/dig.go | 10 ++++++++++ main.go | 33 +++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/cmd/cli.go b/cmd/cli.go index 3478be3..53b6994 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -57,14 +57,14 @@ func ParseCLI(args []string, version string) (*util.Options, error) { if opts.Trace { if opts.TLS || opts.HTTPS || opts.QUIC { - opts.Logger.Warn("Every query after the root query will only use UDP.") + opts.Logger.Warn("Every query after the root query will only use UDP/TCP") } if opts.Reverse { opts.Logger.Error("Reverse queries are not currently supported") } - opts.RD = false + opts.RD = true } opts.Logger.Info("Options fully populated") diff --git a/cmd/dig.go b/cmd/dig.go index 7316b9e..a6117e5 100644 --- a/cmd/dig.go +++ b/cmd/dig.go @@ -27,6 +27,16 @@ func ParseDig(arg string, opts *util.Options) error { switch arg { case "trace", "notrace": opts.Trace = isNo + if isNo == true { + opts.DNSSEC = true + opts.Display.Comments = false + opts.Display.Question = false + opts.Display.Opt = false + opts.Display.Answer = true + opts.Display.Authority = true + opts.Display.Additional = false + opts.Display.Statistics = false + } // Set DNS query flags case "aa", "aaflag", "aaonly": opts.AA = isNo diff --git a/main.go b/main.go index d1bff34..8f2359e 100644 --- a/main.go +++ b/main.go @@ -91,23 +91,40 @@ func run(args []string) (opts *util.Options, code int, err error) { fmt.Println(str) if keepTracing { - // This part is the part that is broken - /* - this needs to be a random answer that comes from the DNS answers. - Since there is no recursion, and the answers are never recursive. The records should all be NS records. + var nothing []dns.RR - https://pkg.go.dev/github.com/miekg/dns@v1.1.50 - */ if opts.Request.Name == "." { - opts.Request.Server = resp.DNS.Answer[r.Intn(len(resp.DNS.Answer))].Header().Name + nothing = resp.DNS.Answer } else { - opts.Request.Server = resp.DNS.Answer[r.Intn(len(resp.DNS.Ns))].Header().Name + nothing = resp.DNS.Ns } + want := func(rr dns.RR) bool { + temp := strings.Split(rr.String(), "\t") + + return temp[len(temp)-2] == "NS" + } + + i := 0 + + for _, x := range nothing { + if want(x) { + nothing[i] = x + i++ + } + } + + nothing = nothing[:i] + nothing2 := nothing[r.Intn(len(nothing))] + + v := strings.Split(nothing2.String(), "\t") + opts.Request.Server = strings.TrimSuffix(v[len(v)-1], ".") + opts.TLS = false opts.HTTPS = false opts.QUIC = false + opts.RD = false opts.Request.Port = 53 } }