Files
metasploit-gs/data/msfcrawler/basic.rb
T

83 lines
1.4 KiB
Ruby
Raw Normal View History

2010-01-26 04:21:07 +00:00
require 'rubygems'
2010-02-06 05:16:29 +00:00
require 'pathname'
2010-03-21 00:13:12 +00:00
require 'hpricot'
2010-01-26 04:21:07 +00:00
require 'uri'
2010-03-21 00:13:12 +00:00
class CrawlerSimple < BaseParser
2010-01-26 04:21:07 +00:00
def parse(request,result)
2010-03-21 00:13:12 +00:00
if !result['Content-Type'].include? "text/html"
return
end
doc = Hpricot(result.body.to_s)
doc.search('a').each do |link|
2010-01-26 04:21:07 +00:00
2010-03-21 00:13:12 +00:00
hr = link.attributes['href']
2010-01-26 04:21:07 +00:00
2010-03-21 00:13:12 +00:00
if hr
#links = result.body.to_s.scan(/href\s*=\s*[\"\'](.+?)[\"\']/)
#links.each do |link|
2010-01-26 04:21:07 +00:00
begin
2010-03-21 00:13:12 +00:00
uri = URI.parse(hr)
2010-01-26 04:21:07 +00:00
tssl = false
if uri.scheme == "https"
tssl = true
else
tssl = false
end
if !uri.host or uri.host == nil
2010-03-21 00:13:12 +00:00
thost = request['rhost']
tssl = self.targetssl
2010-01-26 04:21:07 +00:00
else
thost = uri.host
end
if !uri.port or uri.port == nil
tport = request['rport']
else
tport = uri.port
end
if !uri.path or uri.path == nil
tpath = "/"
else
tpath = uri.path
end
2010-02-06 05:16:29 +00:00
2010-03-21 00:13:12 +00:00
2010-02-06 05:16:29 +00:00
newp = Pathname.new(tpath)
2010-03-21 00:13:12 +00:00
oldp = Pathname.new(request['uri'])
if !oldp.absolute?
if !newp.absolute?
newp = oldp + newp.cleanpath
end
2010-02-06 05:16:29 +00:00
end
2010-01-26 04:21:07 +00:00
hreq = {
'rhost' => thost,
'rport' => tport,
2010-02-06 05:16:29 +00:00
'uri' => newp.to_s,
2010-01-26 04:21:07 +00:00
'method' => 'GET',
'ctype' => 'text/plain',
'ssl' => tssl,
'query' => uri.query
}
2010-03-21 00:13:12 +00:00
2010-01-26 04:21:07 +00:00
insertnewpath(hreq)
2010-03-21 00:13:12 +00:00
rescue URI::InvalidURIError
2010-01-26 04:21:07 +00:00
#puts "Parse error"
#puts "Error: #{link[0]}"
end
end
2010-03-21 00:13:12 +00:00
end
2010-01-26 04:21:07 +00:00
end
end