new: implemented http.proxy.injectjs and https.proxy.injectjs to inject javascript code, files or URLs without a proxy module

This commit is contained in:
evilsocket 2018-08-14 17:12:22 +02:00
commit 6c3157e9c4
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
4 changed files with 74 additions and 12 deletions

View file

@ -40,6 +40,7 @@ type HTTPProxy struct {
CertFile string
KeyFile string
jsHook string
isTLS bool
isRunning bool
stripper *SSLStripper
@ -106,12 +107,29 @@ func (p *HTTPProxy) doProxy(req *http.Request) bool {
return true
}
func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scriptPath string, stripSSL bool) error {
func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scriptPath string, jsToInject string, stripSSL bool) error {
var err error
p.stripper.Enable(stripSSL)
p.Address = address
if strings.HasPrefix(jsToInject, "http://") || strings.HasPrefix(jsToInject, "https://") {
p.jsHook = fmt.Sprintf("<script src=\"%s\" type=\"text/javascript\"></script></head>", jsToInject)
} else if core.Exists(jsToInject) {
if data, err := ioutil.ReadFile(jsToInject); err != nil {
return err
} else {
jsToInject = string(data)
}
}
if p.jsHook == "" && jsToInject != "" {
if strings.HasPrefix(jsToInject, "<script ") == false {
jsToInject = fmt.Sprintf("<script type=\"text/javascript\">%s</script>", jsToInject)
}
p.jsHook = fmt.Sprintf("%s</head>", jsToInject)
}
if scriptPath != "" {
if err, p.Script = LoadHttpProxyScript(scriptPath, p.sess); err != nil {
return err
@ -187,8 +205,8 @@ func TLSConfigFromCA(ca *tls.Certificate) func(host string, ctx *goproxy.ProxyCt
}
}
func (p *HTTPProxy) ConfigureTLS(address string, proxyPort int, httpPort int, scriptPath string, certFile string, keyFile string, stripSSL bool) (err error) {
if p.Configure(address, proxyPort, httpPort, scriptPath, stripSSL); err != nil {
func (p *HTTPProxy) ConfigureTLS(address string, proxyPort int, httpPort int, scriptPath string, certFile string, keyFile string, jsToInject string, stripSSL bool) (err error) {
if p.Configure(address, proxyPort, httpPort, scriptPath, jsToInject, stripSSL); err != nil {
return err
}