Skip to content

Commit cb3966d

Browse files
committed
reduce the nesting in read_file by 2 levels
1 parent 4ca2ce3 commit cb3966d

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

modules/auxiliary/gather/progress_moveit_sftp_fileread_cve_2024_5806.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -161,35 +161,35 @@ def run
161161

162162
def read_file(sftp, file_path)
163163
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?
192165
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
193193
end
194194
ensure
195195
sftp.close!(open_response[:handle]) if open_response.ok?

0 commit comments

Comments
 (0)