Class: WebSite

Inherits:
Object
  • Object
show all
Includes:
InterestingHeaders, RobotsTxt
Defined in:
lib/wpscan/web_site.rb,
lib/wpscan/web_site/robots_txt.rb,
lib/wpscan/web_site/interesting_headers.rb

Direct Known Subclasses

WpTarget

Defined Under Namespace

Modules: InterestingHeaders, RobotsTxt

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from InterestingHeaders

#interesting_headers, known_headers

Methods included from RobotsTxt

#has_robots?, known_dirs, #parse_robots_txt, #robots_url

Constructor Details

- (WebSite) initialize(site_url)

A new instance of WebSite



12
13
14
# File 'lib/wpscan/web_site.rb', line 12

def initialize(site_url)
  self.url = site_url
end

Instance Attribute Details

- (Object) uri (readonly)

Returns the value of attribute uri



10
11
12
# File 'lib/wpscan/web_site.rb', line 10

def uri
  @uri
end

Class Method Details

+ (Boolean) has_log?(log_url, pattern)

Only the first 700 bytes are checked to avoid the download of the whole file which can be very huge (like 2 Go)

Parameters:

  • log_url (String)
  • pattern (RegEx)

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/wpscan/web_site.rb', line 109

def self.has_log?(log_url, pattern)
  log_body = Browser.get(log_url, headers: {'range' => 'bytes=0-700'}).body
  log_body[pattern] ? true : false
end

+ (String) page_hash(page)

Compute the MD5 of the page Comments are deleted from the page to avoid cache generation details

Parameters:

Returns:

  • (String)

    The MD5 hash of the page



73
74
75
76
77
# File 'lib/wpscan/web_site.rb', line 73

def self.page_hash(page)
  page = Browser.get(page) unless page.is_a?(Typhoeus::Response)

  Digest::MD5.hexdigest(page.body.gsub(/<!--.*?-->/m, ''))
end

Instance Method Details

- (Object) error_404_hash

Return the MD5 hash of a 404 page



87
88
89
90
91
92
93
# File 'lib/wpscan/web_site.rb', line 87

def error_404_hash
  unless @error_404_hash
    non_existant_page = Digest::MD5.hexdigest(rand(999_999_999).to_s) + '.html'
    @error_404_hash   = WebSite.page_hash(@uri.merge(non_existant_page).to_s)
  end
  @error_404_hash
end

- (Boolean) has_basic_auth?

Returns:

  • (Boolean)


29
30
31
# File 'lib/wpscan/web_site.rb', line 29

def has_basic_auth?
  Browser.get(@uri.to_s).code == 401
end

- (Boolean) has_xml_rpc?

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/wpscan/web_site.rb', line 33

def has_xml_rpc?
  response = Browser.get_and_follow_location(xml_rpc_url)
  response.body =~ %r{XML-RPC server accepts POST requests only}i    
end

- (Object) homepage_hash



79
80
81
82
83
84
# File 'lib/wpscan/web_site.rb', line 79

def homepage_hash
  unless @homepage_hash
    @homepage_hash = WebSite.page_hash(@uri.to_s)
  end
  @homepage_hash
end

- (Boolean) online?

Checks if the remote website is up.

Returns:

  • (Boolean)


25
26
27
# File 'lib/wpscan/web_site.rb', line 25

def online?
  Browser.get(@uri.to_s).code != 0
end

- (Object) redirection(url = nil)

See if the remote url returns 30x redirect This method is recursive Return a string with the redirection or nil



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/wpscan/web_site.rb', line 50

def redirection(url = nil)
  redirection = nil
  url ||= @uri.to_s
  response = Browser.get(url)

  if response.code == 301 || response.code == 302
    redirection = response.headers_hash['location']

    # Let's check if there is a redirection in the redirection
    if other_redirection = redirection(redirection)
      redirection = other_redirection
    end
  end

  redirection
end

- (Object) rss_url

Will try to find the rss url in the homepage Only the first one found is returned



97
98
99
100
# File 'lib/wpscan/web_site.rb', line 97

def rss_url
  homepage_body = Browser.get(@uri.to_s).body
  homepage_body[%r{<link .* type="application/rss\+xml" .* href="([^"]+)" />}, 1]
end

- (Object) url



20
21
22
# File 'lib/wpscan/web_site.rb', line 20

def url
  @uri.to_s
end

- (Object) url=(url)



16
17
18
# File 'lib/wpscan/web_site.rb', line 16

def url=(url)
  @uri = URI.parse(add_trailing_slash(add_http_protocol(url)))
end

- (Object) xml_rpc_url



39
40
41
42
43
44
45
# File 'lib/wpscan/web_site.rb', line 39

def xml_rpc_url
  unless @xmlrpc_url
    @xmlrpc_url = @uri.merge('xmlrpc.php').to_s
  end

  @xmlrpc_url
end