Skip to content

Commit

Permalink
Merge pull request #1235 from BishopFox/dns-specification
Browse files Browse the repository at this point in the history
Adding support for specifying DNS resolvers through advanced options
  • Loading branch information
moloch-- authored May 15, 2023
2 parents 4690430 + 52daa1a commit 47f10d0
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions implant/sliver/transports/dnsclient/dnsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type DNSOptions struct {
WorkersPerResolver int
ForceBase32 bool
ForceResolvConf string
ForceResolvers string
}

// ParseDNSOptions - Parse c2 specific options
Expand Down Expand Up @@ -141,6 +142,7 @@ func ParseDNSOptions(c2URI *url.URL) *DNSOptions {
WorkersPerResolver: workersPerResolver,
ForceBase32: strings.ToLower(c2URI.Query().Get("force-base32")) == "true",
ForceResolvConf: c2URI.Query().Get("force-resolv-conf"),
ForceResolvers: c2URI.Query().Get("resolvers"),
}
}

Expand All @@ -166,6 +168,7 @@ func NewDNSClient(parent string, opts *DNSOptions) *SliverDNSClient {
parent: parent,
forceBase32: opts.ForceBase32,
forceResolvConf: opts.ForceResolvConf,
forceResolvers: opts.ForceResolvers,
queryTimeout: opts.QueryTimeout,
retryWait: opts.RetryWait,
retryCount: opts.RetryCount,
Expand All @@ -190,6 +193,7 @@ type SliverDNSClient struct {
queryTimeout time.Duration
forceBase32 bool
forceResolvConf string
forceResolvers string
subdataSpace int
dnsSessionID uint32
msgCount uint32
Expand Down Expand Up @@ -738,13 +742,33 @@ func (s *SliverDNSClient) getDNSSessionID() error {

func (s *SliverDNSClient) loadResolvConf() error {
var err error
if len(s.forceResolvConf) < 1 {
if len(s.forceResolvConf) < 1 && s.forceResolvers == "" {
s.resolvConf, err = dnsClientConfig()
} else if s.forceResolvers != "" {
// Convert the specified resolvers into a string that dns.ClientConfigFromReader can understand
// Strip out spaces and split on commas
resolversSlice := strings.Split(s.forceResolvers, " ")
s.resolvConf, err = dns.ClientConfigFromReader(strings.NewReader("nameserver " + strings.Join(resolversSlice, "\nnameserver ")))
if err != nil {
// {{if .Config.Debug}}
log.Printf("[dns] Error trying to use specified resolvers (%s): %s", s.forceResolvers, err.Error())
// {{end}}
} else {
// {{if .Config.Debug}}
log.Printf("[dns] Using specified DNS resolvers: %s", s.forceResolvers)
// {{end}}
}
} else {
// {{if .Config.Debug}}
log.Printf("[dns] Using forced resolv.conf: %s", s.forceResolvConf)
// {{end}}
s.resolvConf, err = dns.ClientConfigFromReader(strings.NewReader(s.forceResolvConf))
if err != nil {
// {{if .Config.Debug}}
log.Printf("[dns] Error trying to use forced resolv.conf (%s): %s", s.forceResolvConf, err.Error())
// {{end}}
} else {
// {{if .Config.Debug}}
log.Printf("[dns] Using forced resolv.conf: %s", s.forceResolvConf)
// {{end}}
}
}
return err
}
Expand Down

0 comments on commit 47f10d0

Please sign in to comment.