new: net.sniffer.interface parameter to sniff from a different interface

This commit is contained in:
evilsocket 2025-03-27 07:47:30 +01:00
parent 2662831fab
commit 69b3daa5b9
3 changed files with 21 additions and 2 deletions

View file

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

View file

@ -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: "",

View file

@ -194,7 +194,9 @@ func (s *Session) Close() {
}
}
if s.Firewall != nil {
s.Firewall.Restore()
}
if *s.Options.EnvFile != "" {
envFile, _ := fs.Expand(*s.Options.EnvFile)