Skip to content

Fix protocol mismatch when manually specifying v4+v6 --local-addr#679

Open
FineTralfazz wants to merge 4 commits intozmap:masterfrom
FineTralfazz:fix/local-addr-protocol-mismatch
Open

Fix protocol mismatch when manually specifying v4+v6 --local-addr#679
FineTralfazz wants to merge 4 commits intozmap:masterfrom
FineTralfazz:fix/local-addr-protocol-mismatch

Conversation

@FineTralfazz
Copy link

@FineTralfazz FineTralfazz commented Mar 3, 2026

When --local-addr is configured with a mix of IPv4 and IPv6 addresses (e.g. --local-addr 192.168.1.1,2001:db8::1), SetRandomLocalAddr picks one at random without considering the target's address family. This causes scans to fail intermittently. Whenever the randomly chosen local address doesn't match the target's protocol (e.g. binding an IPv6 source for an IPv4 destination), the OS rejects the connection and your grab attempt fails with {"ip":"2607:f8b0:400a:809::200e","data":{"http":{"status":"connection-timeout","protocol":"http","port":80,"result":{},"timestamp":"2026-02-27T13:38:26-08:00","error":"unable to dial target (2607:f8b0:400a:809::200e) with L4 Dialer: dial context failed: dial tcp: address 10.10.9.92:0: no suitable address found"}}}

How to Test

Run this command a few times with the existing implementation:

echo 2607:f8b0:400a:809::200e | ./zgrab2 http --local-addr=[your ipv4 here],[your ipv6 here]

It will fail 50% of the time. Then test mine and confirm that it works consistently.

Notes & Caveats

I've tested this patch locally and it works. However I'm not a particularly experienced Go dev and this is my first time looking at the zgrab2 source code, so feedback is welcome and appreciated. In particular, I'm not sure if filterLocalAddrsByFamily's current return behavior is reasonable or if I should be returning an error.

Issue Tracking

N/A

@FineTralfazz FineTralfazz changed the title Fix/local addr protocol mismatch Fix protocol mismatch when manually specifying v4+v6 --local-addr Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants