diff --git a/modules/net_sniff.go b/modules/net_sniff.go index 82277db7..3d50f56b 100644 --- a/modules/net_sniff.go +++ b/modules/net_sniff.go @@ -39,13 +39,18 @@ func NewSniffer(s *session.Session) *Sniffer { sniff.AddParam(session.NewStringParameter("net.sniff.regexp", "", "", - "If filled, only packets matching this regular expression will be considered.")) + "If set, only packets matching this regular expression will be considered.")) sniff.AddParam(session.NewStringParameter("net.sniff.output", "", "", "If set, the sniffer will write captured packets to this file.")) + sniff.AddParam(session.NewStringParameter("net.sniff.source", + "", + "", + "If set, the sniffer will read from this pcap file instead of the current interface.")) + sniff.AddHandler(session.NewModuleHandler("net.sniff stats", "", "Print sniffer session configuration and statistics.", func(args []string) error { diff --git a/modules/net_sniff_context.go b/modules/net_sniff_context.go index c71f324b..80996306 100644 --- a/modules/net_sniff_context.go +++ b/modules/net_sniff_context.go @@ -15,6 +15,7 @@ import ( type SnifferContext struct { Handle *pcap.Handle + Source string DumpLocal bool Verbose bool Filter string @@ -30,10 +31,20 @@ func (s *Sniffer) GetContext() (error, *SnifferContext) { ctx := NewSnifferContext() - if ctx.Handle, err = pcap.OpenLive(s.Session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil { + if err, ctx.Source = s.StringParam("net.sniff.source"); err != nil { return err, ctx } + if ctx.Source == "" { + if ctx.Handle, err = pcap.OpenLive(s.Session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil { + return err, ctx + } + } else { + if ctx.Handle, err = pcap.OpenOffline(ctx.Source); err != nil { + return err, ctx + } + } + if err, ctx.Verbose = s.BoolParam("net.sniff.verbose"); err != nil { return err, ctx }