Ticket #149 (assigned defect)

Opened 10 months ago

Last modified 7 months ago

msfopcode broken under Windows and Cygwin

Reported by: patrickw Assigned to: patrickw (accepted)
Priority: minor Milestone: Metasploit 3.2
Component: framework3 Version:
Keywords: Cc:

Description

$ msfopcode stats
/usr/lib/ruby/1.8/resolv.rb:299:in `open': can't convert nil into String (TypeError)
        from /usr/lib/ruby/1.8/resolv.rb:299:in `lazy_initialize'
        from /usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
        from /usr/lib/ruby/1.8/resolv.rb:295:in `lazy_initialize'
        from /usr/lib/ruby/1.8/resolv.rb:337:in `each_address'
        from /usr/lib/ruby/1.8/resolv.rb:244:in `each_address'
        from /usr/lib/ruby/1.8/resolv.rb:243:in `each'
        from /usr/lib/ruby/1.8/resolv.rb:243:in `each_address'
        from /usr/lib/ruby/1.8/resolv.rb:227:in `getaddress'
         ... 12 levels...
        from /home/framework/lib/rex/proto/http/client.rb:288:in `send_recv'
        from /home/framework/lib/rex/exploitation/opcodedb.rb:739:in `request'
        from /home/framework/lib/rex/exploitation/opcodedb.rb:697:in `statistics
'
        from /home/framework/msfopcode:156

Appears to be the host file lookup prior to DNS, in ruby under cygwin - %windir%/system32/drivers/etc/hosts != /cygdrive/c/%windir% ....

Change History

09/30/07 22:20:25 changed by patrickw

  • status changed from new to assigned.
  • milestone set to Metasploit 3.1 Release.

The flaw occurs in Ruby.

\lib\ruby\1.8\resolv.rb:

class Hosts
    if /mswin32|cygwin|mingw|bccwin/ =~ RUBY_PLATFORM
      require 'win32/resolv'
      DefaultFileName = Win32::Resolv.get_hosts_path
    else
      DefaultFileName = '/etc/hosts'
    end

\lib\ruby\1.8\win32\resolv.rb:

    def self.get_hosts_path
      path = get_hosts_dir
      path = File.join(path.gsub(/\\/, File::SEPARATOR), 'hosts')
      File.exist?(path) ? path : nil
    end

Matches cygwin, but does not cater for cygwin not being able to read %systemroot%.

My fix:

    def self.get_hosts_path
      path = get_hosts_dir
      if /cygwin/ =~ RUBY_PLATFORM
	      path = path.gsub(/%SystemRoot%/, `cygpath -W 2>&1`.chomp)
      end	      
      path = File.join(path.gsub(/\\/, File::SEPARATOR), 'hosts')
      File.exist?(path) ? path : nil
    end

File is outside svn. Ruby bug.

12/27/07 11:51:12 changed by hdm

  • milestone changed from Metasploit 3.1 Release to Metasploit 3.2 Release.

Pushing to 3.2