metasploit-framework/lib/msf/http/wordpress/users.rb

58 lines
1.6 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2013-08-22 15:33:35 +00:00
module Msf::HTTP::Wordpress::Users
2013-09-05 19:11:03 +00:00
# Checks if the given user exists
#
# @param user [String] Username
# @return [Boolean] true if the user exists
def wordpress_user_exists?(user)
res = send_request_cgi({
'method' => 'POST',
'uri' => wordpress_url_login,
'vars_post' => wordpress_helper_login_post_data(user, Rex::Text.rand_text_alpha(6))
})
2013-09-05 19:11:03 +00:00
return true if res and res.code == 200 and
(res.body.to_s =~ /Incorrect password/ or
res.body.to_s =~ /document\.getElementById\('user_pass'\)/)
2013-08-23 20:14:58 +00:00
2013-09-05 19:11:03 +00:00
return false
end
2013-09-05 19:11:03 +00:00
# Checks if the given userid exists
#
# @param user_id [Integer] user_id
# @return [String,nil] the Username if it exists, nil otherwise
def wordpress_userid_exists?(user_id)
url = wordpress_url_author(user_id)
res = send_request_cgi({
'method' => 'GET',
'uri' => url
})
2013-09-05 19:11:03 +00:00
if res and res.code == 301
uri = wordpress_helper_parse_location_header(res)
return nil unless uri
# try to extract username from location
if uri.to_s =~ /\/author\/([^\/\b]+)\/?/i
return $1
end
uri = "#{uri.path}?#{uri.query}"
res = send_request_cgi({
'method' => 'GET',
'uri' => uri
})
end
2013-09-05 19:11:03 +00:00
if res.nil?
print_error("#{peer} - Error getting response.")
return nil
elsif res.code == 200 and
(res.body =~ /href="http[s]*:\/\/.*\/\?*author.+title="([[:print:]]+)" /i or
res.body =~ /<body class="archive author author-(?:[^\s]+) author-(?:\d+)/i)
return $1
end
end
end