MCPcopy
hub / github.com/bettercap/bettercap / Configure

Method Configure

modules/dns_proxy/dns_proxy_base.go:64–178  ·  view source on GitHub ↗
(address string, dnsPort int, doRedirect bool, nameserver string, netProtocol string, proxyPort int, scriptPath string, certFile string, keyFile string)

Source from the content-addressed store, hash-verified

62}
63
64func (p *DNSProxy) Configure(address string, dnsPort int, doRedirect bool, nameserver string, netProtocol string, proxyPort int, scriptPath string, certFile string, keyFile string) error {
65 var err error
66
67 p.Address = address
68 p.doRedirect = doRedirect
69 p.CertFile = certFile
70 p.KeyFile = keyFile
71
72 if scriptPath != "" {
73 if err, p.Script = LoadDnsProxyScript(scriptPath, p.Sess); err != nil {
74 return err
75 } else {
76 p.Debug("proxy script %s loaded.", scriptPath)
77 }
78 }
79
80 dnsClient := dns.Client{
81 DialTimeout: dialTimeout,
82 Net: netProtocol,
83 ReadTimeout: readTimeout,
84 WriteTimeout: writeTimeout,
85 }
86
87 resolverAddr := fmt.Sprintf("%s:%d", nameserver, dnsPort)
88
89 handler := dns.HandlerFunc(func(w dns.ResponseWriter, req *dns.Msg) {
90 m := new(dns.Msg)
91 m.SetReply(req)
92
93 clientIP := strings.Split(w.RemoteAddr().String(), ":")[0]
94
95 req, res := p.onRequestFilter(req, clientIP)
96 if res == nil {
97 // unused var is time til res
98 res, _, err := dnsClient.Exchange(req, resolverAddr)
99 if err != nil {
100 p.Debug("error while resolving DNS query: %s", err.Error())
101 m.SetRcode(req, dns.RcodeServerFailure)
102 w.WriteMsg(m)
103 return
104 }
105 res = p.onResponseFilter(req, res, clientIP)
106 if res == nil {
107 p.Debug("response is nil")
108 m.SetRcode(req, dns.RcodeServerFailure)
109 w.WriteMsg(m)
110 return
111 } else {
112 if err := w.WriteMsg(res); err != nil {
113 p.Error("Error writing response: %s", err)
114 }
115 }
116 } else {
117 if err := w.WriteMsg(res); err != nil {
118 p.Error("Error writing response: %s", err)
119 }
120 }
121 })

Callers

nothing calls this directly

Calls 14

DebugMethod · 0.95
onRequestFilterMethod · 0.95
ErrorMethod · 0.95
onResponseFilterMethod · 0.95
InfoMethod · 0.95
WarningMethod · 0.95
NewRedirectionFunction · 0.92
LoadDnsProxyScriptFunction · 0.85
IsForwardingEnabledMethod · 0.65
EnableForwardingMethod · 0.65
NameMethod · 0.65
EnableRedirectionMethod · 0.65

Tested by

no test coverage detected