new: new net.sniff.source parameter to use a PCAP file as source instead of the interface

This commit is contained in:
evilsocket 2018-02-05 17:11:02 +01:00
commit 6e36256dd1
2 changed files with 18 additions and 2 deletions

View file

@ -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 {

View file

@ -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
}