Module: CMSScanner::Target::Server::Generic
- Included in:
- CMSScanner::Target
- Defined in:
- lib/cms_scanner/target/server/generic.rb
Overview
Generic Server methods
Instance Method Summary collapse
-
#directory_listing?(path = nil, params = {}) ⇒ Boolean
True if url(path) has the directory listing enabled, false otherwise.
-
#directory_listing_entries(path = nil, params = {}, selector = 'pre a', ignore = /parent directory/i) ⇒ Array<String>
The first level of directories/files listed, or an empty array if none.
-
#headers(path = nil, params = {}) ⇒ Hash
The headers.
-
#server(path = nil, params = {}) ⇒ Symbol
The detected remote server (:Apache, :IIS, :Nginx).
Instance Method Details
#directory_listing?(path = nil, params = {}) ⇒ Boolean
Returns true if url(path) has the directory listing enabled, false otherwise.
41 42 43 44 45 |
# File 'lib/cms_scanner/target/server/generic.rb', line 41 def directory_listing?(path = nil, params = {}) res = NS::Browser.get(url(path), params) res.code == 200 && res.body.include?('<h1>Index of') end |
#directory_listing_entries(path = nil, params = {}, selector = 'pre a', ignore = /parent directory/i) ⇒ Array<String>
Returns The first level of directories/files listed, or an empty array if none.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cms_scanner/target/server/generic.rb', line 54 def directory_listing_entries(path = nil, params = {}, selector = 'pre a', ignore = /parent directory/i) return [] unless directory_listing?(path, params) found = [] NS::Browser.get(url(path), params).html.css(selector).each do |node| entry = node.text.to_s next if entry&.match?(ignore) found << entry end found end |
#headers(path = nil, params = {}) ⇒ Hash
Returns The headers.
31 32 33 34 |
# File 'lib/cms_scanner/target/server/generic.rb', line 31 def headers(path = nil, params = {}) # The HEAD method might be rejected by some servers ... maybe switch to GET ? NS::Browser.head(url(path), params).headers end |
#server(path = nil, params = {}) ⇒ Symbol
Returns The detected remote server (:Apache, :IIS, :Nginx).
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cms_scanner/target/server/generic.rb', line 12 def server(path = nil, params = {}) headers = headers(path, params) return unless headers case headers[:server] when /\Aapache/i :Apache when /\AMicrosoft-IIS/i :IIS when /\Anginx/ :Nginx end end |