2008-04-22 18:48:21 +00:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2014-03-13 14:47:52 +00:00
|
|
|
# Copyright (C) 2008 Rapid7, Inc.
|
2008-04-22 18:48:21 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# This script extracts the forms from the main page of each
|
|
|
|
# web site in a list. The output of this can be used with
|
|
|
|
# Metasploit (and other tools) to obtain the saved form data
|
|
|
|
# of these domains.
|
|
|
|
#
|
|
|
|
|
|
|
|
require 'rubygems' # install rubygems
|
|
|
|
require 'hpricot' # gem install hpricot
|
2015-03-06 05:45:28 +00:00
|
|
|
require 'uri'
|
2008-04-22 18:48:21 +00:00
|
|
|
require 'timeout'
|
|
|
|
|
|
|
|
def usage
|
2013-09-30 18:47:53 +00:00
|
|
|
$stderr.puts "#{$0} [site list] [output-dir]"
|
|
|
|
exit(0)
|
2008-04-22 18:48:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
sitelist = ARGV.shift() || usage()
|
|
|
|
output = ARGV.shift() || usage()
|
|
|
|
|
|
|
|
File.readlines(sitelist).each do |site|
|
2013-09-30 18:47:53 +00:00
|
|
|
site.strip!
|
|
|
|
next if site.length == 0
|
|
|
|
next if site =~ /^#/
|
2015-03-06 05:45:28 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
out = File.join(output, site + ".txt")
|
|
|
|
File.unlink(out) if File.exists?(out)
|
2015-03-06 05:45:28 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
fd = File.open(out, "a")
|
2015-03-06 05:45:28 +00:00
|
|
|
|
2008-04-22 18:48:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
["", "www."].each do |prefix|
|
|
|
|
begin
|
2015-03-06 05:45:28 +00:00
|
|
|
Timeout.timeout(10) do
|
|
|
|
doc = Hpricot(URI.parse("http://#{prefix}#{site}/").open)
|
2013-09-30 18:47:53 +00:00
|
|
|
doc.search("//form").each do |form|
|
2008-04-23 04:17:30 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
# Extract the form
|
|
|
|
res = "<form"
|
|
|
|
form.attributes.each do |attr|
|
|
|
|
res << " #{attr[0]}='#{attr[1].gsub("'", "")}'"
|
|
|
|
end
|
|
|
|
res << "> "
|
2008-04-23 04:17:30 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
# Strip out the value
|
|
|
|
form.search("//input") do |inp|
|
2008-04-23 04:17:30 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
inp.attributes.keys.each do |ikey|
|
|
|
|
if (ikey.downcase == "value")
|
|
|
|
inp[ikey] = ""
|
|
|
|
next
|
|
|
|
end
|
2008-04-23 04:17:30 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
if(inp.attributes[ikey] =~ /^http/i)
|
|
|
|
inp[ikey] = ""
|
|
|
|
next
|
|
|
|
end
|
2008-04-22 18:48:21 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
2008-04-23 04:17:30 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
res << inp.to_html
|
|
|
|
end
|
|
|
|
res << "</form>"
|
2008-04-23 03:44:24 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
fd.write(res)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
break
|
|
|
|
rescue ::Timeout::Error
|
|
|
|
$stderr.puts "#{prefix}#{site} timed out"
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
|
|
|
rescue ::Exception => e
|
|
|
|
$stderr.puts "#{prefix}#{site} #{e.class} #{e}"
|
|
|
|
end
|
|
|
|
end
|
2015-03-06 05:45:28 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
fd.close
|
2015-03-06 05:45:28 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
File.unlink(out) if (File.size(out) == 0)
|
2008-04-22 18:48:21 +00:00
|
|
|
|
|
|
|
end
|