Created
June 2, 2022 16:29
-
-
Save mzpqnxow/f7e4b4cd403ba2ced69284c9e1f0a6a4 to your computer and use it in GitHub Desktop.
zgrab2 bind interface (https://github.com/zmap/zgrab2/issues/351)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/conn.go w/conn.go | |
index ef701c8..f8cfb29 100644 | |
--- i/conn.go | |
+++ w/conn.go | |
@@ -5,7 +5,9 @@ import ( | |
"errors" | |
"io" | |
"net" | |
+ "os" | |
"time" | |
+ "syscall" | |
"github.com/sirupsen/logrus" | |
) | |
@@ -342,6 +344,27 @@ func (d *Dialer) SetDefaults() *Dialer { | |
DualStack: true, | |
} | |
} | |
+ if iface := os.Getenv("ZIFACE"); iface != "" { | |
+ | |
+ ief, err := net.InterfaceByName(iface) | |
+ if err != nil { | |
+ panic("InterfaceByName(): interface specified does not exist") | |
+ } | |
+ | |
+ addrs, err := ief.Addrs() | |
+ if err != nil || len(addrs) == 0 { | |
+ panic("Addrs(): specified interface does not exist or has addresses assigned") | |
+ } | |
+ d.Dialer.LocalAddr = addrs[0] | |
+ d.Dialer.Control = func(network, address string, c syscall.RawConn) error { | |
+ return c.Control(func (fd uintptr) { | |
+ if err := syscall.BindToDevice(int(fd), iface); err != nil { | |
+ panic("BindToDevice(): bind to interface failed") | |
+ } | |
+ }) | |
+ } | |
+ | |
+ } | |
return d | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment