Skip to content
This repository was archived by the owner on Oct 22, 2020. It is now read-only.

Commit 8f890da

Browse files
committed
Add StoredXss mixin
1 parent e4c85be commit 8f890da

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

lib/wpxf/core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
require 'wpxf/wordpress/xss'
3030
require 'wpxf/wordpress/reflected_xss'
3131
require 'wpxf/wordpress/staged_reflected_xss'
32+
require 'wpxf/wordpress/stored_xss'
3233
require 'wpxf/wordpress/shell_upload'
3334
require 'wpxf/wordpress/file_download'
3435

lib/wpxf/wordpress/stored_xss.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Provides reusable functionality for stored XSS modules.
2+
module Wpxf::WordPress::StoredXss
3+
include Wpxf::WordPress::Xss
4+
5+
# Initialize a new instance of {StoredXss}.
6+
def initialize
7+
super
8+
@success = false
9+
@info[:desc] = 'This module stores a script in the target system that '\
10+
'will execute when an admin user views the vulnerable page, '\
11+
'which in turn, will create a new admin user to upload '\
12+
'and execute the selected payload in the context of the '\
13+
'web server.'
14+
end
15+
16+
# @return [String] the URL or name of the page an admin user must view to execute the script.
17+
def vulnerable_page
18+
'a vulnerable page'
19+
end
20+
21+
# Abstract method which must be implemented to store the XSS include script.
22+
# @return [Wpxf::Net::HttpResponse] the HTTP response to the request to store the script.
23+
def store_script
24+
raise 'Required method "store_script" has not been implemented'
25+
end
26+
27+
# Call #store_script and validate the response.
28+
# @return [Boolea] return true if the script was successfully stored.
29+
def store_script_and_validate
30+
res = store_script
31+
32+
if res.nil?
33+
emit_error 'No response from the target'
34+
return false
35+
end
36+
37+
return true if res.code == 200
38+
39+
emit_error "Server responded with code #{res.code}"
40+
false
41+
end
42+
43+
# Run the module.
44+
# @return [Boolean] true if successful.
45+
def run
46+
return false unless super
47+
48+
emit_info 'Storing script...'
49+
return false unless store_script_and_validate
50+
51+
emit_success "Script stored and will be executed when a user views #{vulnerable_page}"
52+
start_http_server
53+
54+
xss_shell_success
55+
end
56+
end

spec/wordpress/stored_xss_spec.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
require_relative '../spec_helper'
2+
3+
describe Wpxf::WordPress::StoredXss do
4+
let(:subject) do
5+
Class.new(Wpxf::Module) do
6+
include Wpxf::WordPress::StoredXss
7+
end.new
8+
end
9+
10+
describe '#new' do
11+
it 'sets up the desc key of the info store' do
12+
desc = 'This module stores a script in the target system that '\
13+
'will execute when an admin user views the vulnerable page, '\
14+
'which in turn, will create a new admin user to upload '\
15+
'and execute the selected payload in the context of the '\
16+
'web server.'
17+
18+
expect(subject.module_desc).to eq desc
19+
end
20+
end
21+
22+
describe '#run' do
23+
it 'starts a HTTP server if the module is configured properly' do
24+
invoked = false
25+
allow(subject).to receive(:start_http_server) do
26+
invoked = true
27+
end
28+
29+
allow(subject).to receive(:puts).and_return nil
30+
allow(subject).to receive(:check_wordpress_and_online).and_return true
31+
allow(subject).to receive(:store_script_and_validate).and_return true
32+
subject.run
33+
expect(invoked).to be true
34+
end
35+
end
36+
37+
describe '#store_script' do
38+
it 'raises an error if the store_script method isn\'t implemented' do
39+
expect { subject.store_script }.to raise_error(
40+
'Required method "store_script" has not been implemented'
41+
)
42+
end
43+
end
44+
45+
describe '#store_script_and_validate' do
46+
it 'returns false if the response has a code !== 200' do
47+
typhoeus_res = Typhoeus::Response.new
48+
allow(typhoeus_res).to receive(:code).and_return(404)
49+
allow(subject).to receive(:store_script).and_return(Wpxf::Net::HttpResponse.new(typhoeus_res))
50+
expect(subject.store_script_and_validate).to be false
51+
end
52+
53+
it 'returns false if the response is nil' do
54+
allow(subject).to receive(:store_script).and_return(nil)
55+
expect(subject.store_script_and_validate).to be false
56+
end
57+
58+
it 'returns true if the response code is 200' do
59+
typhoeus_res = Typhoeus::Response.new
60+
allow(typhoeus_res).to receive(:code).and_return(200)
61+
allow(subject).to receive(:store_script).and_return(Wpxf::Net::HttpResponse.new(typhoeus_res))
62+
expect(subject.store_script_and_validate).to be true
63+
end
64+
end
65+
end

0 commit comments

Comments
 (0)