From d4f1314025aada88f40c9a4af70ecd673dc1ea1f Mon Sep 17 00:00:00 2001 From: Joshua Drake Date: Thu, 3 Dec 2009 21:52:59 +0000 Subject: [PATCH] fixed problem reading long lines git-svn-id: file:///home/svn/framework3/trunk@7687 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/exploit/ftp.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/msf/core/exploit/ftp.rb b/lib/msf/core/exploit/ftp.rb index 1ef611cd36..f81f51f6ff 100644 --- a/lib/msf/core/exploit/ftp.rb +++ b/lib/msf/core/exploit/ftp.rb @@ -129,17 +129,31 @@ module Exploit::Remote::Ftp end # - # This method reads a response up until the end of it as designated by FTP - # resposne continuation stuff + # This method reads an FTP response based on FTP continuation stuff # def recv_ftp_resp(nsock = self.sock) found_end = FALSE resp = "" left = "" while TRUE - got = nsock.get_once(-1, ftp_timeout) - return got if not got + data = nsock.get_once(-1, ftp_timeout) + return data if not data + got = left + data + left = "" + + # handle the end w/o newline case + enlidx = got.rindex(0x0a) + if enlidx != (got.length-1) + if not enlidx + left << got + next + else + left << got.slice!((enlidx+1)..got.length) + end + end + + # split into lines rarr = got.split(/\r?\n/) rarr.each do |ln| if not found_end @@ -154,7 +168,7 @@ module Exploit::Remote::Ftp end end if found_end - throw "ut oh!" if !left.empty? + throw "ut oh!" if left.length > 0 return resp end end