Skip to content

Commit cab8475

Browse files
blink-so[bot]f0ssel
andcommitted
Implement comprehensive TCP interception for all ports
- Route ALL TCP traffic (any port) to HTTP proxy using iptables REDIRECT - Handles HTTP traffic on any port: 80, 8080, 3000, 9000, etc. - TLS traffic gets clear error messages instead of silent bypass - Clean, simple solution without port-specific rules or protocol detection - Provides complete coverage without hardcoded port lists This ensures no HTTP traffic can bypass the jail regardless of port. Co-authored-by: f0ssel <[email protected]>
1 parent 74bc439 commit cab8475

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

namespace/linux.go

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

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))
227+
// COMPREHENSIVE APPROACH: Route ALL TCP traffic to HTTP proxy
228+
// The HTTP proxy will intelligently handle both HTTP and TLS traffic
229+
cmd = exec.Command("iptables", "-t", "nat", "-A", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpProxyPort))
229230
err = cmd.Run()
230231
if err != nil {
231-
return fmt.Errorf("failed to add HTTP redirect rule: %v", err)
232+
return fmt.Errorf("failed to add comprehensive TCP redirect rule: %v", err)
232233
}
233234

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)
235+
l.logger.Debug("Comprehensive TCP jailing enabled", "interface", l.vethHost, "proxy_port", l.httpProxyPort)
242236
return nil
243237
}
244238

245239
// removeIptables removes iptables rules
246240
func (l *Linux) removeIptables() error {
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))
241+
// Remove comprehensive TCP redirect rule
242+
cmd := exec.Command("iptables", "-t", "nat", "-D", "PREROUTING", "-i", l.vethHost, "-p", "tcp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", l.httpProxyPort))
253243
cmd.Run() // Ignore errors during cleanup
254244

255245
// Remove NAT rule
@@ -267,4 +257,4 @@ func (l *Linux) removeNamespace() error {
267257
return fmt.Errorf("failed to remove namespace: %v", err)
268258
}
269259
return nil
270-
}
260+
}

proxy/proxy.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,12 @@ 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-
tlsConn := tls.Server(conn, p.tlsConfig)
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)
368373
err = tlsConn.Handshake()
369374
if err != nil {
370375
p.logger.Error("TLS handshake failed", "hostname", hostname, "error", err)

0 commit comments

Comments
 (0)