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.
- Loading branch information
Showing
7 changed files
with
105 additions
and
30 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
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,40 @@ | ||
package wildcard | ||
|
||
import ( | ||
"os" | ||
|
||
command "github.com/esonhugh/k8spider/cmd" | ||
"github.com/esonhugh/k8spider/define" | ||
"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 | ||
} | ||
printResult(scanner.DumpWildCard(command.Opts.Zone)) | ||
}, | ||
} | ||
|
||
func printResult(records define.Records) { | ||
if command.Opts.OutputFile != "" { | ||
f, err := os.OpenFile(command.Opts.OutputFile, os.O_CREATE|os.O_WRONLY, 0644) | ||
if err != nil { | ||
log.Warnf("OpenFile failed: %v", err) | ||
} | ||
defer f.Close() | ||
records.Print(log.StandardLogger().Writer(), f) | ||
} else { | ||
records.Print(log.StandardLogger().Writer()) | ||
} | ||
} |
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) | ||
continue | ||
} | ||
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 | ||
} |