generated from Esonhugh/go-cli-template-v2
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from Esonhugh/wildcard
Wildcard Support
- Loading branch information
Showing
7 changed files
with
98 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package wildcard | ||
|
||
import ( | ||
command "github.com/esonhugh/k8spider/cmd" | ||
"github.com/esonhugh/k8spider/pkg/printer" | ||
"github.com/esonhugh/k8spider/pkg/scanner" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
command.RootCmd.AddCommand(WildCardCmd) | ||
} | ||
|
||
var WildCardCmd = &cobra.Command{ | ||
Use: "wild", | ||
Short: "wild is a tool to abuse wildcard feature in kubernetes service discovery", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if command.Opts.Zone == "" { | ||
log.Warn("zone can't empty") | ||
return | ||
} | ||
record := scanner.DumpWildCard(command.Opts.Zone) | ||
if record == nil || len(record) == 0 { | ||
log.Warnf("DumpWildCard Found Nothing") | ||
return | ||
} | ||
printer.PrintResult(record, command.Opts.OutputFile) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package scanner | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/esonhugh/k8spider/define" | ||
"github.com/miekg/dns" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// default target should be zone | ||
func DumpAXFR(target string, dnsServer string) ([]define.Record, error) { | ||
t := new(dns.Transfer) | ||
m := new(dns.Msg) | ||
m.SetAxfr(target) | ||
ch, err := t.In(m, dnsServer) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var records []define.Record | ||
for rr := range ch { | ||
if rr.Error != nil { | ||
log.Debugf("Error: %v", rr.Error) | ||
return records, rr.Error | ||
} | ||
for _, r := range rr.RR { | ||
records = append(records, define.Record{ | ||
SvcDomain: r.Header().Name, | ||
Extra: strings.Join(strings.Split(r.String(), "\t"), " "), | ||
}) | ||
} | ||
log.Debugf("Record: %v", rr.RR) | ||
} | ||
return records, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package scanner | ||
|
||
import ( | ||
"github.com/esonhugh/k8spider/define" | ||
"github.com/esonhugh/k8spider/pkg" | ||
"github.com/miekg/dns" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func DumpWildCard(zone string) []define.Record { | ||
searchDNS := []string{ | ||
dns.Fqdn("any.any.svc." + zone), | ||
dns.Fqdn("any.any.any.svc." + zone), | ||
} | ||
var records []define.Record | ||
for _, dns := range searchDNS { | ||
_, srv, err := pkg.SRVRecord(dns) | ||
if err != nil { | ||
log.Warnf("wildcard dns query to %v failed: %v", dns, err) | ||
continue | ||
} | ||
r := define.Record{} | ||
r.SetSrvRecord(dns, srv) | ||
records = append(records, r) | ||
} | ||
return records | ||
} |