mirror of
https://github.com/bettercap/bettercap
synced 2025-07-05 20:42:09 -07:00
new: net.sniffer.interface parameter to sniff from a different interface
This commit is contained in:
parent
2662831fab
commit
69b3daa5b9
3 changed files with 21 additions and 2 deletions
|
@ -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."))
|
"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", "",
|
mod.AddHandler(session.NewModuleHandler("net.sniff stats", "",
|
||||||
"Print sniffer session configuration and statistics.",
|
"Print sniffer session configuration and statistics.",
|
||||||
func(args []string) error {
|
func(args []string) error {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import (
|
||||||
|
|
||||||
type SnifferContext struct {
|
type SnifferContext struct {
|
||||||
Handle *pcap.Handle
|
Handle *pcap.Handle
|
||||||
|
Interface string
|
||||||
Source string
|
Source string
|
||||||
DumpLocal bool
|
DumpLocal bool
|
||||||
Verbose bool
|
Verbose bool
|
||||||
|
@ -37,13 +38,22 @@ func (mod *Sniffer) GetContext() (error, *SnifferContext) {
|
||||||
return err, ctx
|
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 == "" {
|
if ctx.Source == "" {
|
||||||
/*
|
/*
|
||||||
* We don't want to pcap.BlockForever otherwise pcap_close(handle)
|
* We don't want to pcap.BlockForever otherwise pcap_close(handle)
|
||||||
* could hang waiting for a timeout to expire ...
|
* could hang waiting for a timeout to expire ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
readTimeout := 500 * time.Millisecond
|
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
|
return err, ctx
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,6 +104,8 @@ func (mod *Sniffer) GetContext() (error, *SnifferContext) {
|
||||||
func NewSnifferContext() *SnifferContext {
|
func NewSnifferContext() *SnifferContext {
|
||||||
return &SnifferContext{
|
return &SnifferContext{
|
||||||
Handle: nil,
|
Handle: nil,
|
||||||
|
Interface: "",
|
||||||
|
Source: "",
|
||||||
DumpLocal: false,
|
DumpLocal: false,
|
||||||
Verbose: false,
|
Verbose: false,
|
||||||
Filter: "",
|
Filter: "",
|
||||||
|
|
|
@ -194,7 +194,9 @@ func (s *Session) Close() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Firewall.Restore()
|
if s.Firewall != nil {
|
||||||
|
s.Firewall.Restore()
|
||||||
|
}
|
||||||
|
|
||||||
if *s.Options.EnvFile != "" {
|
if *s.Options.EnvFile != "" {
|
||||||
envFile, _ := fs.Expand(*s.Options.EnvFile)
|
envFile, _ := fs.Expand(*s.Options.EnvFile)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue