|
| 1 | +# frozen_string_literal: true |
| 2 | +# |
| 3 | +# ronin-recon - A micro-framework and tool for performing reconnaissance. |
| 4 | +# |
| 5 | +# Copyright (c) 2023-2025 Hal Brodigan ([email protected]) |
| 6 | +# |
| 7 | +# ronin-recon is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU Lesser General Public License as published |
| 9 | +# by the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# ronin-recon is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU Lesser General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU Lesser General Public License |
| 18 | +# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +require_relative '../values' |
| 22 | + |
| 23 | +module Ronin |
| 24 | + module Recon |
| 25 | + class CLI |
| 26 | + # |
| 27 | + # Helper methods for generating display text. |
| 28 | + # |
| 29 | + # @since 0.2.0 |
| 30 | + # |
| 31 | + module Text |
| 32 | + # Mapping of {Value} classes to printable names. |
| 33 | + VALUE_CLASS_NAMES = { |
| 34 | + Values::Domain => 'domain', |
| 35 | + Values::Mailserver => 'mailserver', |
| 36 | + Values::Nameserver => 'nameserver', |
| 37 | + Values::Wildcard => 'wildcard host name', |
| 38 | + Values::Host => 'host', |
| 39 | + Values::IP => 'IP address', |
| 40 | + Values::IPRange => 'IP range', |
| 41 | + Values::OpenPort => 'open port', |
| 42 | + Values::Cert => 'SSL/TLS certificate', |
| 43 | + Values::Website => 'website', |
| 44 | + Values::URL => 'URL', |
| 45 | + Values::EmailAddress => 'email addresse' |
| 46 | + } |
| 47 | + |
| 48 | + # |
| 49 | + # Converts the value class into a printable name. |
| 50 | + # |
| 51 | + # @param [Class<Value>] value_class |
| 52 | + # The value class. |
| 53 | + # |
| 54 | + # @return [String] |
| 55 | + # The descriptive name for the value class. |
| 56 | + # |
| 57 | + # @raise [NotImplementedError] |
| 58 | + # |
| 59 | + def value_class_name(value_class) |
| 60 | + VALUE_CLASS_NAMES.fetch(value_class) do |
| 61 | + raise(NotImplementedError,"unknown value class: #{value_class.inspect}") |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + # |
| 66 | + # Formats a value object into a human readable string. |
| 67 | + # |
| 68 | + # @param [Value] value |
| 69 | + # The value object to format. |
| 70 | + # |
| 71 | + # @return [String] |
| 72 | + # The formatted value. |
| 73 | + # |
| 74 | + # @raise [NotImplementedError] |
| 75 | + # The given value object was not supported. |
| 76 | + # |
| 77 | + def format_value(value) |
| 78 | + case value |
| 79 | + when Values::Domain then "domain #{value}" |
| 80 | + when Values::Mailserver then "mailserver #{value}" |
| 81 | + when Values::Nameserver then "nameserver #{value}" |
| 82 | + when Values::Wildcard then "wildcard host name #{value}" |
| 83 | + when Values::Host then "host #{value}" |
| 84 | + when Values::IP then "IP address #{value}" |
| 85 | + when Values::IPRange then "IP range #{value}" |
| 86 | + when Values::OpenPort then "open #{value.protocol.upcase} port #{value}" |
| 87 | + when Values::Cert then "SSL/TLS certificate #{value.subject}" |
| 88 | + when Values::Website then "website #{value}" |
| 89 | + when Values::URL then "URL #{value}" |
| 90 | + when Values::EmailAddress then "email address #{value}" |
| 91 | + else |
| 92 | + raise(NotImplementedError,"value class #{value.class} not supported") |
| 93 | + end |
| 94 | + end |
| 95 | + end |
| 96 | + end |
| 97 | + end |
| 98 | +end |
0 commit comments