session_tagger.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #
  2. # $Id$
  3. # $Revision$
  4. #
  5. module Msf
  6. ###
  7. #
  8. # This class hooks all session creation events and allows automated interaction
  9. # This is only an example of what you can do with plugins
  10. #
  11. ###
  12. class Plugin::SessionTagger < Msf::Plugin
  13. include Msf::SessionEvent
  14. def on_session_open(session)
  15. print_status("Hooked session #{session.sid} / #{session.session_host}")
  16. # XXX: Determine what type of session this is before writing to it
  17. if session.interactive?
  18. session.shell_write("MKDIR C:\\TaggedBy#{ENV['USER']}\n")
  19. session.shell_write("mkdir /tmp/TaggedBy#{ENV['USER']}\n")
  20. end
  21. #
  22. # Read output with session.shell_read()
  23. #
  24. end
  25. def on_session_close(session, _reason = '')
  26. print_status("Hooked session #{session.sid} is shutting down")
  27. end
  28. def initialize(framework, opts)
  29. super
  30. self.framework.events.add_session_subscriber(self)
  31. end
  32. def cleanup
  33. framework.events.remove_session_subscriber(self)
  34. end
  35. def name
  36. 'session_tagger'
  37. end
  38. def desc
  39. 'Automatically interacts with new sessions to create a new remote TaggedByUser file'
  40. end
  41. end
  42. end