Class: Metasploit::Credential::SSHKey

Inherits:
Private
  • Object
show all
Defined in:
app/models/metasploit/credential/ssh_key.rb

Overview

A private SSH key file.

Instance Attribute Summary collapse

Attributes inherited from Private

#cores, #created_at, #id, #type, #updated_at

Instance Method Summary collapse

Instance Attribute Details

#dataString

A private SSH key file’s content including the ‘—–BEGIN <type> PRIVATE KEY—–` header and `—–END <type> PRIVATE KEY—–` footer with everything in between.

Returns:

  • (String)


# File 'app/models/metasploit/credential/ssh_key.rb', line 9

Instance Method Details

#encrypted?false, true

Whether the key data in #data is encrypted. Encrypted keys cannot be saved and should be decrypted before saving in a Metasploit::Credential::SSHKey.

Returns:

  • (false)

    if #data does not contain ‘’ENCRYPTED’‘ or #data is `nil`.

  • (true)

    if #data contains ‘’ENCRYPTED’‘.



44
45
46
47
48
49
50
51
# File 'app/models/metasploit/credential/ssh_key.rb', line 44

def encrypted?
  if data
    # see https://github.com/net-ssh/net-ssh/blob/1b5db680fee66e1d846d0396eb1a68d3fabdc3de/lib/net/ssh/key_factory.rb#L72
    data.match(/ENCRYPTED/)
  else
    false
  end
end

#private?false, true

Whether the key data in #data is a private key. Only private keys are supported as public keys cannot be used as Public#data.

Returns:

  • (false)

    if #data does not contain ‘’—–BEGIN <type> PRIVATE KEY—–‘` or #data is `nil`.

  • (true)

    if #data contains ‘’—–BEGIN <type> PRIVATE KEY—–‘`.



58
59
60
61
62
63
64
65
# File 'app/models/metasploit/credential/ssh_key.rb', line 58

def private?
  if data
    # @see https://github.com/net-ssh/net-ssh/blob/1b5db680fee66e1d846d0396eb1a68d3fabdc3de/lib/net/ssh/key_factory.rb#L56-L69
    data.match(/-----BEGIN (.+) PRIVATE KEY-----/)
  else
    false
  end
end

#to_sString

The key data‘s fingerprint, suitable for displaying to the user.

Returns:

  • (String)


71
72
73
# File 'app/models/metasploit/credential/ssh_key.rb', line 71

def to_s
  data ? openssl_pkey_pkey.fingerprint : ''
end