| 1 | package net_sniffscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/ |
| 2 | |
| 3 | import ( |
| 4 | "math/randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 6 | |
| 7 | "github.com/google/gopacketscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/" |
| 8 | |
| 9 | "github.com/evilsocket/islazy/strscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/" |
| 10 | ) |
| 11 | |
| 12 | var mutatorsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators. = []func(byte) byte{ |
| 13 | func(bscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators:b. byte) byte { |
| 14 | return byte(randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.16 `math/rand`/Intn().(256) & 0xff) |
| 15 | }, |
| 16 | func(bscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators:b. byte) byte { |
| 17 | return byte(bscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators:b. << uint(randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.16 `math/rand`/Intn().(9))) |
| 18 | }, |
| 19 | func(bscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators:b. byte) byte { |
| 20 | return byte(bscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators:b. >> uint(randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.16 `math/rand`/Intn().(9))) |
| 21 | }, |
| 22 | } |
| 23 | |
| 24 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) fuzzscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzz().(data []byte) int { |
| 25 | changes := 0 |
| 26 | for off, b := range data { |
| 27 | if randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/.Float64scip-go gomod github.com/golang/go/src go1.16 `math/rand`/Float64().() > mod.fuzzRatioscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRatio. { |
| 28 | continue |
| 29 | } |
| 30 | |
| 31 | data[off] = mutatorsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators.[randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/.Intnscip-go gomod github.com/golang/go/src go1.16 `math/rand`/Intn().(len(mutatorsscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/mutators.))](b) |
| 32 | changes++ |
| 33 | } |
| 34 | return changes |
| 35 | } |
| 36 | |
| 37 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) doFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#doFuzzing().(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#) { |
| 38 | if randscip-go gomod github.com/golang/go/src go1.16 `math/rand`/.Float64scip-go gomod github.com/golang/go/src go1.16 `math/rand`/Float64().() > mod.fuzzRatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRate. { |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | layersChanged := 0 |
| 43 | bytesChanged := 0 |
| 44 | |
| 45 | for _, fuzzLayerType := range mod.fuzzLayersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzLayers. { |
| 46 | for _, layer := range pkt.Layersscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Layers().() { |
| 47 | if layer.LayerTypescip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Layer#LayerType().().Stringscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/LayerType#String().() == fuzzLayerType { |
| 48 | fuzzData := layer.LayerContentsscip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Layer#LayerContents().() |
| 49 | changes := mod.fuzzscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzz().(fuzzData) |
| 50 | if changes > 0 { |
| 51 | layersChanged++ |
| 52 | bytesChanged += changes |
| 53 | } |
| 54 | |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if bytesChanged > 0 { |
| 60 | logFn := mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info(). |
| 61 | if mod.fuzzSilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzSilent. { |
| 62 | logFn = mod.Debugscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Debug(). |
| 63 | } |
| 64 | logFn("changed %d bytes in %d layers.", bytesChanged, layersChanged) |
| 65 | if err := mod.Sessionscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Session..Queuescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/Session#Queue..Sendscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/packets`/Queue#Send().(pkt.Datascip-go gomod github.com/google/gopacket v1.1.19 `github.com/google/gopacket`/Packet#Data().()); err != nil { |
| 66 | mod.Errorscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Error().("error sending fuzzed packet: %s", err) |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) configureFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#configureFuzzing().() (err error) { |
| 72 | layers := "" |
| 73 | |
| 74 | if err, layers = mod.StringParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#StringParam().("net.fuzz.layers"); err != nil { |
| 75 | return |
| 76 | } else { |
| 77 | mod.fuzzLayersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzLayers. = strscip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/.Commascip-go gomod github.com/evilsocket/islazy v1.11.0 `github.com/evilsocket/islazy/str`/Comma().(layers) |
| 78 | } |
| 79 | |
| 80 | if err, mod.fuzzRatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRate. = mod.DecParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#DecParam().("net.fuzz.rate"); err != nil { |
| 81 | return |
| 82 | } |
| 83 | |
| 84 | if err, mod.fuzzRatioscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRatio. = mod.DecParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#DecParam().("net.fuzz.ratio"); err != nil { |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | if err, mod.fuzzSilentscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzSilent. = mod.BoolParamscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#BoolParam().("net.fuzz.silent"); err != nil { |
| 89 | return |
| 90 | } |
| 91 | |
| 92 | return |
| 93 | } |
| 94 | |
| 95 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) StartFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#StartFuzzing().() error { |
| 96 | if mod.fuzzActivescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzActive. { |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | if err := mod.configureFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#configureFuzzing().(); err != nil { |
| 101 | return err |
| 102 | } else if !mod.Runningscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Running().() { |
| 103 | if err := mod.Startscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#Start().(); err != nil { |
| 104 | return err |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | mod.fuzzActivescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzActive. = true |
| 109 | |
| 110 | mod.Infoscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/session`/SessionModule#Info().("active on layer types %s (rate:%f ratio:%f)", stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Joinscip-go gomod github.com/golang/go/src go1.16 strings/Join().(mod.fuzzLayersscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzLayers., ","), mod.fuzzRatescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRate., mod.fuzzRatioscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzRatio.) |
| 111 | |
| 112 | return nil |
| 113 | } |
| 114 | |
| 115 | func (mod *Snifferscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#) StopFuzzingscip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#StopFuzzing().() error { |
| 116 | mod.fuzzActivescip-go gomod github.com/bettercap/bettercap . `github.com/bettercap/bettercap/modules/net_sniff`/Sniffer#fuzzActive. = false |
| 117 | return nil |
| 118 | } |