@@ -53,10 +53,15 @@ def initialize
5353 deregister_options ( 'FTPUSER' , 'FTPPASS' ) # Can use these, but should use 'username' and 'password'
5454 end
5555
56+ def sanitize_ftp_response ( str )
57+ Rex ::Text . to_hex_ascii ( str . to_s . gsub ( /^\d {3}[\s -]/ , '' ) . strip . gsub ( /\A \( |\) \z / , '' ) )
58+ end
59+
5660 def grab_report_banner
61+ vprint_status ( 'Getting FTP banner' )
62+
5763 begin
5864 connect ( true , false )
59- banner_version = banner . to_s . gsub ( /^\d {3}[\s -]/ , '' ) . strip . gsub ( /\A \( |\) \z / , '' )
6065 rescue ::Rex ::ConnectionRefused
6166 report_host ( host : rhost )
6267 return
@@ -78,7 +83,7 @@ def grab_report_banner
7883 port : rport ,
7984 proto : 'tcp' ,
8085 name : 'ftp' ,
81- info : banner_version
86+ info : @ banner_version
8287 )
8388
8489 # Raw FTP banner
@@ -92,10 +97,10 @@ def grab_report_banner
9297 end
9398
9499 def run_host ( ip )
95- print_status ( 'Starting FTP login sweep' )
96-
97100 grab_report_banner
98101
102+ print_status ( 'Starting FTP login sweep' )
103+
99104 cred_collection = build_credential_collection (
100105 username : datastore [ 'USERNAME' ] ,
101106 password : datastore [ 'PASSWORD' ] ,
@@ -138,10 +143,15 @@ def run_host(ip)
138143 workspace_id : myworkspace_id
139144 )
140145 if result . success?
146+ msg = "Login Successful: #{ result . credential } "
147+ msg << " (#{ access_level } )" if access_level
148+ print_good ( msg )
149+
141150 credential_data [ :private_type ] = :password
142151 credential_core = create_credential ( credential_data )
143152 credential_data [ :core ] = credential_core
144153
154+ vprint_status ( 'Checking read/write access' ) if datastore [ 'CHECK_ACCESS' ]
145155 access_level = test_ftp_access ( result . credential . public , result . credential . private ) if datastore [ 'CHECK_ACCESS' ]
146156 credential_data [ :access_level ] = access_level if access_level
147157
@@ -155,15 +165,12 @@ def run_host(ip)
155165 )
156166
157167 create_credential_login ( credential_data )
158-
159- msg = "Login Successful: #{ result . credential } "
160- msg << " (#{ access_level } )" if access_level
161- print_good ( msg )
162168 else
163- invalidate_login ( credential_data )
164169 proof = result . proof . to_s . strip
165170 proof_str = proof . empty? ? result . status . to_s : "#{ result . status } : #{ proof } "
166171 vprint_error ( "Login Failed: #{ result . credential } (#{ proof_str } )" )
172+
173+ invalidate_login ( credential_data )
167174 end
168175 end
169176 end
0 commit comments