Skip to content

Commit b370dd0

Browse files
author
Brent Cook
committed
Fix CVE-2017-5229 - extapi Clipboard.parse_dump() Directory Traversal
1 parent d0f6d4e commit b370dd0

File tree

1 file changed

+13
-3
lines changed
  • lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi

1 file changed

+13
-3
lines changed

lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/clipboard.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ def cmd_clipboard_monitor_stop(*args)
373373
def download_file( dest_folder, source )
374374
stat = client.fs.file.stat( source )
375375
base = ::Rex::Post::Meterpreter::Extensions::Stdapi::Fs::File.basename( source )
376+
377+
# Basename ends up with a single name/folder. This is the only point where it
378+
# may be possible to do a dir trav up one folder. We need to check to make sure
379+
# that the basename doesn't result in a traversal
380+
if base == '..'
381+
return false
382+
end
383+
376384
dest = File.join( dest_folder, base )
377385

378386
if stat.directory?
@@ -386,6 +394,8 @@ def download_file( dest_folder, source )
386394
client.framework.events.on_session_download( client, src, dest ) if msf_loaded?
387395
}
388396
end
397+
398+
return true
389399
end
390400

391401
def parse_dump(dump, get_images, get_files, download_path)
@@ -406,15 +416,15 @@ def parse_dump(dump, get_images, get_files, download_path)
406416
print_line(v)
407417

408418
when 'Files'
409-
total = 0
410419
v.each do |f|
411420
print_line("Remote Path : #{f[:name]}")
412421
print_line("File size : #{f[:size]} bytes")
413422
if get_files
414-
download_file( loot_dir, f[:name] )
423+
unless download_file( loot_dir, f[:name] )
424+
print_error("Download of #{f:name]} failed.")
425+
end
415426
end
416427
print_line
417-
total += f[:size]
418428
end
419429

420430
when 'Image'

0 commit comments

Comments
 (0)