Skip to content

Commit a6479a7

Browse files
committed
Implented feedback from @jhart-r7
1 parent baff003 commit a6479a7

File tree

9 files changed

+18
-28
lines changed

9 files changed

+18
-28
lines changed

lib/msf/http/wordpress.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: UTF-8
21
# -*- coding: binary -*-
32

43
# This module provides a way of interacting with wordpress installations

lib/msf/http/wordpress/base.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: UTF-8
21
# -*- coding: binary -*-
32

43
module Msf::HTTP::Wordpress::Base
@@ -10,16 +9,15 @@ def wordpress_and_online?
109
'method' => 'GET',
1110
'uri' => normalize_uri(target_uri.path)
1211
)
13-
return res if res &&
14-
res.code == 200 &&
15-
(
16-
res.body =~ /["'][^"']*\/#{Regexp.escape(wp_content_dir)}\/[^"']*["']/i ||
17-
res.body =~ /<link rel=["']wlwmanifest["'].*href=["'].*\/wp-includes\/wlwmanifest\.xml["'] \/>/i ||
18-
res.body =~ /<link rel=["']pingback["'].*href=["'].*\/xmlrpc\.php["'](?: \/)*>/i
19-
)
12+
wordpress_detect_regexes = [
13+
/["'][^"']*\/#{Regexp.escape(wp_content_dir)}\/[^"']*["']/i,
14+
/<link rel=["']wlwmanifest["'].*href=["'].*\/wp-includes\/wlwmanifest\.xml["'] \/>/i,
15+
/<link rel=["']pingback["'].*href=["'].*\/xmlrpc\.php["'](?: \/)*>/i
16+
]
17+
return res if res && res.code == 200 && res.body && wordpress_detect_regexes.any? { |r| res.body =~ r }
2018
return nil
21-
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout
22-
print_error("#{peer} - Error connecting to #{target_uri}")
19+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout => e
20+
print_error("#{peer} - Error connecting to #{target_uri}: #{e}")
2321
return nil
2422
end
2523
end

lib/msf/http/wordpress/helpers.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def wordpress_helper_post_comment(comment, comment_post_id, login_cookie, author
4949
options.merge!({'vars_post' => vars_post})
5050
options.merge!({'cookie' => login_cookie}) if login_cookie
5151
res = send_request_cgi(options)
52-
if res and (res.code == 301 or res.code == 302) and res.headers['Location']
52+
if res and res.redirect? and res.redirection
5353
return wordpress_helper_parse_location_header(res)
5454
else
5555
message = "#{peer} - Post comment failed."
@@ -101,7 +101,7 @@ def wordpress_helper_check_post_id(uri, comments_enabled=false, login_cookie=nil
101101
else
102102
return res.body
103103
end
104-
elsif res and (res.code == 301 or res.code == 302) and res.headers['Location']
104+
elsif res && res.redirect? && res.redirection
105105
path = wordpress_helper_parse_location_header(res)
106106
return wordpress_helper_check_post_id(path, comments_enabled, login_cookie)
107107
end
@@ -113,9 +113,9 @@ def wordpress_helper_check_post_id(uri, comments_enabled=false, login_cookie=nil
113113
# @param res [Rex::Proto::Http::Response] The HTTP response
114114
# @return [String,nil] the path and query, nil on error
115115
def wordpress_helper_parse_location_header(res)
116-
return nil unless res and (res.code == 301 or res.code == 302) and res.headers['Location']
116+
return nil unless res && res.redirect? && res.redirection
117117

118-
location = res.headers['Location']
118+
location = res.redirection
119119
path_from_uri(location)
120120
end
121121

lib/msf/http/wordpress/login.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: UTF-8
21
# -*- coding: binary -*-
32

43
module Msf::HTTP::Wordpress::Login
@@ -15,7 +14,7 @@ def wordpress_login(user, pass)
1514
'vars_post' => wordpress_helper_login_post_data(user, pass, redirect)
1615
)
1716

18-
if res && (res.code == 301 || res.code == 302) && res.headers['Location'] == redirect
17+
if res && res.redirect? && res.redirection == redirect
1918
cookies = res.get_cookies
2019
# Check if a valid wordpress cookie is returned
2120
return cookies if

lib/msf/http/wordpress/posts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def wordpress_get_all_blog_posts_via_feed(max_redirects = 10)
112112
count = max_redirects
113113

114114
# Follow redirects
115-
while (res.code == 301 || res.code == 302) and res.headers['Location'] and count != 0
115+
while res.redirect? && res.redirection && count != 0
116116
path = wordpress_helper_parse_location_header(res)
117117
return nil unless path
118118

lib/msf/http/wordpress/users.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def wordpress_userid_exists?(user_id)
3333
'uri' => url
3434
})
3535

36-
if res and res.code == 301
36+
if res and res.redirect?
3737
uri = wordpress_helper_parse_location_header(res)
3838
return nil unless uri
3939
# try to extract username from location

lib/msf/http/wordpress/version.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# encoding: UTF-8
21
# -*- coding: binary -*-
32

43
module Msf::HTTP::Wordpress::Version
@@ -88,7 +87,7 @@ def check_version_from_readme(type, name, fixed_version, vuln_introduced_version
8887
when :theme
8988
folder = 'themes'
9089
else
91-
fail("Unknown type #{type}")
90+
fail("Unknown readme type #{type}")
9291
end
9392

9493
readme_url = normalize_uri(target_uri.path, wp_content_dir, folder, name, 'readme.txt')
@@ -121,7 +120,6 @@ def check_version_from_readme(type, name, fixed_version, vuln_introduced_version
121120
# Not in range, nut vulnerable
122121
return Msf::Exploit::CheckCode::Safe
123122
end
124-
return
125123
# version newer than fixed version
126124
else
127125
return Msf::Exploit::CheckCode::Safe

modules/exploits/unix/webapp/wp_wptouch_file_upload.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: UTF-8
2-
31
##
42
# This module requires Metasploit: http//metasploit.com/download
53
# Current source: https://github.com/rapid7/metasploit-framework
@@ -72,8 +70,8 @@ def get_nonce(cookie)
7270
)
7371

7472
# forward to profile.php or other page?
75-
if res && res.code.to_s =~ /30[0-9]/ && res.headers['Location']
76-
location = res.headers['Location']
73+
if res && res.redirect? && res.redirection
74+
location = res.redirection
7775
print_status("#{peer} - Following redirect to #{location}")
7876
res = send_request_cgi(
7977
'uri' => location,

modules/exploits/unix/webapp/wp_wysija_newsletters_upload.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# encoding: UTF-8
2-
31
##
42
# This module requires Metasploit: http//metasploit.com/download
53
# Current source: https://github.com/rapid7/metasploit-framework

0 commit comments

Comments
 (0)