mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: new net.sniff.source parameter to use a PCAP file as source instead of the interface
This commit is contained in:
parent
0d266ec4d5
commit
6e36256dd1
2 changed files with 18 additions and 2 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue