Changeset 5565

Show
Ignore:
Timestamp:
07/22/08 14:03:59 (1 month ago)
Author:
hdm
Message:

Raw IP socket support for Rex. Guess what this is for :-)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/trunk/lib/rex/socket.rb

    r5561 r5565  
    6767        end 
    6868 
     69        # 
     70        # Create a IP socket using the supplied parameter hash. 
     71        # 
     72        def self.create_ip(opts = {}) 
     73                return create_param(Rex::Socket::Parameters.from_hash(opts.merge('Proto' => 'ip'))) 
     74        end 
     75         
    6976        ## 
    7077        # 
  • framework3/trunk/lib/rex/socket/comm/local.rb

    r5546 r5565  
    55require 'rex/socket/ssl_tcp_server' 
    66require 'rex/socket/udp' 
     7require 'rex/socket/ip' 
    78require 'timeout' 
    89 
     
    2627                        when 'udp' 
    2728                                return create_by_type(param, ::Socket::SOCK_DGRAM, ::Socket::IPPROTO_UDP) 
     29                        when 'ip' 
     30                                return create_ip(param) 
    2831                        else 
    2932                                raise Rex::UnsupportedProtocol.new(param.proto), caller 
     
    3134        end 
    3235 
     36 
     37        # 
     38        # Creates a raw IP socket using the supplied Parameter instance. 
     39        # Special-cased because of how different it is from UDP/TCP 
     40        # 
     41        def self.create_ip(param) 
     42                sock = ::Socket.open(::Socket::PF_INET, ::Socket::SOCK_RAW, ::Socket::IPPROTO_RAW) 
     43                unless sock.getsockopt(::Socket::SOL_IP, ::Socket::IP_HDRINCL) 
     44                        sock.setsockopt(::Socket::SOL_IP, ::Socket::IP_HDRINCL, true) 
     45                end              
     46 
     47                return sock if (param.bare?) 
     48 
     49                sock.extend(::Rex::Socket::Ip) 
     50                sock.initsock(param) 
     51                 
     52                sock 
     53        end 
     54         
     55         
    3356        # 
    3457        # Creates a socket using the supplied Parameter instance. 
  • framework3/trunk/lib/rex/socket/parameters.rb

    r5113 r5565  
    193193 
    194194        # 
     195        # Returns true if the protocol for the parameters is IP. 
     196        # 
     197        def ip? 
     198                return (proto == 'ip') 
     199        end 
     200         
     201        # 
    195202        # Returns true if the socket is a bare socket that does not inherit from 
    196203        # any extended Rex classes.