@@ -40,6 +40,12 @@ def initialize(info = {})
4040 OptString . new ( 'TARGETURI' , [ true , 'URI to test' , '/' ] )
4141 ] , Exploit ::Remote ::HttpClient
4242 )
43+
44+ register_advanced_options (
45+ [
46+ OptString . new ( 'STATUS_CODES_REGEX' , [ true , 'Ensure that canary pages and probe responses have status codes that match this regex' , '^4\d{3}$' ] )
47+ ] , self . class
48+ )
4349 end
4450
4551 def check_host ( _ip )
@@ -62,6 +68,10 @@ def run_host(ip)
6268 end
6369 end
6470
71+ def setup
72+ @status_codes_regex = Regexp . new ( datastore [ 'STATUS_CODES_REGEX' ] )
73+ end
74+
6575 # Fingerprints the provided HTTP response and returns
6676 # Exploit::CheckCode::Appears if it is a vulnerable version of RomPager,
6777 # otherwise returns the provided fall-back status.
@@ -86,9 +96,9 @@ def find_canary
8696 'headers' => headers
8797 )
8898 # in most cases, the canary URI will not exist and will return a 404, but
89- # if everything under TARGETURI is protected by auth, that may be fine
90- # too
91- return canary if res && ( res . code == 401 || res . code == 404 )
99+ # if everything under TARGETURI is protected by auth, a 401 may be OK too.
100+ # but, regardless, respect the configuration set for this module
101+ return canary if res && res . code . to_s =~ @status_codes_regex
92102 end
93103 nil
94104 end
@@ -107,7 +117,7 @@ def headers
107117 # overwrote RomPager's concept of the requested URI, indicating that it is
108118 # vulnerable.
109119 def test_misfortune
110- # find a usable canary URI (one that returns a 404 already)
120+ # find a usable canary URI (one that returns an acceptable status code already)
111121 unless ( canary_value = find_canary )
112122 vprint_error ( "#{ peer } Unable to find a suitable canary URI" )
113123 return Exploit ::CheckCode ::Unknown
@@ -129,7 +139,7 @@ def test_misfortune
129139 return Exploit ::CheckCode ::Unknown
130140 end
131141
132- unless res . code == 404
142+ unless res . code . to_s =~ @status_codes_regex
133143 vprint_status ( "#{ full_uri } unexpected HTTP code #{ res . code } response" )
134144 return check_response_fingerprint ( res , Exploit ::CheckCode ::Detected )
135145 end
0 commit comments