Skip to content

Instantly share code, notes, and snippets.

@mjg123
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjg123/e51551c65dad6cea7c70 to your computer and use it in GitHub Desktop.
Save mjg123/e51551c65dad6cea7c70 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/elazarl/goproxy"
"io/ioutil"
"log"
"net/http"
)
func main() {
proxy := goproxy.NewProxyHttpServer()
proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)
proxy.OnRequest(goproxy.DstHostIs("review.openstack.org:443")).DoFunc(
func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
log.Println(r.URL.Path)
if r.URL.Path == "/projects/openstack-infra/config/config" { // workaround for
r.URL.Path = "/projects/openstack-infra%2Fconfig/config" // https://github.com/elazarl/goproxy/issues/61
}
if r.URL.Path == "/static/hideci.js" {
log.Println("Hijacked!")
hideci, _ := ioutil.ReadFile("/home/mjg/hideci.js") // Change as appropriate
return r, goproxy.NewResponse(r,
goproxy.ContentTypeText, http.StatusOK,
string(hideci))
}
return r, nil
})
log.Fatal(http.ListenAndServe(":8080", proxy))
}
@mjg123
Copy link
Author

mjg123 commented Oct 2, 2014

  • run this with "go run main.go"
  • point browser's http proxy setting to localhost:8080
  • accept warnings about certificates (you are MITM-ing yourself, after all)

@takac
Copy link

takac commented Oct 2, 2014

Also have to run go get github.com/elazarl/goproxy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment