|
| 1 | +# This file is Copyright 2023 Volatility Foundation and licensed under the Volatility Software License 1.0 |
| 2 | +# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 |
| 3 | +# |
| 4 | + |
| 5 | +from typing import List |
| 6 | +from volatility3.framework import interfaces, renderers, constants |
| 7 | +from volatility3.framework.configuration import requirements |
| 8 | +from volatility3.framework.interfaces import plugins |
| 9 | +from volatility3.framework.symbols.linux import network |
| 10 | +from volatility3.framework.symbols.linux.extensions import network as net_extensions |
| 11 | + |
| 12 | + |
| 13 | +class Addr(plugins.PluginInterface): |
| 14 | + """Lists network interface information for all devices""" |
| 15 | + |
| 16 | + _required_framework_version = (2, 22, 0) |
| 17 | + |
| 18 | + _version = (1, 0, 1) |
| 19 | + |
| 20 | + @classmethod |
| 21 | + def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: |
| 22 | + return [ |
| 23 | + requirements.ModuleRequirement( |
| 24 | + name="kernel", |
| 25 | + description="Linux kernel", |
| 26 | + architectures=["Intel32", "Intel64"], |
| 27 | + ), |
| 28 | + requirements.VersionRequirement( |
| 29 | + name="Net", component=network.NetSymbols, version=(1, 0, 0) |
| 30 | + ), |
| 31 | + ] |
| 32 | + |
| 33 | + def _gather_net_dev_info(self, net_dev: net_extensions.net_device): |
| 34 | + mac_addr = net_dev.get_mac_address() |
| 35 | + promisc = net_dev.promisc |
| 36 | + operational_state = net_dev.get_operational_state() |
| 37 | + iface_name = net_dev.get_device_name() |
| 38 | + iface_ifindex = net_dev.ifindex |
| 39 | + try: |
| 40 | + net_ns_id = net_dev.get_net_namespace_id() |
| 41 | + except AttributeError: |
| 42 | + net_ns_id = renderers.NotAvailableValue() |
| 43 | + |
| 44 | + # Interface IPv4 Addresses |
| 45 | + in_device = net_dev.ip_ptr.dereference().cast("in_device") |
| 46 | + for in_ifaddr in in_device.get_addresses(): |
| 47 | + prefix_len = in_ifaddr.get_prefix_len() |
| 48 | + scope_type = in_ifaddr.get_scope_type() |
| 49 | + ip_addr = in_ifaddr.get_address() |
| 50 | + yield net_ns_id, iface_ifindex, iface_name, mac_addr, promisc, ip_addr, prefix_len, scope_type, operational_state |
| 51 | + |
| 52 | + # Interface IPv6 Addresses |
| 53 | + inet6_dev = net_dev.ip6_ptr.dereference().cast("inet6_dev") |
| 54 | + for inet6_ifaddr in inet6_dev.get_addresses(): |
| 55 | + prefix_len = inet6_ifaddr.get_prefix_len() |
| 56 | + scope_type = inet6_ifaddr.get_scope_type() |
| 57 | + ip6_addr = inet6_ifaddr.get_address() |
| 58 | + yield net_ns_id, iface_ifindex, iface_name, mac_addr, promisc, ip6_addr, prefix_len, scope_type, operational_state |
| 59 | + |
| 60 | + def _generator(self): |
| 61 | + vmlinux = self.context.modules[self.config["kernel"]] |
| 62 | + |
| 63 | + net_type_symname = vmlinux.symbol_table_name + constants.BANG + "net" |
| 64 | + net_device_symname = vmlinux.symbol_table_name + constants.BANG + "net_device" |
| 65 | + network.NetSymbols.apply(self.context.symbol_space[vmlinux.symbol_table_name]) |
| 66 | + |
| 67 | + # 'net_namespace_list' exists from kernels >= 2.6.24 |
| 68 | + net_namespace_list = vmlinux.object_from_symbol("net_namespace_list") |
| 69 | + for net_ns in net_namespace_list.to_list(net_type_symname, "list"): |
| 70 | + for net_dev in net_ns.dev_base_head.to_list(net_device_symname, "dev_list"): |
| 71 | + for fields in self._gather_net_dev_info(net_dev): |
| 72 | + yield 0, fields |
| 73 | + |
| 74 | + def run(self): |
| 75 | + headers = [ |
| 76 | + ("NetNS", int), |
| 77 | + ("Index", int), |
| 78 | + ("Interface", str), |
| 79 | + ("MAC", str), |
| 80 | + ("Promiscuous", bool), |
| 81 | + ("IP", str), |
| 82 | + ("Prefix", int), |
| 83 | + ("Scope Type", str), |
| 84 | + ("State", str), |
| 85 | + ] |
| 86 | + |
| 87 | + return renderers.TreeGrid(headers, self._generator()) |
| 88 | + |
| 89 | + |
| 90 | +class Link(plugins.PluginInterface): |
| 91 | + """Lists information about network interfaces similar to `ip link show`""" |
| 92 | + |
| 93 | + _required_framework_version = (2, 0, 0) |
| 94 | + _version = (1, 0, 0) |
| 95 | + |
| 96 | + @classmethod |
| 97 | + def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: |
| 98 | + return [ |
| 99 | + requirements.ModuleRequirement( |
| 100 | + name="kernel", |
| 101 | + description="Linux kernel", |
| 102 | + architectures=["Intel32", "Intel64"], |
| 103 | + ), |
| 104 | + requirements.VersionRequirement( |
| 105 | + name="Net", component=network.NetSymbols, version=(1, 0, 0) |
| 106 | + ), |
| 107 | + ] |
| 108 | + |
| 109 | + def _gather_net_dev_link_info(self, net_device): |
| 110 | + mac_addr = net_device.get_mac_address() |
| 111 | + operational_state = net_device.get_operational_state() |
| 112 | + iface_name = net_device.get_device_name() |
| 113 | + mtu = net_device.mtu |
| 114 | + qdisc_name = net_device.get_qdisc_name() |
| 115 | + qlen = net_device.get_queue_length() |
| 116 | + try: |
| 117 | + net_ns_id = net_device.get_net_namespace_id() |
| 118 | + except AttributeError: |
| 119 | + net_ns_id = renderers.NotAvailableValue() |
| 120 | + |
| 121 | + # Format flags to string. Drop IFF_ to match iproute2 'ip link' output. |
| 122 | + # Also, note that iproute2 removes IFF_RUNNING, see print_link_flags() |
| 123 | + flags_list = [ |
| 124 | + flag.replace("IFF_", "") |
| 125 | + for flag in net_device.get_flag_names() |
| 126 | + if flag != "IFF_RUNNING" |
| 127 | + ] |
| 128 | + flags_str = ",".join(flags_list) |
| 129 | + |
| 130 | + yield net_ns_id, iface_name, mac_addr, operational_state, mtu, qdisc_name, qlen, flags_str |
| 131 | + |
| 132 | + def _generator(self): |
| 133 | + vmlinux = self.context.modules[self.config["kernel"]] |
| 134 | + |
| 135 | + network.NetSymbols.apply(self.context.symbol_space[vmlinux.symbol_table_name]) |
| 136 | + |
| 137 | + net_type_symname = vmlinux.symbol_table_name + constants.BANG + "net" |
| 138 | + net_device_symname = vmlinux.symbol_table_name + constants.BANG + "net_device" |
| 139 | + |
| 140 | + # 'net_namespace_list' exists from kernels >= 2.6.24 |
| 141 | + net_namespace_list = vmlinux.object_from_symbol("net_namespace_list") |
| 142 | + for net_ns in net_namespace_list.to_list(net_type_symname, "list"): |
| 143 | + for net_dev in net_ns.dev_base_head.to_list(net_device_symname, "dev_list"): |
| 144 | + for fields in self._gather_net_dev_link_info(net_dev): |
| 145 | + yield 0, fields |
| 146 | + |
| 147 | + def run(self): |
| 148 | + headers = [ |
| 149 | + ("NS", int), |
| 150 | + ("Interface", str), |
| 151 | + ("MAC", str), |
| 152 | + ("State", str), |
| 153 | + ("MTU", int), |
| 154 | + ("Qdisc", str), |
| 155 | + ("Qlen", int), |
| 156 | + ("Flags", str), |
| 157 | + ] |
| 158 | + |
| 159 | + return renderers.TreeGrid(headers, self._generator()) |
0 commit comments