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.

ffautoregen.rb 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #
  2. # $Id: $
  3. # $Revision: $
  4. #
  5. module Msf
  6. ###
  7. #
  8. # This plugin reloads and re-executes a file-format exploit module once it has changed.
  9. #
  10. ###
  11. class Plugin::FFAutoRegen < Msf::Plugin
  12. ###
  13. #
  14. # This class implements a single edit command.
  15. #
  16. ###
  17. class FFAutoRegenCommandDispatcher
  18. include Msf::Ui::Console::CommandDispatcher
  19. #
  20. # The dispatcher's name.
  21. #
  22. def name
  23. "FFAutoRegen"
  24. end
  25. #
  26. # Returns the hash of commands supported by this dispatcher.
  27. #
  28. def commands
  29. {
  30. "ffautoregen" => "Automatically regenerate the document when the exploti source changes"
  31. }
  32. end
  33. #
  34. # This method handles the command.
  35. #
  36. def cmd_ffautoregen(*args)
  37. if (not active_module) or (not (path = active_module.file_path))
  38. print_line("Error: No active module selected")
  39. return nil
  40. end
  41. last = mt = File.stat(path).mtime
  42. loop {
  43. sleep(1)
  44. mt = File.stat(path).mtime
  45. if (mt != last)
  46. last = mt
  47. omod = active_module
  48. nmod = framework.modules.reload_module(active_module)
  49. if not nmod
  50. print_line("Error: Failed to reload module, trying again on next change...")
  51. next
  52. end
  53. active_module = nmod
  54. jobify = false
  55. payload = nmod.datastore['PAYLOAD']
  56. encoder = nmod.datastore['ENCODER']
  57. target = nmod.datastore['TARGET']
  58. nop = nmod.datastore['NOP']
  59. nmod.exploit_simple(
  60. 'Encoder' => encoder,
  61. 'Payload' => payload,
  62. 'Target' => target,
  63. 'Nop' => nop,
  64. # 'OptionStr' => opt_str,
  65. 'LocalInput' => driver.input,
  66. 'LocalOutput' => driver.output,
  67. 'RunAsJob' => jobify)
  68. end
  69. }
  70. end
  71. end
  72. def initialize(framework, opts)
  73. super
  74. # console dispatcher commands.
  75. add_console_dispatcher(FFAutoRegenCommandDispatcher)
  76. end
  77. def cleanup
  78. remove_console_dispatcher('FFAutoRegen')
  79. end
  80. def name
  81. "ffautoregen"
  82. end
  83. def desc
  84. "FileFormat AutoRegen Plugin"
  85. end
  86. protected
  87. end
  88. end