Statistics
| Branch: | Tag: | Revision:

root / modules / auxiliary / admin / http / tomcat_administration.rb @ master

History | View | Annotate | Download (3.4 kB)

1
##
2
# $Id$
3
##
4

    
5
##
6
# This file is part of the Metasploit Framework and may be subject to
7
# redistribution and commercial restrictions. Please see the Metasploit
8
# Framework web site for more information on licensing and terms of use.
9
# http://metasploit.com/framework/
10
##
11

    
12
require 'msf/core'
13

    
14
class Metasploit3 < Msf::Auxiliary
15

    
16
        include Msf::Exploit::Remote::HttpClient
17
        include Msf::Auxiliary::WMAPScanServer
18
        include Msf::Auxiliary::Scanner
19

    
20
        def initialize
21
                super(
22
                        'Name'        => 'Tomcat Administration Tool Default Access',
23
                        'Version'     => '$Revision$',
24
                        'Description' => 'Detect the Tomcat administration interface.',
25
                        'References'  =>
26
                                [
27
                                        ['URL', 'http://tomcat.apache.org/'],
28
                                ],
29
                        'Author'      => 'Matteo Cantoni <goony[at]nothink.org>',
30
                        'License'     => MSF_LICENSE
31
                )
32

    
33
                register_options(
34
                        [
35
                                Opt::RPORT(8180),
36
                                OptString.new('TOMCAT_USER', [ false, 'The username to authenticate as', '']),
37
                                OptString.new('TOMCAT_PASS', [ false, 'The password for the specified username', '']),
38
                        ], self.class)
39
        end
40

    
41
        def run_host(ip)
42

    
43
                begin
44
                        res = send_request_raw(
45
                                {
46
                                        'method'  => 'GET',
47
                                        'uri'     => '/',
48
                                }, 25)
49

    
50
                        http_fingerprint({ :response => res })
51

    
52
                        if (res and res.code == 200)
53

    
54
                                ver = ""
55

    
56
                                if res.body.match(/<title>Apache Tomcat\/(.*)<\/title>/)
57
                                        ver = "Apache Tomcat/" + $1
58
                                end
59

    
60
                                user = datastore['TOMCAT_USER'].to_s
61
                                pass = datastore['TOMCAT_PASS'].to_s
62

    
63
                                if user.length == 0
64
                                        default_usernames = ['admin','manager','role1','root','tomcat']
65
                                else
66
                                        default_usernames = [user]
67
                                end
68

    
69
                                if pass.length == 0
70
                                        default_passwords = ['admin','manager','role1','root','tomcat']
71
                                else
72
                                        default_passwords = [pass]
73
                                end
74

    
75
                                default_usernames.each do |username|
76
                                        default_passwords.each do |password|
77

    
78
                                                res = send_request_raw({
79
                                                        'method'  => 'GET',
80
                                                        'uri'     => '/admin/',
81
                                                }, 25)
82

    
83
                                                if (res and res.code == 200)
84

    
85
                                                        if (res.headers['Set-Cookie'] and res.headers['Set-Cookie'].match(/JSESSIONID=(.*);(.*)/i))
86

    
87
                                                                jsessionid = $1
88

    
89
                                                                post_data = "j_username=#{username}&j_password=#{password}"
90

    
91
                                                                res = send_request_cgi({
92
                                                                        'uri'          => '/admin/j_security_check',
93
                                                                        'method'       => 'POST',
94
                                                                        'content-type' => 'application/x-www-form-urlencoded',
95
                                                                        'cookie'       => "JSESSIONID=#{jsessionid}",
96
                                                                        'data'         => post_data,
97
                                                                }, 25)
98

    
99
                                                                if (res.code == 302)
100

    
101
                                                                        res = send_request_cgi({
102
                                                                                'uri'     => "/admin/",
103
                                                                                'method'  => 'GET',
104
                                                                                'cookie'  => "JSESSIONID=#{jsessionid}",
105
                                                                        }, 25)
106

    
107
                                                                        if (res.code == 302)
108

    
109
                                                                                res = send_request_cgi({
110
                                                                                        'uri'     => "/admin/frameset.jsp",
111
                                                                                        'method'  => 'GET',
112
                                                                                        'cookie'  => "JSESSIONID=#{jsessionid}",
113
                                                                                }, 25)
114

    
115
                                                                                if (res.code == 200)
116
                                                                                        print_status("http://#{target_host}:#{rport}/admin [#{res.headers['Server']}] [#{ver}] [Tomcat Server Administration] [#{username}/#{password}]")
117
                                                                                end
118

    
119
                                                                                # LogOut
120
                                                                                res = send_request_cgi({
121
                                                                                        'uri'          => '/admin/logOut.do',
122
                                                                                        'method'       => 'GET',
123
                                                                                        'cookie'       => "JSESSIONID=#{jsessionid}",
124
                                                                                }, 25)
125
                                                                        end
126
                                                                end
127
                                                        end
128
                                                end
129
                                        end
130
                                end
131
                        end
132

    
133
                        rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
134
                        rescue ::Timeout::Error, ::Errno::EPIPE
135
                end
136
        end
137
end