Skip to content

Commit

Permalink
fix: bug of skipping kubedns checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Esonhugh committed Sep 3, 2024
1 parent ae12899 commit d3ec2be
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
"fmt"
"os"

Expand All @@ -24,13 +25,20 @@ var Opts = struct {
}{}

func init() {

RootCmd.PersistentFlags().StringVarP(&Opts.Cidr, "cidr", "c", os.Getenv("KUBERNETES_SERVICE_HOST")+"/16", "cidr like: 192.168.0.1/16")

RootCmd.PersistentFlags().StringVarP(&Opts.DnsServer, "dns-server", "d", "", "dns server")
RootCmd.PersistentFlags().IntVarP(&pkg.DnsTimeout, "dns-timeout", "i", 2, "dns timeout")

RootCmd.PersistentFlags().StringSliceVarP(&Opts.SvcDomains, "svc-domains", "s", []string{}, "service domains, like: kubernetes.default,etcd.default don't add zone like svc.cluster.local")

RootCmd.PersistentFlags().StringVarP(&Opts.Zone, "zone", "z", "cluster.local", "zone")

RootCmd.PersistentFlags().StringVarP(&Opts.OutputFile, "output-file", "o", "", "output file")

RootCmd.PersistentFlags().CountVarP(&Opts.Verbose, "verbose", "v", "log level (-v debug,-vv trace, info")

RootCmd.PersistentFlags().BoolVarP(&Opts.MultiThreadingMode, "thread", "t", false, "multi threading mode, work pair with -n")
RootCmd.PersistentFlags().IntVarP(&Opts.ThreadingNum, "thread-num", "n", 16, "threading num, default 16")

Expand All @@ -40,23 +48,33 @@ func init() {
var RootCmd = &cobra.Command{
Use: "k8spider",
Short: "k8spider is a tool to discover k8s services",
Long: "k8spider is a tool to discover k8s services",
Long: "k8spider is Powerful+Fast+Low Privilege Kubernetes service discovery tools via kubernetes DNS service. Currently supported service ip-port BruteForcing / AXFR Domain Transfer Dump / Coredns WildCard Dump / Pod Verified IP discovery\n\nTopics\n",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Set Log Levels
SetLogLevel(Opts.Verbose)
// Set pkg global config
pkg.Zone = Opts.Zone

// debug print option data
opt, _ := json.MarshalIndent(Opts, "", " ")
log.Tracef("Opts: %v", string(opt))

if Opts.DnsServer != "" {
pkg.NetResolver = pkg.WarpDnsServer(Opts.DnsServer)
}

// Check if current environment is a kubernetes cluster
// If the command is whereisdns, that DNS is not sure , so skip this check
// If the command is whereisdns, which means DNS is not sure , so skip this check!
// If SkipKubeDNSCheck is true, skip this check!
if Opts.SkipKubeDNSCheck == false || cmd.Use != "whereisdns" {
if pkg.CheckKubeDNS() {
log.Warn("current environment is not a kubernetes cluster")
os.Exit(1)
if Opts.SkipKubeDNSCheck == false {
if cmd.Use != "whereisdns" {
if !pkg.CheckKubeDNS() {
log.Warn("current environment is not a kubernetes cluster")
os.Exit(1)
}
}
} else {
log.Tracef("kubernetes environment checking bypassed")
}
},
Run: func(cmd *cobra.Command, args []string) {
Expand Down

0 comments on commit d3ec2be

Please sign in to comment.