diff --git a/modules/net_sniff/net_sniff.go b/modules/net_sniff/net_sniff.go index 4daa9859..cb2c1b48 100644 --- a/modules/net_sniff/net_sniff.go +++ b/modules/net_sniff/net_sniff.go @@ -59,6 +59,11 @@ func NewSniffer(s *session.Session) *Sniffer { "", "If set, the sniffer will read from this pcap file instead of the current interface.")) + mod.AddParam(session.NewStringParameter("net.sniff.interface", + "", + "", + "Interface to sniff on.")) + mod.AddHandler(session.NewModuleHandler("net.sniff stats", "", "Print sniffer session configuration and statistics.", func(args []string) error { diff --git a/modules/net_sniff/net_sniff_context.go b/modules/net_sniff/net_sniff_context.go index e275ebf8..ccc09ee5 100644 --- a/modules/net_sniff/net_sniff_context.go +++ b/modules/net_sniff/net_sniff_context.go @@ -17,6 +17,7 @@ import ( type SnifferContext struct { Handle *pcap.Handle + Interface string Source string DumpLocal bool Verbose bool @@ -37,13 +38,22 @@ func (mod *Sniffer) GetContext() (error, *SnifferContext) { return err, ctx } + if err, ctx.Interface = mod.StringParam("net.sniff.interface"); err != nil { + return err, ctx + } + + if ctx.Interface == "" { + ctx.Interface = mod.Session.Interface.Name() + } + if ctx.Source == "" { /* * We don't want to pcap.BlockForever otherwise pcap_close(handle) * could hang waiting for a timeout to expire ... */ + readTimeout := 500 * time.Millisecond - if ctx.Handle, err = network.CaptureWithTimeout(mod.Session.Interface.Name(), readTimeout); err != nil { + if ctx.Handle, err = network.CaptureWithTimeout(ctx.Interface, readTimeout); err != nil { return err, ctx } } else { @@ -94,6 +104,8 @@ func (mod *Sniffer) GetContext() (error, *SnifferContext) { func NewSnifferContext() *SnifferContext { return &SnifferContext{ Handle: nil, + Interface: "", + Source: "", DumpLocal: false, Verbose: false, Filter: "", diff --git a/session/session.go b/session/session.go index 983ef1a2..df597b60 100644 --- a/session/session.go +++ b/session/session.go @@ -194,7 +194,9 @@ func (s *Session) Close() { } } - s.Firewall.Restore() + if s.Firewall != nil { + s.Firewall.Restore() + } if *s.Options.EnvFile != "" { envFile, _ := fs.Expand(*s.Options.EnvFile)