Skip to content

Instantly share code, notes, and snippets.

@tasuten
Created July 8, 2015 18:54
Show Gist options
  • Save tasuten/455f16c85c3660a66387 to your computer and use it in GitHub Desktop.
Save tasuten/455f16c85c3660a66387 to your computer and use it in GitHub Desktop.
Metasploit Frameworkのモジュールを練習がてら書いたもの。~/.msf4/modules/auxiliary/scanner/http/simple_http_version.rbあたりに置くと良いと思います
#!/usr/bin/env ruby
# encoding : utf-8
require 'msf/core'
class Metasploit3 < Msf::Auxiliary
include Msf::Exploit::Remote::Tcp
include Msf::Auxiliary::Scanner
def initialize
super(
'Name' => 'Simple HTTP server detector',
'Description' => %q{
This module detects HTTP server name and version on target host,
from Server: field's value in response header.
},
'Author' => 'tasuten',
'License' => MSF_LICENSE
)
register_options(
[
Opt::RPORT(80)
], self.class)
end
def run_host(ip)
connect()
# including \r\n, so use ", not '
sock.puts("GET / HTTP/1.1\r\n")
sock.puts("Host: #{ip}\r\n") # required in HTTP/1.1
sock.puts("\r\n")
server_version = get_server_version(sock)
if server_version
print_good("#{server_version} on #{ip}")
else
print_error("Can't find server version...")
end
disconnect()
end
def get_server_version(sock)
sock.each_line do |line|
if line =~ /^Server:/i # HTTP headers are case-insensitive
return line.gsub(/^Server:/i, '').strip
elsif line.strip == '' # empty line in response header's tail
return false
else
# nop
end
end
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment