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

59 lines
1.2 KiB
Ruby
Raw Normal View History

2010-05-03 17:13:09 +00:00
##
# $Id$
##
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##
# $Revision$
2010-03-26 02:39:19 +00:00
require 'rubygems'
require 'pathname'
2014-07-17 00:14:07 +02:00
require 'nokogiri'
2010-03-26 02:39:19 +00:00
require 'uri'
class CrawlerForms < BaseParser
2013-09-30 13:47:53 -05:00
def parse(request,result)
2010-05-03 17:13:09 +00:00
2013-09-30 13:47:53 -05:00
if !result['Content-Type'].include? "text/html"
return
end
2010-05-03 17:13:09 +00:00
2013-09-30 13:47:53 -05:00
hr = ''
m = ''
2010-03-26 02:39:19 +00:00
2014-07-17 00:14:07 +02:00
doc = Nokogiri::HTML(result.body.to_s)
doc.css('form').each do |f|
hr = f['action']
2010-04-03 05:52:22 +00:00
2014-07-17 00:14:07 +02:00
fname = f['name']
fname = "NONE" if fname.empty?
2010-05-03 17:13:09 +00:00
2014-07-17 00:14:07 +02:00
m = f['method'].empty? ? 'GET' : f['method'].upcase
2010-05-03 17:13:09 +00:00
2014-07-17 00:14:07 +02:00
htmlform = Nokogiri::HTML(f.inner_html)
2010-05-03 17:13:09 +00:00
2013-09-30 13:47:53 -05:00
arrdata = []
2010-05-03 17:13:09 +00:00
2014-07-17 00:14:07 +02:00
htmlform.css('input').each do |p|
arrdata << "#{p['name']}=#{Rex::Text.uri_encode(p['value'])}"
2013-09-30 13:47:53 -05:00
end
2010-05-03 17:13:09 +00:00
2013-09-30 13:47:53 -05:00
data = arrdata.join("&").to_s
2010-05-03 17:13:09 +00:00
2013-09-30 13:47:53 -05:00
begin
2014-07-17 00:14:07 +02:00
hreq = urltohash(m, hr, request['uri'], data)
2013-09-30 13:47:53 -05:00
hreq['ctype'] = 'application/x-www-form-urlencoded'
insertnewpath(hreq)
rescue URI::InvalidURIError
end
end
end
2010-03-26 02:39:19 +00:00
end