Module: Ronin::Masscan::CLI::FilteringOptions Private
- Included in:
- Commands::Dump, Commands::Grep, Commands::Print
- Defined in:
- lib/ronin/masscan/cli/filtering_options.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Mixin which adds nmap target filtering options to commands.
Instance Attribute Summary collapse
-
#ip_ranges ⇒ Set<IPAddr>
readonly
private
The IP ranges to filter the targets by.
-
#ips ⇒ Set<String>
readonly
private
The IPs to filter the targets by.
-
#ports ⇒ Set<PortList>
readonly
private
The ports to filter the targets by.
-
#protocols ⇒ Set<:tcp, :udp>
readonly
private
The protocols to filter the targets by.
-
#with_app_protocols ⇒ Set<String>
readonly
private
The app protocols to filter the targets by.
-
#with_payloads ⇒ Set<String, Regexp>
readonly
private
The payload Strings or Regexps to filter the targets by.
Class Method Summary collapse
-
.included(command) ⇒ Object
private
Adds filtering options to the command class including FilteringOptions.
Instance Method Summary collapse
-
#filter_banner_records(records) ⇒ Enumerator::Lazy
private
Filter
Masscan::Banner
records. -
#filter_records(output_file) ⇒ Enumerator::Lazy
private
Filters the masscan records.
-
#filter_records_by_app_protocol(records) ⇒ Enumerator::Lazy
private
Filters the records by app-protocol IDs.
-
#filter_records_by_ip(records) ⇒ Enumerator::Lazy
private
Filters the records by IP address.
-
#filter_records_by_ip_range(records) ⇒ Enumerator::Lazy
private
Filters the records by an IP rangeo.
-
#filter_records_by_payload(records) ⇒ Enumerator::Lazy
private
Filters the records by payload contents.
-
#filter_records_by_port(records) ⇒ Enumerator::Lazy
private
Filters the records by port number.
-
#filter_records_by_protocol(records) ⇒ Enumerator::Lazy
private
Filters the records by protocol.
-
#filter_status_records(records) ⇒ Enumerator::Lazy
private
Filter
Masscan::Status
records. -
#initialize(**kwargs) ⇒ Object
private
Initializes the command.
Instance Attribute Details
#ip_ranges ⇒ Set<IPAddr> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The IP ranges to filter the targets by.
109 110 111 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 109 def ip_ranges @ip_ranges end |
#ips ⇒ Set<String> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The IPs to filter the targets by.
104 105 106 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 104 def ips @ips end |
#ports ⇒ Set<PortList> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The ports to filter the targets by.
114 115 116 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 114 def ports @ports end |
#protocols ⇒ Set<:tcp, :udp> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The protocols to filter the targets by.
99 100 101 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 99 def protocols @protocols end |
#with_app_protocols ⇒ Set<String> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The app protocols to filter the targets by.
119 120 121 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 119 def with_app_protocols @with_app_protocols end |
#with_payloads ⇒ Set<String, Regexp> (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The payload Strings or Regexps to filter the targets by.
124 125 126 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 124 def with_payloads @with_payloads end |
Class Method Details
.included(command) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds filtering options to the command class including Ronin::Masscan::CLI::FilteringOptions.
37 38 39 40 41 42 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 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 37 def self.included(command) command.option :protocol, short: '-P', value: { type: [:tcp, :udp] }, desc: 'Filters the targets by protocol' do |proto| @protocols << proto end command.option :ip, value: { type: String, usage: 'IP' }, desc: 'Filters the targets by IP' do |ip| @ips << ip end command.option :ip_range, value: { type: String, usage: 'CIDR' }, desc: 'Filters the targets by IP range' do |ip_range| @ip_ranges << IPAddr.new(ip_range) end command.option :ports, short: '-p', value: { type: /\A(?:\d+|\d+-\d+)(?:,(?:\d+|\d+-\d+))*\z/, usage: '{PORT | PORT1-PORT2},...' }, desc: 'Filter targets by port number' do |ports| @ports << PortList.parse(ports) end command.option :with_app_protocol, value: { type: /\A[a-z][a-z0-9_-]*\z/, usage: 'APP_PROTOCOL[,...]' }, desc: 'Filters targets with the app protocol' do |app_protocol| @with_app_protocols << app_protocol.to_sym end command.option :with_payload, value: { type: String, usage: 'STRING' }, desc: 'Filters targets containing the payload' do |string| @with_payloads << string end command.option :with_payload_regex, value: { type: Regexp, usage: '/REGEX/' }, desc: 'Filters targets with the matching payload' do |regexp| @with_payloads << regexp end end |
Instance Method Details
#filter_banner_records(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filter Masscan::Banner
records.
208 209 210 211 212 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 208 def (records) records.filter do |record| record.kind_of?(::Masscan::Banner) end end |
#filter_records(output_file) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the masscan records.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 154 def filter_records(output_file) records = output_file.each.lazy unless @protocols.empty? records = filter_records_by_protocol(records) end unless @ips.empty? records = filter_records_by_ip(records) end unless @ip_ranges.empty? records = filter_records_by_ip_range(records) end unless @ports.empty? records = filter_records_by_port(records) end unless @with_app_protocols.empty? records = filter_records_by_app_protocol(records) end unless @with_payloads.empty? records = filter_records_by_payload(records) end return records end |
#filter_records_by_app_protocol(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the records by app-protocol IDs.
285 286 287 288 289 290 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 285 def filter_records_by_app_protocol(records) records.filter do |record| record.kind_of?(::Masscan::Banner) && @with_app_protocols.include?(record.app_protocol) end end |
#filter_records_by_ip(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the records by IP address.
238 239 240 241 242 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 238 def filter_records_by_ip(records) records.filter do |record| @ips.include?(record.ip) end end |
#filter_records_by_ip_range(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the records by an IP rangeo.
253 254 255 256 257 258 259 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 253 def filter_records_by_ip_range(records) records.filter do |record| @ip_ranges.any? do |ip_range| ip_range.include?(record.ip) end end end |
#filter_records_by_payload(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the records by payload contents.
301 302 303 304 305 306 307 308 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 301 def filter_records_by_payload(records) regexp = Regexp.union(@with_payloads.to_a) records.filter do |record| record.kind_of?(::Masscan::Banner) && record.payload =~ regexp end end |
#filter_records_by_port(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the records by port number.
270 271 272 273 274 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 270 def filter_records_by_port(records) records.filter do |record| @ports.include?(record.port) end end |
#filter_records_by_protocol(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filters the records by protocol
223 224 225 226 227 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 223 def filter_records_by_protocol(records) records.filter do |record| @protocols.include?(record.protocol) end end |
#filter_status_records(records) ⇒ Enumerator::Lazy
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Filter Masscan::Status
records.
193 194 195 196 197 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 193 def filter_status_records(records) records.filter do |record| record.kind_of?(::Masscan::Status) end end |
#initialize(**kwargs) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the command.
132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ronin/masscan/cli/filtering_options.rb', line 132 def initialize(**kwargs) super(**kwargs) @protocols = Set.new @ips = Set.new @ip_ranges = Set.new @ports = Set.new # Masscan::Banner filtering options @with_app_protocols = Set.new @with_payloads = Set.new end |