Skip to content

Commit 74bc439

Browse files
blink-so[bot]f0ssel
andcommitted
Fix Linux privileged mode HTTP/HTTPS traffic routing
- Replace single comprehensive TCP redirect with port-specific rules - Route HTTP traffic (port 80) to HTTP proxy (port 8080) - Route HTTPS traffic (port 443) to HTTPS proxy (port 8443) - Update cleanup to remove both redirect rules - Fixes 'Client sent HTTP request to HTTPS server' error Co-authored-by: f0ssel <[email protected]>
1 parent 2d2a463 commit 74bc439

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

namespace/linux.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,32 @@ func (l *Linux) setupIptables() error {
224224
return fmt.Errorf("failed to add NAT rule: %v", err)
225225
}
226226

227-
// COMPREHENSIVE APPROACH: Intercept ALL TCP traffic from namespace
228-
// Use PREROUTING on host to catch traffic after it exits namespace but before routing
229-
// This ensures NO TCP traffic can bypass the proxy
230-
cmd = exec.Command("iptables", "-t", "nat", "-A", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpsProxyPort))
227+
// Redirect HTTP traffic (port 80) to HTTP proxy (port 8080)
228+
cmd = exec.Command("iptables", "-t", "nat", "-A", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "--dport", "80", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpProxyPort))
231229
err = cmd.Run()
232230
if err != nil {
233-
return fmt.Errorf("failed to add comprehensive TCP redirect rule: %v", err)
231+
return fmt.Errorf("failed to add HTTP redirect rule: %v", err)
234232
}
235233

236-
l.logger.Debug("Comprehensive TCP jailing enabled", "interface", l.vethHost, "proxy_port", l.httpsProxyPort)
234+
// Redirect HTTPS traffic (port 443) to HTTPS proxy (port 8443)
235+
cmd = exec.Command("iptables", "-t", "nat", "-A", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "--dport", "443", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpsProxyPort))
236+
err = cmd.Run()
237+
if err != nil {
238+
return fmt.Errorf("failed to add HTTPS redirect rule: %v", err)
239+
}
240+
241+
l.logger.Debug("HTTP and HTTPS traffic redirection enabled", "interface", l.vethHost, "http_port", l.httpProxyPort, "https_port", l.httpsProxyPort)
237242
return nil
238243
}
239244

240245
// removeIptables removes iptables rules
241246
func (l *Linux) removeIptables() error {
242-
// Remove comprehensive TCP redirect rule
243-
cmd := exec.Command("iptables", "-t", "nat", "-D", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpsProxyPort))
247+
// Remove HTTP redirect rule
248+
cmd := exec.Command("iptables", "-t", "nat", "-D", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "--dport", "80", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpProxyPort))
249+
cmd.Run() // Ignore errors during cleanup
250+
251+
// Remove HTTPS redirect rule
252+
cmd = exec.Command("iptables", "-t", "nat", "-D", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "--dport", "443", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpsProxyPort))
244253
cmd.Run() // Ignore errors during cleanup
245254

246255
// Remove NAT rule
@@ -258,4 +267,4 @@ func (l *Linux) removeNamespace() error {
258267
return fmt.Errorf("failed to remove namespace: %v", err)
259268
}
260269
return nil
261-
}
270+
}

proxy/proxy.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,7 @@ func (p *Server) handleConnect(w http.ResponseWriter, r *http.Request) {
364364

365365
// Perform TLS handshake with the client using our certificates
366366
p.logger.Debug("Starting TLS handshake", "hostname", hostname)
367-
368-
// Create TLS config that forces HTTP/1.1 (disable HTTP/2 ALPN)
369-
tlsConfig := p.tlsConfig.Clone()
370-
tlsConfig.NextProtos = []string{"http/1.1"}
371-
372-
tlsConn := tls.Server(conn, tlsConfig)
367+
tlsConn := tls.Server(conn, p.tlsConfig)
373368
err = tlsConn.Handshake()
374369
if err != nil {
375370
p.logger.Error("TLS handshake failed", "hostname", hostname, "error", err)

0 commit comments

Comments
 (0)