Class: BetterCap::SniffOptions
- Inherits:
-
Object
- Object
- BetterCap::SniffOptions
- Defined in:
- lib/bettercap/options/sniff_options.rb
Instance Attribute Summary collapse
-
#custom_parser ⇒ Object
Regular expression to use with the BetterCap::Parsers::Custom parser.
-
#enabled ⇒ Object
If true the BetterCap::Sniffer will be enabled.
-
#filter ⇒ Object
BPF filter to apply to sniffed packets.
-
#local ⇒ Object
If true, bettercap will sniff packets from the local interface as well.
-
#output ⇒ Object
PCAP file name to save captured packets to.
-
#parsers ⇒ Object
Comma separated list of BetterCap::Parsers to enable.
-
#src ⇒ Object
Input PCAP file, if specified the BetterCap::Sniffer will read packets from it instead of the network.
Instance Method Summary collapse
-
#enabled?(parser = nil) ⇒ Boolean
Return true if the specified
parser
is enabled, otherwise false. -
#initialize ⇒ SniffOptions
constructor
A new instance of SniffOptions.
- #parse!(ctx, opts) ⇒ Object
Constructor Details
#initialize ⇒ SniffOptions
Returns a new instance of SniffOptions.
33 34 35 36 37 38 39 40 41 |
# File 'lib/bettercap/options/sniff_options.rb', line 33 def initialize @enabled = false @output = nil @filter = nil @src = nil @parsers = ['*'] @custom_parser = nil @local = false end |
Instance Attribute Details
#custom_parser ⇒ Object
Regular expression to use with the BetterCap::Parsers::Custom parser.
29 30 31 |
# File 'lib/bettercap/options/sniff_options.rb', line 29 def custom_parser @custom_parser end |
#enabled ⇒ Object
If true the BetterCap::Sniffer will be enabled.
18 19 20 |
# File 'lib/bettercap/options/sniff_options.rb', line 18 def enabled @enabled end |
#filter ⇒ Object
BPF filter to apply to sniffed packets.
22 23 24 |
# File 'lib/bettercap/options/sniff_options.rb', line 22 def filter @filter end |
#local ⇒ Object
If true, bettercap will sniff packets from the local interface as well.
31 32 33 |
# File 'lib/bettercap/options/sniff_options.rb', line 31 def local @local end |
#output ⇒ Object
PCAP file name to save captured packets to.
20 21 22 |
# File 'lib/bettercap/options/sniff_options.rb', line 20 def output @output end |
#parsers ⇒ Object
Comma separated list of BetterCap::Parsers to enable.
27 28 29 |
# File 'lib/bettercap/options/sniff_options.rb', line 27 def parsers @parsers end |
#src ⇒ Object
Input PCAP file, if specified the BetterCap::Sniffer will read packets from it instead of the network.
25 26 27 |
# File 'lib/bettercap/options/sniff_options.rb', line 25 def src @src end |
Instance Method Details
#enabled?(parser = nil) ⇒ Boolean
Return true if the specified parser
is enabled, otherwise false.
85 86 87 |
# File 'lib/bettercap/options/sniff_options.rb', line 85 def enabled?( parser = nil ) @enabled and ( parser.nil? or ( @parsers.include?('*') or @parsers.include?(parser.upcase) ) ) end |
#parse!(ctx, opts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/bettercap/options/sniff_options.rb', line 43 def parse!( ctx, opts ) opts.separator "" opts.separator "SNIFFING:".bold opts.separator "" opts.on( '-X', '--sniffer', 'Enable sniffer.' ) do @enabled = true end opts.on( '-L', '--local', "Parse packets coming from/to the address of this computer ( NOTE: Will set -X to true ), default to #{'false'.yellow}." ) do @enabled = true @local = true end opts.on( '--sniffer-source FILE', 'Load packets from the specified PCAP file instead of the interface ( will enable sniffer ).' ) do |v| @enabled = true @src = File. v end opts.on( '--sniffer-output FILE', 'Save all packets to the specified PCAP file ( will enable sniffer ).' ) do |v| @enabled = true @output = File. v end opts.on( '--sniffer-filter EXPRESSION', 'Configure the sniffer to use this BPF filter ( will enable sniffer ).' ) do |v| @enabled = true @filter = v end opts.on( '-P', '--parsers PARSERS', "Comma separated list of packet parsers to enable, '*' for all ( NOTE: Will set -X to true ), available: #{Parsers::Base.available.map { |x| x.yellow }.join(', ')} - default: #{'*'.yellow}" ) do |v| @enabled = true @parsers = Parsers::Base.from_cmdline(v) end opts.on( '--custom-parser EXPRESSION', 'Use a custom regular expression in order to capture and show sniffed data ( NOTE: Will set -X to true ).' ) do |v| @enabled = true @parsers = ['CUSTOM'] @custom_parser = Regexp.new(v) end end |