| 1 | package net_sniffscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/ |
| 2 | |
| 3 | import ( |
| 4 | "osscip-go gomod github.com/golang/go/src go1.16 os/" |
| 5 | "regexpscip-go gomod github.com/golang/go/src go1.16 regexp/" |
| 6 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 7 | |
| 8 | "github.com/bettercap/bettercap/logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/" |
| 9 | "github.com/bettercap/bettercap/networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/" |
| 10 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 11 | |
| 12 | "github.com/google/gopacket/pcapscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/" |
| 13 | "github.com/google/gopacket/pcapgoscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/" |
| 14 | |
| 15 | "github.com/evilsocket/islazy/tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/" |
| 16 | ) |
| 17 | |
| 18 | type SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext# struct { |
| 19 | Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle. *pcapscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/.Handlescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle# |
| 20 | Sourcescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Source. string |
| 21 | DumpLocalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#DumpLocal. bool |
| 22 | Verbosescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Verbose. bool |
| 23 | Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter. string |
| 24 | Expressionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Expression. string |
| 25 | Compiledscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Compiled. *regexpscip-go gomod github.com/golang/go/src go1.16 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp# |
| 26 | Outputscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Output. string |
| 27 | OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile. *osscip-go gomod github.com/golang/go/src go1.16 os/.Filescip-go gomod github.com/golang/go/src go1.16 os/File# |
| 28 | OutputWriterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputWriter. *pcapgoscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/.Writerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/Writer# |
| 29 | } |
| 30 | |
| 31 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) GetContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#GetContext().() (error, *SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#) { |
| 32 | var err error |
| 33 | |
| 34 | ctx := NewSnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/NewSnifferContext().() |
| 35 | |
| 36 | if err, ctx.Sourcescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Source. = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("net.sniff.source"); err != nil { |
| 37 | return err, ctx |
| 38 | } |
| 39 | |
| 40 | if ctx.Sourcescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Source. == "" { |
| 41 | /* |
| 42 | * We don't want to pcap.BlockForever otherwise pcap_close(handle) |
| 43 | * could hang waiting for a timeout to expire ... |
| 44 | */ |
| 45 | readTimeout := 500 * timescip-go gomod github.com/golang/go/src go1.16 time/.Millisecondscip-go gomod github.com/golang/go/src go1.16 time/Millisecond. |
| 46 | if ctx.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle., err = networkscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/.CaptureWithTimeoutscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/CaptureWithTimeout().(mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Interfacescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Interface..Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#Name().(), readTimeout); err != nil { |
| 47 | return err, ctx |
| 48 | } |
| 49 | } else { |
| 50 | if ctx.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle., err = pcapscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/.OpenOfflinescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/OpenOffline().(ctx.Sourcescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Source.); err != nil { |
| 51 | return err, ctx |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | if err, ctx.Verbosescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Verbose. = mod.BoolParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#BoolParam().("net.sniff.verbose"); err != nil { |
| 56 | return err, ctx |
| 57 | } |
| 58 | |
| 59 | if err, ctx.DumpLocalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#DumpLocal. = mod.BoolParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#BoolParam().("net.sniff.local"); err != nil { |
| 60 | return err, ctx |
| 61 | } |
| 62 | |
| 63 | if err, ctx.Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter. = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("net.sniff.filter"); err != nil { |
| 64 | return err, ctx |
| 65 | } else if ctx.Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter. != "" { |
| 66 | err = ctx.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle..SetBPFFilterscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#SetBPFFilter().(ctx.Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter.) |
| 67 | if err != nil { |
| 68 | return err, ctx |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | if err, ctx.Expressionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Expression. = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("net.sniff.regexp"); err != nil { |
| 73 | return err, ctx |
| 74 | } else if ctx.Expressionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Expression. != "" { |
| 75 | if ctx.Compiledscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Compiled., err = regexpscip-go gomod github.com/golang/go/src go1.16 regexp/.Compilescip-go gomod github.com/golang/go/src go1.16 regexp/Compile().(ctx.Expressionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Expression.); err != nil { |
| 76 | return err, ctx |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | if err, ctx.Outputscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Output. = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("net.sniff.output"); err != nil { |
| 81 | return err, ctx |
| 82 | } else if ctx.Outputscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Output. != "" { |
| 83 | if ctx.OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile., err = osscip-go gomod github.com/golang/go/src go1.16 os/.Createscip-go gomod github.com/golang/go/src go1.16 os/Create().(ctx.Outputscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Output.); err != nil { |
| 84 | return err, ctx |
| 85 | } |
| 86 | |
| 87 | ctx.OutputWriterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputWriter. = pcapgoscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/.NewWriterscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/NewWriter().(ctx.OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile.) |
| 88 | ctx.OutputWriterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputWriter..WriteFileHeaderscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/Writer#WriteFileHeader().(65536, ctx.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle..LinkTypescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#LinkType().()) |
| 89 | } |
| 90 | |
| 91 | return nil, ctx |
| 92 | } |
| 93 | |
| 94 | func NewSnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/NewSnifferContext().() *SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext# { |
| 95 | return &SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#{ |
| 96 | Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle.: nil, |
| 97 | DumpLocalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#DumpLocal.: false, |
| 98 | Verbosescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Verbose.: false, |
| 99 | Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter.: "", |
| 100 | Expressionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Expression.: "", |
| 101 | Compiledscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Compiled.: nil, |
| 102 | Outputscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Output.: "", |
| 103 | OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile.: nil, |
| 104 | OutputWriterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputWriter.: nil, |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | var ( |
| 109 | noscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/no. = tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Redscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Red().("no") |
| 110 | yesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/yes. = tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Greenscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Green().("yes") |
| 111 | ynscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/yn. = map[bool]string{ |
| 112 | true: yesscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/yes., |
| 113 | false: noscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/no., |
| 114 | } |
| 115 | ) |
| 116 | |
| 117 | func (c *SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#) Logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Log().(sess *sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#) { |
| 118 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Info().("Skip local packets : %s", ynscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/yn.[c.DumpLocalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#DumpLocal.]) |
| 119 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Info().("Verbose : %s", ynscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/yn.[c.Verbosescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Verbose.]) |
| 120 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Info().("BPF Filter : '%s'", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Yellowscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Yellow().(c.Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter.)) |
| 121 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Info().("Regular expression : '%s'", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Yellowscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Yellow().(c.Expressionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Expression.)) |
| 122 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Info().("File output : '%s'", tuiscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/.Yellowscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/tui`/Yellow().(c.Outputscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Output.)) |
| 123 | } |
| 124 | |
| 125 | func (c *SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#) Closescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Close().() { |
| 126 | if c.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle. != nil { |
| 127 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Debug().("closing handle") |
| 128 | c.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle..Closescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcap`/Handle#Close().() |
| 129 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Debug().("handle closed") |
| 130 | c.Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle. = nil |
| 131 | } |
| 132 | |
| 133 | if c.OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile. != nil { |
| 134 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Debug().("closing output") |
| 135 | c.OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile..Closescip-go gomod github.com/golang/go/src go1.16 os/File#Close().() |
| 136 | logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/log`/Debug().("output closed") |
| 137 | c.OutputFilescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputFile. = nil |
| 138 | } |
| 139 | } |