This class provides an interface to the network configuration that exists on the remote machine, such as interfaces, and routes.
Initializes a Config instance that is used to get information about the network configuration of the remote machine.
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 32 def initialize(client) self.client = client end
Adds a route to the target machine.
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 143 def add_route(subnet, netmask, gateway) request = Packet.create_request('stdapi_net_config_add_route') request.add_tlv(TLV_TYPE_SUBNET_STRING, subnet) request.add_tlv(TLV_TYPE_NETMASK_STRING, netmask) request.add_tlv(TLV_TYPE_GATEWAY_STRING, gateway) response = client.send_request(request) return true end
Enumerates each interface.
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 45 def each_interface(&block) get_interfaces().each(&block) end
Enumerates each route.
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 111 def each_route(&block) get_routes().each(&block) end
Returns an array of network interfaces with each element.
being an Interface
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 53 def get_interfaces request = Packet.create_request('stdapi_net_config_get_interfaces') ifaces = [] response = client.send_request(request) response.each(TLV_TYPE_NETWORK_INTERFACE) { |iface| addrs = [] netmasks = [] scopes = [] while (a = iface.get_tlv_value(TLV_TYPE_IP, addrs.length)) # Netmasks aren't tightly associated with addresses, they're # just thrown all together in the interface TLV ordered to # match up. This could be done better by creating another # GroupTlv type for addresses containing an address, a netmask, # and possibly a scope. n = iface.get_tlv_value(TLV_TYPE_NETMASK, addrs.length) if (n.nil?) # Some systems can't report a netmask, only a network # prefix, so figure out the netmask from that. n = iface.get_tlv_value(TLV_TYPE_IP_PREFIX, addrs.length) if n n = Rex::Socket.bit2netmask(n, !!(a.length == 16)) end else n = Rex::Socket.addr_ntoa(n) end s = iface.get_tlv_value(TLV_TYPE_IP6_SCOPE, addrs.length) scopes[addrs.length] = s if s netmasks[addrs.length] = n if n addrs << Rex::Socket.addr_ntoa(a) end ifaces << Interface.new( :index => iface.get_tlv_value(TLV_TYPE_INTERFACE_INDEX), :mac_addr => iface.get_tlv_value(TLV_TYPE_MAC_ADDRESS), :mac_name => iface.get_tlv_value(TLV_TYPE_MAC_NAME), :mtu => iface.get_tlv_value(TLV_TYPE_INTERFACE_MTU), :flags => iface.get_tlv_value(TLV_TYPE_INTERFACE_FLAGS), :addrs => addrs, :netmasks => netmasks, :scopes => scopes ) } return ifaces end
Returns an array of routes with each element being a Route.
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 118 def get_routes request = Packet.create_request('stdapi_net_config_get_routes') routes = [] response = client.send_request(request) # Build out the array of routes # Note: This will include both IPv4 and IPv6 routes response.each(TLV_TYPE_NETWORK_ROUTE) { |route| routes << Route.new( route.get_tlv_value(TLV_TYPE_SUBNET), route.get_tlv_value(TLV_TYPE_NETMASK), route.get_tlv_value(TLV_TYPE_GATEWAY), route.get_tlv_value(TLV_TYPE_STRING), route.get_tlv_value(TLV_TYPE_ROUTE_METRIC)) } return routes end
Removes a route from the target machine.
# File lib/rex/post/meterpreter/extensions/stdapi/net/config.rb, line 158 def remove_route(subnet, netmask, gateway) request = Packet.create_request('stdapi_net_config_remove_route') request.add_tlv(TLV_TYPE_SUBNET_STRING, subnet) request.add_tlv(TLV_TYPE_NETMASK_STRING, netmask) request.add_tlv(TLV_TYPE_GATEWAY_STRING, gateway) response = client.send_request(request) return true end
Generated with the Darkfish Rdoc Generator 2.