Skip to content

Msf::Exploit::Remote::SSH provides shared settings for Net::SSH connections. Its implementation is lib/msf/core/exploit/remote/ssh.rb. Options come through Msf::Exploit::Remote::SSH::Options.

include Msf::Exploit::Remote::SSH
# Or include only Options
include Msf::Exploit::Remote::SSH::Options
def ssh_client_defaults
# non_interactive, verify_host_key: :never, proxy factory, etc.
end
factory = ssh_socket_factory

A connection example:

opts = ssh_client_defaults.merge(
auth_methods: ['password', 'keyboard-interactive'],
port: datastore['RPORT'],
password: pass
)
ssh = Net::SSH.start(ip, user, opts)
ssh.exec!('id')

AuthBrute + Scanner + SSH Options. Record a successful login with create_credential_and_login and create a session if needed.

Existing example: modules/auxiliary/scanner/ssh/ssh_login.rb

After authentication, use exec! to send CmdStager fragments or a payload.

Existing example: modules/exploits/multi/ssh/sshexec.rb (execute_command uses ssh_socket.exec!)

Some targets support an interactive channel through a payload or session such as generic/ssh/interact. See SSH / WinRM Login for operational steps.

OptionMeaning
RPORTUsually 22
SSH_TIMEOUT / SSH_DEBUG / SSH_IDENTProvided by the Options mixin (names may vary by version)
KEY_PATH / PRIVATE_KEYPublic-key authentication (module-dependent)

Check the actual option names with show options and show advanced.