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.

window.rb 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # -*- coding: binary -*-
  2. require 'rex/post/meterpreter'
  3. module Rex
  4. module Post
  5. module Meterpreter
  6. module Ui
  7. ###
  8. #
  9. # Extended API window management user interface.
  10. #
  11. ###
  12. class Console::CommandDispatcher::Extapi::Window
  13. Klass = Console::CommandDispatcher::Extapi::Window
  14. include Console::CommandDispatcher
  15. #
  16. # List of supported commands.
  17. #
  18. def commands
  19. {
  20. "window_enum" => "Enumerate all current open windows"
  21. }
  22. end
  23. #
  24. # Name for this dispatcher
  25. #
  26. def name
  27. "Extapi: Window Management"
  28. end
  29. #
  30. # Options for the window_enum command.
  31. #
  32. @@window_enum_opts = Rex::Parser::Arguments.new(
  33. "-h" => [ false, "Help banner" ],
  34. "-p" => [ true, "Parent window handle, used to enumerate child windows" ],
  35. "-u" => [ false, "Include unknown/untitled windows in the result set" ]
  36. )
  37. def window_enum_usage
  38. print(
  39. "\nUsage: window_enum [-h] [-p parent_window] [-u]\n\n" +
  40. "Enumerate the windows on the target.\n\n" +
  41. "Enumeration returns the Process ID and Window Handle for each window\n" +
  42. "found. The Window Handle can be used for further calls to window_enum\n" +
  43. "or the railgun API.\n" +
  44. @@window_enum_opts.usage +
  45. "Note: Not all windows can be enumerated. An attempt to enumerate\n" +
  46. " the children of such a window will result in a failure with the\n"+
  47. " message \"Operation failed: The parameter is incorrect.\"\n\n")
  48. end
  49. #
  50. # Enumerate top-level windows.
  51. #
  52. def cmd_window_enum(*args)
  53. parent_window = nil
  54. include_unknown = false
  55. @@window_enum_opts.parse(args) { |opt, idx, val|
  56. case opt
  57. when "-u"
  58. include_unknown = true
  59. when "-p"
  60. parent_window = val.to_i
  61. if parent_window == 0
  62. window_enum_usage
  63. return true
  64. end
  65. when "-h"
  66. window_enum_usage
  67. return true
  68. end
  69. }
  70. windows = client.extapi.window.enumerate(include_unknown, parent_window)
  71. header = parent_window ? "Child windows of #{parent_window}" : "Top-level windows"
  72. table = Rex::Text::Table.new(
  73. 'Header' => header,
  74. 'Indent' => 0,
  75. 'SortIndex' => 0,
  76. 'Columns' => [
  77. 'PID', 'Handle', 'Title'
  78. ]
  79. )
  80. windows.each { |w|
  81. table << [w[:pid], w[:handle], w[:title]]
  82. }
  83. print_line
  84. print_line(table.to_s)
  85. if parent_window.nil?
  86. print_line("Total top-level Windows: #{windows.length}")
  87. else
  88. print_line("Total child Windows: #{windows.length}")
  89. end
  90. print_line
  91. return true
  92. end
  93. end
  94. end
  95. end
  96. end
  97. end