Everything You Want to Know About France and More...

Remote Proxy For Http Injector -

go build -o remote-proxy proxy.go

func handle(w http.ResponseWriter, r *http.Request) { dest := r.Header.Get("X-Real-Host") if dest == "" { dest = r.Host } if dest == "" { http.Error(w, "Missing destination", 400) return }

// Connect to destination dialer := net.Dialer{Timeout: 10 * time.Second} destConn, err := dialer.Dial("tcp", dest) if err != nil { http.Error(w, err.Error(), 502) return } defer destConn.Close()

destConn, err := net.Dial("tcp", dest) if err != nil { log.Printf("Failed to connect to %s: %v", dest, err) http.Error(w, err.Error(), http.StatusBadGateway) return } defer destConn.Close() remote proxy for http injector

GET http://injector.example.com/ HTTP/1.1 Host: injected.host.com X-Real-Host: target.com:443 We need to parse the real destination from custom headers. package main import ( "bufio" "bytes" "io" "log" "net" "net/http" "strings" )

func main() { flag.Parse() http.HandleFunc("/", handle) log.Printf("Remote proxy listening on %s", *listenAddr) log.Fatal(http.ListenAndServe(*listenAddr, nil)) } Build:

package main import ( "io" "log" "net" "net/http" ) go build -o remote-proxy proxy

// Ensure port is present if !strings.Contains(dest, ":") { dest = dest + ":80" // default to HTTP }

func main() { server := &http.Server{ Addr: ":8080", Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodConnect { handleTunnel(w, r) return } http.Error(w, "Only CONNECT method allowed", http.StatusMethodNotAllowed) }), } log.Fatal(server.ListenAndServe()) }

go func() { io.Copy(destConn, clientConn) }() io.Copy(clientConn, destConn) } err := dialer.Dial("tcp"

// Bidirectional copy go func() { io.Copy(destConn, clientConn) }() io.Copy(clientConn, destConn) }

// Hijack the client connection hijacker, ok := w.(http.Hijacker) if !ok { http.Error(w, "Hijacking not supported", http.StatusInternalServerError) return } clientConn, _, err := hijacker.Hijack() if err != nil { http.Error(w, err.Error(), http.StatusServiceUnavailable) return } defer clientConn.Close()

// Send 200 Connection Established clientConn.Write([]byte("HTTP/1.1 200 Connection Established\r\n\r\n"))

clientConn.Write([]byte("HTTP/1.1 200 OK\r\n\r\n"))

func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // Handle both CONNECT and normal HTTP requests with custom payload if r.Method == http.MethodConnect { handleInjectorTunnel(w, r) return } handleInjectorTunnel(w, r) // also handle GET/POST injector payloads })

Scroll to Top