Path: blob/master/modules/auxiliary/scanner/gopher/gopher_gophermap.rb
19812 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Tcp7include Msf::Auxiliary::Report8include Msf::Auxiliary::Scanner910def initialize11super(12'Name' => 'Gopher gophermap Scanner',13'Description' => %q(14This module identifies Gopher servers, and processes the gophermap15file which lists all the files on the server.16),17'References' => [18['URL', 'https://sdfeu.org/w/tutorials:gopher']19],20'Author' => 'h00die',21'License' => MSF_LICENSE22)2324register_options(25[26Opt::RPORT(70),27OptString.new('PATH', [false, 'Path to enumerate', ''])28]29)30end3132TYPE_MAP = {33'0' => 'Text file',34'1' => 'Directory',35'2' => 'CSO name server',36'3' => 'Error',37'4' => 'Mac HQX filer',38'5' => 'PC binary',39'6' => 'UNIX uuencoded file',40'7' => 'Search server',41'8' => 'Telnet Session',42'9' => 'Binary File',43'c' => 'Calendar',44'e' => 'Event',45'g' => 'GIF image',46'h' => 'HTML',47'i' => 'inline text',48's' => 'Sound',49'I' => 'Image',50'M' => 'MIME multipart/mixed message',51'T' => 'TN3270 Session'52}.freeze5354def get_type(char)55TYPE_MAP.fetch(char.chomp)56end5758def run_host(ip)59begin60connect61sock.put("#{datastore['path']}\r\n")62gophermap = sock.get_once63if gophermap64gophermap.split("\r\n").each do |line|65line_parts = line.split("\t")66next unless line_parts.length >= 26768# syntax: [type_character]description[tab]path[tab, after this is optional]server[tab]port69line_parts = line.split("\t")70desc = line_parts[0]71type_char = desc.slice!(0) # remove first character which is the file type72file_type = get_type(type_char)73if file_type && file_type == 'inline text'74print_good(desc)75next76end77if file_type78print_good(" #{file_type}: #{desc}")79else80print_good(" Invalid File Type (#{type_char}): #{desc}")81end82if line_parts.length >= 383print_good(" Path: #{line_parts[2]}:#{line_parts[3]}#{line_parts[1]}")84elsif line.length >= 285print_good(" Path: #{line_parts[2]}#{line_parts[1]}")86else87print_good(" Path: #{line_parts[1]}")8889end90end91report_service(host: ip, port: rport, service: 'gopher', info: gophermap)92else93print_error('No gophermap')94end95rescue ::Rex::ConnectionError, ::IOError, ::Errno::ECONNRESET96rescue ::Exception => e97print_error("#{ip}: #{e} #{e.backtrace}")98ensure99disconnect100end101end102end103104105