@@ -224,23 +224,32 @@ func (l *Linux) setupIptables() error {
224
224
return fmt .Errorf ("failed to add NAT rule: %v" , err )
225
225
}
226
226
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 ))
231
229
err = cmd .Run ()
232
230
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 )
234
232
}
235
233
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 )
237
242
return nil
238
243
}
239
244
240
245
// removeIptables removes iptables rules
241
246
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 ))
244
253
cmd .Run () // Ignore errors during cleanup
245
254
246
255
// Remove NAT rule
@@ -258,4 +267,4 @@ func (l *Linux) removeNamespace() error {
258
267
return fmt .Errorf ("failed to remove namespace: %v" , err )
259
268
}
260
269
return nil
261
- }
270
+ }
0 commit comments