Class: Ronin::CLI::Commands::CertGrab Private

Inherits:
ValueProcessorCommand show all
Includes:
HostAndPort
Defined in:
lib/ronin/cli/commands/cert_grab.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Downloads the SSL/TLS certificate for a SSL/TLS service or https:// URL.

Usage

ronin cert-grab [options] {HOST:PORT | URL} ...

Options

-f, --file FILE                  Optional file to read values from
-h, --help                       Print help information

Arguments

HOST:PORT | URL ...              A HOST:PORT or URL

Examples

ronin cert-grab github.com:443
ronin cert-grab 93.184.216.34:443
ronin cert-grab https://github.com/

Since:

  • 2.0.0

Instance Attribute Summary

Attributes inherited from ValueProcessorCommand

#files

Instance Method Summary collapse

Methods included from HostAndPort

#host_and_port, #host_and_port_from_url

Methods inherited from ValueProcessorCommand

#initialize, #process_file, #run

Constructor Details

This class inherits a constructor from Ronin::CLI::ValueProcessorCommand

Instance Method Details

#cert_file_for(host, port) ⇒ String

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 output file for the given host and port.

Parameters:

  • host (String)
  • port (Integer)

Returns:

  • (String)

    The output .crt file to save the certificate to.

Since:

  • 2.0.0



106
107
108
# File 'lib/ronin/cli/commands/cert_grab.rb', line 106

def cert_file_for(host,port)
  "#{host}:#{port}.crt"
end

#grab_cert(host, port) ⇒ 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.

Downloads the certificate for the given host and port.

Parameters:

  • host (String)

    The host to connect to.

  • port (Integer)

    The port to connect to.

Since:

  • 2.0.0



119
120
121
122
123
# File 'lib/ronin/cli/commands/cert_grab.rb', line 119

def grab_cert(host,port)
  cert = Support::Network::SSL.get_cert(host,port)

  cert.save(cert_file_for(host,port))
end

#process_value(value) ⇒ 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.

Runs the ronin cert-grab command.

Parameters:

  • value (String)

    The HOST:PORT or URL value to process.

Since:

  • 2.0.0



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ronin/cli/commands/cert_grab.rb', line 80

def process_value(value)
  case value
  when /\A[^:]+:\d+\z/
    host, port = host_and_port(value)

    grab_cert(host,port)
  when /\Ahttps:/
    host, port = host_and_port_from_url(value)

    grab_cert(host,port)
  else
    print_error "invalid target: must be a HOST:PORT or a URL: #{value.inspect}"
    exit(1)
  end
end