| 1 | package net_sniffscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 5 | "timescip-go gomod github.com/golang/go/src go1.16 time/" |
| 6 | |
| 7 | "github.com/bettercap/bettercap/sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/" |
| 8 | |
| 9 | "github.com/google/gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/" |
| 10 | "github.com/google/gopacket/layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/" |
| 11 | ) |
| 12 | |
| 13 | type Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer# struct { |
| 14 | sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#SessionModule. |
| 15 | Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats. *SnifferStatsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats# |
| 16 | Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx. *SnifferContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext# |
| 17 | pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#pktSourceChan. chan gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet# |
| 18 | |
| 19 | fuzzActivescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzActive. bool |
| 20 | fuzzSilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzSilent. bool |
| 21 | fuzzLayersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzLayers. []string |
| 22 | fuzzRatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRate. float64 |
| 23 | fuzzRatioscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRatio. float64 |
| 24 | } |
| 25 | |
| 26 | func NewSnifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/NewSniffer().(s *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#) *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer# { |
| 27 | mod := &Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#{ |
| 28 | SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#SessionModule.: sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewSessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewSessionModule().("net.sniff", s), |
| 29 | Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats.: nil, |
| 30 | } |
| 31 | |
| 32 | mod.SessionModulescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#SessionModule..Requiresscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Requires().("net.recon") |
| 33 | |
| 34 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewBoolParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewBoolParameter().("net.sniff.verbose", |
| 35 | "false", |
| 36 | "If true, every captured and parsed packet will be sent to the events.stream for displaying, otherwise only the ones parsed at the application layer (sni, http, etc).")) |
| 37 | |
| 38 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewBoolParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewBoolParameter().("net.sniff.local", |
| 39 | "false", |
| 40 | "If true it will consider packets from/to this computer, otherwise it will skip them.")) |
| 41 | |
| 42 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("net.sniff.filter", |
| 43 | "not arp", |
| 44 | "", |
| 45 | "BPF filter for the sniffer.")) |
| 46 | |
| 47 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("net.sniff.regexp", |
| 48 | "", |
| 49 | "", |
| 50 | "If set, only packets matching this regular expression will be considered.")) |
| 51 | |
| 52 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("net.sniff.output", |
| 53 | "", |
| 54 | "", |
| 55 | "If set, the sniffer will write captured packets to this file.")) |
| 56 | |
| 57 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("net.sniff.source", |
| 58 | "", |
| 59 | "", |
| 60 | "If set, the sniffer will read from this pcap file instead of the current interface.")) |
| 61 | |
| 62 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("net.sniff stats", "", |
| 63 | "Print sniffer session configuration and statistics.", |
| 64 | func(args []string) error { |
| 65 | if mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats. == nil { |
| 66 | return fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.16 fmt/Errorf().("No stats yet.") |
| 67 | } |
| 68 | |
| 69 | mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Logscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Log().(mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session.) |
| 70 | |
| 71 | return mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..Printscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#Print().() |
| 72 | })) |
| 73 | |
| 74 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("net.sniff on", "", |
| 75 | "Start network sniffer in background.", |
| 76 | func(args []string) error { |
| 77 | return mod.Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Start().() |
| 78 | })) |
| 79 | |
| 80 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("net.sniff off", "", |
| 81 | "Stop network sniffer in background.", |
| 82 | func(args []string) error { |
| 83 | return mod.Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stop().() |
| 84 | })) |
| 85 | |
| 86 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("net.fuzz on", "", |
| 87 | "Enable fuzzing for every sniffed packet containing the specified layers.", |
| 88 | func(args []string) error { |
| 89 | return mod.StartFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#StartFuzzing().() |
| 90 | })) |
| 91 | |
| 92 | mod.AddHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddHandler().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewModuleHandlerscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewModuleHandler().("net.fuzz off", "", |
| 93 | "Disable fuzzing", |
| 94 | func(args []string) error { |
| 95 | return mod.StopFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#StopFuzzing().() |
| 96 | })) |
| 97 | |
| 98 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewStringParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewStringParameter().("net.fuzz.layers", |
| 99 | "Payload", |
| 100 | "", |
| 101 | "Types of layer to fuzz.")) |
| 102 | |
| 103 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewDecimalParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewDecimalParameter().("net.fuzz.rate", |
| 104 | "1.0", |
| 105 | "Rate in the [0.0,1.0] interval of packets to fuzz.")) |
| 106 | |
| 107 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewDecimalParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewDecimalParameter().("net.fuzz.ratio", |
| 108 | "0.4", |
| 109 | "Rate in the [0.0,1.0] interval of bytes to fuzz for each packet.")) |
| 110 | |
| 111 | mod.AddParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#AddParam().(sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.NewBoolParameterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/NewBoolParameter().("net.fuzz.silent", |
| 112 | "false", |
| 113 | "If true it will not report fuzzed packets.")) |
| 114 | |
| 115 | return mod |
| 116 | } |
| 117 | |
| 118 | func (mod Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Name().() string { |
| 119 | return "net.sniff" |
| 120 | } |
| 121 | |
| 122 | func (mod Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) Descriptionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Description().() string { |
| 123 | return "Sniff packets from the network." |
| 124 | } |
| 125 | |
| 126 | func (mod Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) Authorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Author().() string { |
| 127 | return "Simone Margaritelli <[email protected]>" |
| 128 | } |
| 129 | |
| 130 | func (mod Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) isLocalPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#isLocalPacket().(packet gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#) bool { |
| 131 | ip4l := packet.Layerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layer().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.LayerTypeIPv4scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/LayerTypeIPv4.) |
| 132 | if ip4l != nil { |
| 133 | ip4, _ := ip4l.(*layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPv4scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv4#) |
| 134 | if ip4.SrcIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv4#SrcIP..Equalscip-go gomod github.com/golang/go/src go1.16 net/IP#Equal().(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..IPscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IP.) || ip4.DstIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv4#DstIP..Equalscip-go gomod github.com/golang/go/src go1.16 net/IP#Equal().(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..IPscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IP.) { |
| 135 | return true |
| 136 | } |
| 137 | } else { |
| 138 | ip6l := packet.Layerscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layer().(layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.LayerTypeIPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/LayerTypeIPv6.) |
| 139 | if ip6l != nil { |
| 140 | ip6, _ := ip6l.(*layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/.IPv6scip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#) |
| 141 | if ip6.SrcIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#SrcIP..Equalscip-go gomod github.com/golang/go/src go1.16 net/IP#Equal().(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..IPv6scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IPv6.) || ip6.DstIPscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/layers`/IPv6#DstIP..Equalscip-go gomod github.com/golang/go/src go1.16 net/IP#Equal().(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..IPv6scip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/network`/Endpoint#IPv6.) { |
| 142 | return true |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | return false |
| 147 | } |
| 148 | |
| 149 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) onPacketMatchedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#onPacketMatched().(pkt gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.Packetscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#) { |
| 150 | if mainParserscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mainParser().(pkt, mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Verbosescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Verbose.) { |
| 151 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..NumDumpedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#NumDumped.++ |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Configure().() error { |
| 156 | var err error |
| 157 | |
| 158 | if mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 159 | return sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/.ErrAlreadyStartedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/ErrAlreadyStarted().(mod.Namescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Name().()) |
| 160 | } else if err, mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx. = mod.GetContextscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#GetContext().(); err != nil { |
| 161 | if mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx. != nil { |
| 162 | mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Closescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Close().() |
| 163 | mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx. = nil |
| 164 | } |
| 165 | return err |
| 166 | } |
| 167 | |
| 168 | return nil |
| 169 | } |
| 170 | |
| 171 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Start().() error { |
| 172 | if err := mod.Configurescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Configure().(); err != nil { |
| 173 | return err |
| 174 | } |
| 175 | |
| 176 | return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(true, func() { |
| 177 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats. = NewSnifferStatsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/NewSnifferStats().() |
| 178 | |
| 179 | src := gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/.NewPacketSourcescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/NewPacketSource().(mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Handlescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Handle., mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#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().()) |
| 180 | mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#pktSourceChan. = src.Packetsscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/PacketSource#Packets().() |
| 181 | for packet := range mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#pktSourceChan. { |
| 182 | if !mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 183 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("end pkt loop (pkt=%v filter='%s')", packet, mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Filterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Filter.) |
| 184 | break |
| 185 | } |
| 186 | |
| 187 | now := timescip-go gomod github.com/golang/go/src go1.16 time/.Nowscip-go gomod github.com/golang/go/src go1.16 time/Now().() |
| 188 | if mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..FirstPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#FirstPacket..IsZeroscip-go gomod github.com/golang/go/src go1.16 time/Time#IsZero().() { |
| 189 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..FirstPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#FirstPacket. = now |
| 190 | } |
| 191 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..LastPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#LastPacket. = now |
| 192 | |
| 193 | isLocal := mod.isLocalPacketscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#isLocalPacket().(packet) |
| 194 | if isLocal { |
| 195 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..NumLocalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#NumLocal.++ |
| 196 | } |
| 197 | |
| 198 | if mod.fuzzActivescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzActive. { |
| 199 | mod.doFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#doFuzzing().(packet) |
| 200 | } |
| 201 | |
| 202 | if mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..DumpLocalscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#DumpLocal. || !isLocal { |
| 203 | data := packet.Datascip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Data().() |
| 204 | if mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Compiledscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Compiled. == nil || mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Compiledscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Compiled..Matchscip-go gomod github.com/golang/go/src go1.16 regexp/Regexp#Match().(data) { |
| 205 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..NumMatchedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#NumMatched.++ |
| 206 | |
| 207 | mod.onPacketMatchedscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#onPacketMatched().(packet) |
| 208 | |
| 209 | if mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..OutputWriterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputWriter. != nil { |
| 210 | mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..OutputWriterscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#OutputWriter..WritePacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket/pcapgo`/Writer#WritePacket().(packet.Metadatascip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Metadata().().CaptureInfoscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/PacketMetadata#CaptureInfo., data) |
| 211 | mod.Statsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stats..NumWrotescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferStats#NumWrote.++ |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#pktSourceChan. = nil |
| 218 | }) |
| 219 | } |
| 220 | |
| 221 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) Stopscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Stop().() error { |
| 222 | return mod.SetRunningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#SetRunning().(false, func() { |
| 223 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("stopping sniffer") |
| 224 | if mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#pktSourceChan. != nil { |
| 225 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("sending nil") |
| 226 | mod.pktSourceChanscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#pktSourceChan. <- nil |
| 227 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("nil sent") |
| 228 | } |
| 229 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("closing ctx") |
| 230 | mod.Ctxscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Ctx..Closescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/SnifferContext#Close().() |
| 231 | mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug().("ctx closed") |
| 232 | }) |
| 233 | } |