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.

multi_console_command.rb 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #
  7. # Meterpreter script for running multiple console commands on a meterpreter session
  8. # Provided by Carlos Perez at carlos_perez[at]darkoperator[dot]com
  9. # Verion: 0.1
  10. #
  11. ################## Variable Declarations ##################
  12. @client = client
  13. # Setting Arguments
  14. @@exec_opts = Rex::Parser::Arguments.new(
  15. "-h" => [ false,"Help menu." ],
  16. "-s" => [ false,"Hide commands output for work in background sessions"],
  17. "-c" => [ true,"Commands to execute. The command must be enclosed in double quotes and separated by a comma."],
  18. "-r" => [ true,"Text file with list of commands, one per line."]
  19. )
  20. commands = nil
  21. script = []
  22. help = false
  23. silence = false
  24. def usage
  25. print_line("Console Multi Command Execution Meterpreter Script ")
  26. print_line(@@exec_opts.usage)
  27. raise Rex::Script::Completed
  28. end
  29. @@exec_opts.parse(args) { |opt, idx, val|
  30. case opt
  31. when "-c"
  32. commands = val.split(",")
  33. when "-r"
  34. script = val
  35. if not ::File.exist?(script)
  36. raise "Command List File does not exists!"
  37. else
  38. commands = []
  39. ::File.open(script, "r").each_line do |line|
  40. commands << line.chomp
  41. end
  42. end
  43. when "-h"
  44. help = true
  45. when "-s"
  46. silence = true
  47. end
  48. }
  49. if args.length == 0 or help or commands.nil?
  50. usage
  51. end
  52. print_status("Running Command List ...")
  53. commands.each do |cmd|
  54. next if cmd.strip.length < 1
  55. next if cmd[0,1] == "#"
  56. begin
  57. print_status "\tRunning command #{cmd}"
  58. if silence
  59. @client.console.disable_output = true
  60. end
  61. @client.console.run_single(cmd)
  62. if silence
  63. @client.console.disable_output = false
  64. end
  65. rescue ::Exception => e
  66. print_status("Error Running Command #{cmd}: #{e.class} #{e}")
  67. end
  68. end