Remote Proxy For Http Injector -
// 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()
go func() { io.Copy(destConn, clientConn) }() io.Copy(clientConn, destConn) }
go build -o remote-proxy proxy.go
func main() { flag.Parse() http.HandleFunc("/", handle) log.Printf("Remote proxy listening on %s", *listenAddr) log.Fatal(http.ListenAndServe(*listenAddr, nil)) } Build: remote proxy for http injector
func extractDestination(r *http.Request) (string, error) { // Priority 1: X-Real-Host header (common in custom payloads) if realHost := r.Header.Get("X-Real-Host"); realHost != "" { return realHost, nil } // Priority 2: Host header if r.Host != "" { return r.Host, nil } // Priority 3: Parse from URL (if GET/POST) if r.URL.Host != "" { return r.URL.Host, nil } return "", fmt.Errorf("no destination found") }
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()
package main import ( "io" "log" "net" "net/http" ) // Hijack the client connection hijacker, ok := w
var ( listenAddr = flag.String("listen", ":8080", "HTTP proxy listen address") )
func (p *connPool) Put(addr string, conn net.Conn) { p.Lock() defer p.Unlock() p.conns[addr] = append(p.conns[addr], conn) } A public remote proxy will be scanned and abused immediately. Implement: IP-based authentication var allowedIPs = map[string]bool{ "192.168.1.100": true, "203.0.113.50": true, } func checkIP(r *http.Request) bool { ip := strings.Split(r.RemoteAddr, ":")[0] return allowedIPs[ip] } TLS (HTTPS) for the proxy control port // Generate certs or use Let's Encrypt log.Fatal(http.ListenAndServeTLS(":8443", "server.crt", "server.key", nil)) Payload size limits & timeouts server := &http.Server{ Addr: ":8080", ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, IdleTimeout: 30 * time.Second, Handler: myHandler, } 7. Full Production-Ready Example (Minimal) package main import ( "flag" "io" "log" "net" "net/http" "strings" "time" )
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 } It will work as a standard tunnel
Configure HTTP Injector with proxy type HTTP → Host your-server-ip → Port 8080 . It will work as a standard tunnel. 4. Adding Injector-Specific Payload Support HTTP Injector often sends custom payloads – not just CONNECT. For example, it might send a crafted HTTP request with a Host header that contains the real destination inside a query parameter or a custom header like X-Forward-Host .
func handleInjectorTunnel(w http.ResponseWriter, r *http.Request) { dest, err := extractDestination(r) if err != nil { http.Error(w, "Missing destination", http.StatusBadRequest) return }
// Send 200 Connection Established clientConn.Write([]byte("HTTP/1.1 200 Connection Established\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 })