Class: Ronin::Vulns::WebVuln
- Defined in:
- lib/ronin/vulns/web_vuln.rb,
lib/ronin/vulns/web_vuln/http_request.rb
Overview
The base class for all web vulnerabilities.
Direct Known Subclasses
CommandInjection, LFI, OpenRedirect, RFI, ReflectedXSS, SQLI, SSTI
Defined Under Namespace
Classes: HTTPRequest
Instance Attribute Summary collapse
-
#cookie ⇒ Hash{String => String}?
readonly
Additional
Cookie
header. -
#cookie_param ⇒ String, ...
readonly
The
Cookie:
param name to test or exploit. -
#form_data ⇒ Hash?
readonly
The form data that may be sent in the body of the request.
-
#form_param ⇒ String, ...
readonly
The form param name to test or exploit.
-
#header_name ⇒ String, ...
readonly
The HTTP Header name to test or exploit.
-
#headers ⇒ Hash{Symbol,String => String}?
readonly
Additional HTTP header names and values to add to the request.
-
#http ⇒ Ronin::Support::Network::HTTP?
readonly
An HTTP session to use for testing the URL.
-
#password ⇒ String?
readonly
The password to authenticate with.
-
#query_param ⇒ String, ...
readonly
The query param to test or exploit.
-
#query_params ⇒ Hash{String,Symbol => String}
readonly
The query params to send with each request.
-
#referer ⇒ String?
readonly
The optional HTTP
Referer
header to send with each request. -
#request_method ⇒ :copy, ...
readonly
The HTTP request method for each request.
-
#url ⇒ URI::HTTP
readonly
The URL to test or exploit.
-
#user ⇒ String?
readonly
The user to authenticate as.
-
#user_agent ⇒ String, ...
readonly
The optional HTTP
User-Agent
header to send with each request.
Class Method Summary collapse
-
.scan(url, query_params: nil, header_names: nil, cookie_params: nil, form_params: nil, http: nil, **kwargs) {|vuln| ... } ⇒ Array<WebVuln>
Scans the URL for web vulnerabilities.
-
.scan_cookie_params(url, cookie_params = nil, http: nil, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the URL and the
Cookie
header params. -
.scan_form_params(url, form_params = nil, http: nil, form_data: {}, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the URL and the form params.
-
.scan_headers(url, header_names, http: nil, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the URL and request headers.
-
.scan_query_params(url, query_params = nil, http: nil, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the query parameters of the URL.
-
.test(url, **kwargs) ⇒ WebVuln?
Tests the URL for a web vulnerability and returns the first found vulnerability.
-
.test_param(url, http:, **kwargs) ⇒ WebVuln?
private
Internal method that tests combinations of configurations for a specific query param, header name, cookie param, or form param.
Instance Method Summary collapse
-
#encode_payload(payload) ⇒ String
Place holder method for applying additional encoding to the payload.
-
#exploit(payload, **kwargs) ⇒ Net::HTTPResponse
Exploits the web vulnerability by sending an HTTP request.
-
#exploit_cookie(payload) ⇒ Hash{String,Symbol => String}, ...
The exploit cookie params with the payload injected.
-
#exploit_form_data(payload) ⇒ Hash{String,Symbol => String}?
The exploit form data with the payload injected.
-
#exploit_headers(payload) ⇒ Hash{String,Symbol => String}?
The exploit headers with the payload injected.
-
#exploit_query_params(payload) ⇒ Hash{String,Symbol => String}
The exploit query params with the payload injected.
-
#initialize(url, query_param: nil, header_name: nil, cookie_param: nil, form_param: nil, http: nil, request_method: :get, user: nil, password: nil, headers: nil, user_agent: nil, cookie: nil, form_data: nil, referer: nil) ⇒ WebVuln
constructor
Initializes the web vulnerability.
-
#original_value ⇒ String?
The original value of the vulnerable query param, header, cookie param, or form param.
-
#random_value(length = 4) ⇒ String
Returns a random value.
-
#request(**kwargs) ⇒ Net::HTTPResponse
Performs a normal request for the URL to test.
-
#to_curl(payload = 'PAYLOAD') ⇒ String
Converts the HTTP request to a
curl
command. -
#to_http(payload = 'PAYLOAD') ⇒ String
Converts the HTTP request to a raw HTTP request.
-
#to_s ⇒ String
Converts the web vulnerability into a String.
-
#vulnerable? ⇒ Boolean
abstract
Determines if the #url is vulnerable.
Methods inherited from Vuln
Constructor Details
#initialize(url, query_param: nil, header_name: nil, cookie_param: nil, form_param: nil, http: nil, request_method: :get, user: nil, password: nil, headers: nil, user_agent: nil, cookie: nil, form_data: nil, referer: nil) ⇒ WebVuln
Initializes the web vulnerability.
The HTTP request mehtod for each request.
The optional HTTP User-Agent
header to send with each request.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/ronin/vulns/web_vuln.rb', line 174 def initialize(url, query_param: nil, header_name: nil, cookie_param: nil, form_param: nil, # http keyword arguments http: nil, request_method: :get, user: nil, password: nil, headers: nil, user_agent: nil, cookie: nil, form_data: nil, referer: nil) @url = URI(url) @query_param = String(query_param) if query_param @header_name = String(header_name) if header_name @cookie_param = String() if @form_param = String(form_param) if form_param @http = http || Support::Network::HTTP.connect_uri(@url) @request_method = request_method @query_params = @url.query_params @user = user @password = password @headers = headers @user_agent = user_agent @cookie = @form_data = form_data @referer = referer end |
Instance Attribute Details
#cookie ⇒ Hash{String => String}? (readonly)
Additional Cookie
header. If a Hash
is given, it will be converted
to a String
using Ronin::Support::Network::HTTP::Cookie
.
108 109 110 |
# File 'lib/ronin/vulns/web_vuln.rb', line 108 def @cookie end |
#cookie_param ⇒ String, ... (readonly)
The Cookie:
param name to test or exploit.
52 53 54 |
# File 'lib/ronin/vulns/web_vuln.rb', line 52 def @cookie_param end |
#form_data ⇒ Hash? (readonly)
The form data that may be sent in the body of the request.
113 114 115 |
# File 'lib/ronin/vulns/web_vuln.rb', line 113 def form_data @form_data end |
#form_param ⇒ String, ... (readonly)
The form param name to test or exploit.
57 58 59 |
# File 'lib/ronin/vulns/web_vuln.rb', line 57 def form_param @form_param end |
#header_name ⇒ String, ... (readonly)
The HTTP Header name to test or exploit.
47 48 49 |
# File 'lib/ronin/vulns/web_vuln.rb', line 47 def header_name @header_name end |
#headers ⇒ Hash{Symbol,String => String}? (readonly)
Additional HTTP header names and values to add to the request.
89 90 91 |
# File 'lib/ronin/vulns/web_vuln.rb', line 89 def headers @headers end |
#http ⇒ Ronin::Support::Network::HTTP? (readonly)
An HTTP session to use for testing the URL.
62 63 64 |
# File 'lib/ronin/vulns/web_vuln.rb', line 62 def http @http end |
#password ⇒ String? (readonly)
The password to authenticate with.
84 85 86 |
# File 'lib/ronin/vulns/web_vuln.rb', line 84 def password @password end |
#query_param ⇒ String, ... (readonly)
The query param to test or exploit.
42 43 44 |
# File 'lib/ronin/vulns/web_vuln.rb', line 42 def query_param @query_param end |
#query_params ⇒ Hash{String,Symbol => String} (readonly)
The query params to send with each request.
74 75 76 |
# File 'lib/ronin/vulns/web_vuln.rb', line 74 def query_params @query_params end |
#referer ⇒ String? (readonly)
The optional HTTP Referer
header to send with each request.
118 119 120 |
# File 'lib/ronin/vulns/web_vuln.rb', line 118 def referer @referer end |
#request_method ⇒ :copy, ... (readonly)
The HTTP request method for each request.
69 70 71 |
# File 'lib/ronin/vulns/web_vuln.rb', line 69 def request_method @request_method end |
#url ⇒ URI::HTTP (readonly)
The URL to test or exploit.
37 38 39 |
# File 'lib/ronin/vulns/web_vuln.rb', line 37 def url @url end |
#user ⇒ String? (readonly)
The user to authenticate as.
79 80 81 |
# File 'lib/ronin/vulns/web_vuln.rb', line 79 def user @user end |
#user_agent ⇒ String, ... (readonly)
The optional HTTP User-Agent
header to send with each request.
102 103 104 |
# File 'lib/ronin/vulns/web_vuln.rb', line 102 def user_agent @user_agent end |
Class Method Details
.scan(url, query_params: nil, header_names: nil, cookie_params: nil, form_params: nil, http: nil, **kwargs) {|vuln| ... } ⇒ Array<WebVuln>
Scans the URL for web vulnerabilities.
The HTTP request mehtod for each request.
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'lib/ronin/vulns/web_vuln.rb', line 473 def self.scan(url, query_params: nil, header_names: nil, cookie_params: nil, form_params: nil, http: nil, **kwargs, &block) url = URI(url) http ||= Support::Network::HTTP.connect_uri(url) vulns = [] if (query_params.nil? && header_names.nil? && .nil? && form_params.nil?) vulns.concat(scan_query_params(url, http: http, **kwargs,&block)) else if query_params vulns.concat( case query_params when true scan_query_params(url, http: http, **kwargs,&block) else scan_query_params(url,query_params, http: http, **kwargs,&block) end ) end if header_names vulns.concat( scan_headers(url,header_names, http: http, **kwargs,&block) ) end if vulns.concat( case when true (url, http: http, **kwargs,&block) else (url,, http: http, **kwargs,&block) end ) end if form_params vulns.concat( case form_params when true scan_form_params(url, http: http, **kwargs,&block) else scan_form_params(url,form_params, http: http, **kwargs,&block) end ) end end return vulns end |
.scan_cookie_params(url, cookie_params = nil, http: nil, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the URL and the Cookie
header params.
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/ronin/vulns/web_vuln.rb', line 350 def self.(url,=nil, http: nil, **kwargs) url = URI(url) http ||= Support::Network::HTTP.connect_uri(url) unless = Set.new http.(url.request_uri).each do || .merge(.params.keys) end end vulns = [] .each do || if (vuln = test_param(url, cookie_param: , http: http, **kwargs)) yield vuln if block_given? vulns << vuln end end return vulns end |
.scan_form_params(url, form_params = nil, http: nil, form_data: {}, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the URL and the form params.
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/ronin/vulns/web_vuln.rb', line 396 def self.scan_form_params(url,form_params=nil, http: nil, form_data: {}, **kwargs) url = URI(url) http ||= Support::Network::HTTP.connect_uri(url) form_params ||= form_data.keys vulns = [] form_params.each do |form_param| if (vuln = test_param(url, form_param: form_param, form_data: form_data, http: http, **kwargs)) yield vuln if block_given? vulns << vuln end end return vulns end |
.scan_headers(url, header_names, http: nil, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the URL and request headers.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/ronin/vulns/web_vuln.rb', line 309 def self.scan_headers(url,header_names, http: nil, **kwargs) url = URI(url) http ||= Support::Network::HTTP.connect_uri(url) vulns = [] header_names.each do |header_name| if (vuln = test_param(url, header_name: header_name, http: http, **kwargs)) yield vuln if block_given? vulns << vuln end end return vulns end |
.scan_query_params(url, query_params = nil, http: nil, **kwargs) {|vuln| ... } ⇒ Array<Web>
Scans the query parameters of the URL.
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/ronin/vulns/web_vuln.rb', line 270 def self.scan_query_params(url,query_params=nil, http: nil, **kwargs) url = URI(url) http ||= Support::Network::HTTP.connect_uri(url) query_params ||= url.query_params.keys vulns = [] query_params.each do |param| if (vuln = test_param(url, query_param: param, http: http, **kwargs)) yield vuln if block_given? vulns << vuln end end return vulns end |
.test(url, **kwargs) ⇒ WebVuln?
Tests the URL for a web vulnerability and returns the first found vulnerability.
The HTTP request mehtod for each request.
585 586 587 588 589 590 591 |
# File 'lib/ronin/vulns/web_vuln.rb', line 585 def self.test(url,**kwargs) scan(url,**kwargs) do |vuln| return vuln end return nil end |
.test_param(url, http:, **kwargs) ⇒ WebVuln?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal method that tests combinations of configurations for a specific query param, header name, cookie param, or form param.
241 242 243 244 245 |
# File 'lib/ronin/vulns/web_vuln.rb', line 241 def self.test_param(url, http: , **kwargs) vuln = new(url, http: http, **kwargs) return vuln if vuln.vulnerable? end |
Instance Method Details
#encode_payload(payload) ⇒ String
Place holder method for applying additional encoding to the payload.
713 714 715 |
# File 'lib/ronin/vulns/web_vuln.rb', line 713 def encode_payload(payload) payload.to_s end |
#exploit(payload, **kwargs) ⇒ Net::HTTPResponse
Exploits the web vulnerability by sending an HTTP request.
729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/ronin/vulns/web_vuln.rb', line 729 def exploit(payload,**kwargs) payload = encode_payload(payload) request( query_params: exploit_query_params(payload), cookie: (payload), headers: exploit_headers(payload), form_data: exploit_form_data(payload), **kwargs ) end |
#exploit_cookie(payload) ⇒ Hash{String,Symbol => String}, ...
The exploit cookie params with the payload injected.
670 671 672 673 674 675 676 677 678 679 680 |
# File 'lib/ronin/vulns/web_vuln.rb', line 670 def (payload) if @cookie_param if @cookie @cookie.merge(@cookie_param.to_s => payload) else {@cookie_param.to_s => payload} end else @cookie end end |
#exploit_form_data(payload) ⇒ Hash{String,Symbol => String}?
The exploit form data with the payload injected.
692 693 694 695 696 697 698 699 700 701 702 |
# File 'lib/ronin/vulns/web_vuln.rb', line 692 def exploit_form_data(payload) if @form_param if @form_data @form_data.merge(@form_param.to_s => payload) else {@form_param.to_s => payload} end else @form_data end end |
#exploit_headers(payload) ⇒ Hash{String,Symbol => String}?
The exploit headers with the payload injected.
648 649 650 651 652 653 654 655 656 657 658 |
# File 'lib/ronin/vulns/web_vuln.rb', line 648 def exploit_headers(payload) if @header_name if @headers @headers.merge(@header_name.to_s => payload) else {@header_name.to_s => payload} end else @headers end end |
#exploit_query_params(payload) ⇒ Hash{String,Symbol => String}
The exploit query params with the payload injected.
626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/ronin/vulns/web_vuln.rb', line 626 def exploit_query_params(payload) if @query_param if @query_params @query_params.merge(@query_param.to_s => payload) else {@query_param.to_s => payload} end else @query_params end end |
#original_value ⇒ String?
The original value of the vulnerable query param, header, cookie param, or form param.
747 748 749 750 751 752 753 754 755 756 757 |
# File 'lib/ronin/vulns/web_vuln.rb', line 747 def original_value if @query_param @url.query_params[@query_param] elsif @header_name @headers[@header_name] if @headers elsif @cookie_param @cookie[@cookie_param] if @cookie elsif @form_param @form_data[@form_param] if @form_data end end |
#random_value(length = 4) ⇒ String
Returns a random value.
768 769 770 |
# File 'lib/ronin/vulns/web_vuln.rb', line 768 def random_value(length=4) Chars::ALPHA.random_string(length) end |
#request(**kwargs) ⇒ Net::HTTPResponse
Performs a normal request for the URL to test.
602 603 604 605 606 607 608 609 610 611 612 613 614 |
# File 'lib/ronin/vulns/web_vuln.rb', line 602 def request(**kwargs) @http.request( @request_method, @url.path, user: @user, password: @password, query_params: @query_params, user_agent: @user_agent, cookie: @cookie, referer: @referer, headers: @headers, form_data: @form_data, **kwargs ) end |
#to_curl(payload = 'PAYLOAD') ⇒ String
Converts the HTTP request to a curl
command.
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 |
# File 'lib/ronin/vulns/web_vuln.rb', line 802 def to_curl(payload='PAYLOAD') payload = encode_payload(payload) HTTPRequest.new( @url, request_method: @request_method, user: @user, password: @password, user_agent: @user_agent, referer: @referer, query_params: exploit_query_params(payload), cookie: (payload), headers: exploit_headers(payload), form_data: exploit_form_data(payload) ).to_curl end |
#to_http(payload = 'PAYLOAD') ⇒ String
Converts the HTTP request to a raw HTTP request.
826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
# File 'lib/ronin/vulns/web_vuln.rb', line 826 def to_http(payload='PAYLOAD') payload = encode_payload(payload) HTTPRequest.new( @url, request_method: @request_method, user: @user, password: @password, user_agent: @user_agent, referer: @referer, query_params: exploit_query_params(payload), cookie: (payload), headers: exploit_headers(payload), form_data: exploit_form_data(payload) ).to_http end |
#to_s ⇒ String
Converts the web vulnerability into a String.
790 791 792 |
# File 'lib/ronin/vulns/web_vuln.rb', line 790 def to_s @url.to_s end |
#vulnerable? ⇒ Boolean
Determines if the #url is vulnerable.
780 781 782 |
# File 'lib/ronin/vulns/web_vuln.rb', line 780 def vulnerable? raise(NotImplementedError,"#{self.inspect} did not implement ##{__method__}") end |