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

Method Configure

modules/http_proxy/http_proxy_base.go:174–263  ·  view source on GitHub ↗
(address string, proxyPort int, httpPort int, doRedirect bool, scriptPath string,
	jsToInject string, stripSSL bool)

Source from the content-addressed store, hash-verified

172}
173
174func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, doRedirect bool, scriptPath string,
175 jsToInject string, stripSSL bool) error {
176 var err error
177
178 // check if another http(s) proxy is using sslstrip and merge strippers
179 if stripSSL {
180 for _, mname := range []string{"http.proxy", "https.proxy"} {
181 err, m := p.Sess.Module(mname)
182 if err == nil && m.Running() {
183 var mextra interface{}
184 var mstripper *SSLStripper
185 mextra = m.Extra()
186 mextramap := mextra.(map[string]interface{})
187 mstripper = mextramap["stripper"].(*SSLStripper)
188 if mstripper != nil && mstripper.Enabled() {
189 p.Info("found another proxy using sslstrip -> merging strippers...")
190 p.Stripper = mstripper
191 break
192 }
193 }
194 }
195 }
196
197 p.Stripper.Enable(stripSSL)
198 p.Address = address
199 p.doRedirect = doRedirect
200 p.jsHook = ""
201
202 if strings.HasPrefix(jsToInject, "http://") || strings.HasPrefix(jsToInject, "https://") {
203 p.jsHook = fmt.Sprintf("<script src=\"%s\" type=\"text/javascript\"></script></head>", jsToInject)
204 } else if fs.Exists(jsToInject) {
205 if data, err := ioutil.ReadFile(jsToInject); err != nil {
206 return err
207 } else {
208 jsToInject = string(data)
209 }
210 }
211
212 if p.jsHook == "" && jsToInject != "" {
213 if !strings.HasPrefix(jsToInject, "<script ") {
214 jsToInject = fmt.Sprintf("<script type=\"text/javascript\">%s</script>", jsToInject)
215 }
216 p.jsHook = fmt.Sprintf("%s</head>", jsToInject)
217 }
218
219 if scriptPath != "" {
220 if err, p.Script = LoadHttpProxyScript(scriptPath, p.Sess); err != nil {
221 return err
222 } else {
223 p.Debug("proxy script %s loaded.", scriptPath)
224 }
225 }
226
227 p.Server = &http.Server{
228 Addr: fmt.Sprintf("%s:%d", p.Address, proxyPort),
229 Handler: p.Proxy,
230 ReadTimeout: httpReadTimeout,
231 WriteTimeout: httpWriteTimeout,

Callers 4

ConfigureTLSMethod · 0.95

Calls 15

EnabledMethod · 0.95
InfoMethod · 0.95
DebugMethod · 0.95
WarningMethod · 0.95
NewRedirectionFunction · 0.92
LoadHttpProxyScriptFunction · 0.85
ModuleMethod · 0.80
RunningMethod · 0.65
ExtraMethod · 0.65
IsForwardingEnabledMethod · 0.65
EnableForwardingMethod · 0.65
NameMethod · 0.65

Tested by 3