Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb
Views: 11795
# -*- coding: binary -*-12require 'ipaddr'34module Rex5module Post6module Meterpreter7module Extensions8module Stdapi9module Net1011###12#13# This class represents a logical physical interface14# on the remote machine.15#16###17class Interface1819##20#21# Constructor22#23##2425#26# Returns a logical interface and initializes it to the supplied27# parameters.28#29def initialize(opts={})30self.index = opts[:index] || -131self.mac_addr = opts[:mac_addr]32self.mac_name = opts[:mac_name]33self.mtu = opts[:mtu]34self.flags = opts[:flags]35self.addrs = opts[:addrs]36self.netmasks = opts[:netmasks]37self.scopes = opts[:scopes]38end3940#41# Returns a pretty string representation of the interface's properties.42#43def pretty44macocts = []45mac_addr.each_byte { |o| macocts << o }46macocts += [0] * (6 - macocts.size) if macocts.size < 64748info = [49["Name" , mac_name ],50["Hardware MAC" , sprintf("%02x:%02x:%02x:%02x:%02x:%02x",51macocts[0], macocts[1], macocts[2],52macocts[3], macocts[4], macocts[5])],53["MTU" , mtu ],54["Flags" , flags ],55]5657# If all went as planned, addrs and netmasks will have the same number58# of elements and be properly ordered such that they match up59# correctly.60addr_masks = addrs.zip(netmasks)6162addr_masks.select { |a| Rex::Socket.is_ipv4?(a[0]) }.each { |a|63info << [ "IPv4 Address", a[0] ]64info << [ "IPv4 Netmask", a[1] ]65}66addr_masks.select { |a| Rex::Socket.is_ipv6?(a[0]) }.each { |a|67info << [ "IPv6 Address", a[0] ]68info << [ "IPv6 Netmask", a[1] ]69}7071pad = info.map{|i| i[0] }.max_by{|k|k.length}.length7273ret = sprintf(74"Interface %2d\n" +75"============\n",76index77)7879info.map {|k,v|80next if v.nil?81ret << k.ljust(pad) + " : #{v}\n"82}8384ret85end8687#88# The first address associated with this Interface89#90def ip91addrs.first92end9394#95# The index of the interface.96#97attr_accessor :index98#99# An Array of IP addresses bound to the Interface.100#101attr_accessor :addrs102#103# The physical (MAC) address of the NIC.104#105attr_accessor :mac_addr106#107# The name of the interface.108#109attr_accessor :mac_name110#111# The MTU associated with the interface.112#113attr_accessor :mtu114#115# The flags associated with the interface.116#117attr_accessor :flags118#119# An Array of netmasks. This will have the same number of elements as #addrs120#121attr_accessor :netmasks122#123# An Array of IPv6 address scopes. This will have the same number of elements as #addrs124#125attr_accessor :scopes126end127128end; end; end; end; end; end129130131