-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linux ip.Addr and ip.Link plugins #1079
base: develop
Are you sure you want to change the base?
Changes from 3 commits
82668af
6b3bbad
6e0ffc9
97007e8
620b9b4
cd867bf
5a8a0de
c72fa75
1b153cc
6f1e7c2
260fbd8
7b1c75c
8b6bd0f
5219e8a
828b688
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -281,3 +281,47 @@ | |
) | ||
|
||
ELF_MAX_EXTRACTION_SIZE = 1024 * 1024 * 1024 * 4 - 1 | ||
|
||
# For IFA_* below - Ref: include/net/ipv6.h | ||
IPV6_ADDR_LOOPBACK = 0x0010 | ||
IPV6_ADDR_LINKLOCAL = 0x0020 | ||
IPV6_ADDR_SITELOCAL = 0x0040 | ||
# For inet6_ifaddr - Ref: include/net/if_inet6.h | ||
IFA_HOST = IPV6_ADDR_LOOPBACK | ||
IFA_LINK = IPV6_ADDR_LINKLOCAL | ||
IFA_SITE = IPV6_ADDR_SITELOCAL | ||
|
||
# Only for kernels < 3.15 when the net_device_flags enum didn't exist | ||
# ref include/uapi/linux/if.h | ||
NET_DEVICE_FLAGS = { | ||
"IFF_UP": 0x1, | ||
"IFF_BROADCAST": 0x2, | ||
"IFF_DEBUG": 0x4, | ||
"IFF_LOOPBACK": 0x8, | ||
"IFF_POINTOPOINT": 0x10, | ||
"IFF_NOTRAILERS": 0x20, | ||
"IFF_RUNNING": 0x40, | ||
"IFF_NOARP": 0x80, | ||
"IFF_PROMISC": 0x100, | ||
"IFF_ALLMULTI": 0x200, | ||
"IFF_MASTER": 0x400, | ||
"IFF_SLAVE": 0x800, | ||
"IFF_MULTICAST": 0x1000, | ||
"IFF_PORTSEL": 0x2000, | ||
"IFF_AUTOMEDIA": 0x4000, | ||
"IFF_DYNAMIC": 0x8000, | ||
"IFF_LOWER_UP": 0x10000, | ||
"IFF_DORMANT": 0x20000, | ||
"IFF_ECHO": 0x40000, | ||
} | ||
|
||
# RFC 2863 operational status. Kernels >= 2.6.17. See IF_OPER_* in include/uapi/linux/if.h | ||
IF_OPER_STATES = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. This is used by value, so I don't think at the moment being an Enum offers any usability advantage. Although I reckon it may look better to Pythonic eyes ;) |
||
"UNKNOWN", | ||
"NOTPRESENT", | ||
"DOWN", | ||
"LOWERLAYERDOWN", | ||
"TESTING", | ||
"DORMANT", | ||
"UP", | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# This file is Copyright 2023 Volatility Foundation and licensed under the Volatility Software License 1.0 | ||
# which is available at https://www.volatilityfoundation.org/license/vsl-v1.0 | ||
# | ||
|
||
from typing import List | ||
from volatility3.framework import interfaces, renderers, constants | ||
from volatility3.framework.configuration import requirements | ||
from volatility3.framework.interfaces import plugins | ||
from volatility3.framework.objects import utility | ||
|
||
|
||
class Addr(plugins.PluginInterface): | ||
"""Lists network interface information for all devices""" | ||
|
||
_required_framework_version = (2, 0, 0) | ||
|
||
_version = (1, 0, 0) | ||
|
||
@classmethod | ||
def get_requirements(cls) -> List[interfaces.configuration.RequirementInterface]: | ||
return [ | ||
requirements.ModuleRequirement( | ||
name="kernel", | ||
description="Linux kernel", | ||
architectures=["Intel32", "Intel64"], | ||
), | ||
] | ||
|
||
def _gather_net_dev_info(self, net_dev): | ||
mac_addr = net_dev.get_mac_address() | ||
promisc = net_dev.promisc | ||
operational_state = net_dev.get_operational_state() | ||
iface_name = utility.array_to_string(net_dev.name) | ||
iface_ifindex = net_dev.ifindex | ||
try: | ||
net_ns_id = net_dev.get_net_namespace_id() | ||
except AttributeError: | ||
net_ns_id = renderers.NotAvailableValue() | ||
|
||
# Interface IPv4 Addresses | ||
in_device = net_dev.ip_ptr.dereference().cast("in_device") | ||
for in_ifaddr in in_device.get_addresses(): | ||
prefix_len = in_ifaddr.get_prefix_len() | ||
scope_type = in_ifaddr.get_scope_type() | ||
ip_addr = in_ifaddr.get_address() | ||
yield net_ns_id, iface_ifindex, iface_name, mac_addr, promisc, ip_addr, prefix_len, scope_type, operational_state | ||
|
||
# Interface IPv6 Addresses | ||
inet6_dev = net_dev.ip6_ptr.dereference().cast("inet6_dev") | ||
for inet6_ifaddr in inet6_dev.get_addresses(): | ||
prefix_len = inet6_ifaddr.get_prefix_len() | ||
scope_type = inet6_ifaddr.get_scope_type() | ||
ip6_addr = inet6_ifaddr.get_address() | ||
yield net_ns_id, iface_ifindex, iface_name, mac_addr, promisc, ip6_addr, prefix_len, scope_type, operational_state | ||
|
||
def _generator(self): | ||
vmlinux = self.context.modules[self.config["kernel"]] | ||
|
||
net_type_symname = vmlinux.symbol_table_name + constants.BANG + "net" | ||
net_device_symname = vmlinux.symbol_table_name + constants.BANG + "net_device" | ||
|
||
# 'net_namespace_list' exists from kernels >= 2.6.24 | ||
net_namespace_list = vmlinux.object_from_symbol("net_namespace_list") | ||
for net_ns in net_namespace_list.to_list(net_type_symname, "list"): | ||
for net_dev in net_ns.dev_base_head.to_list(net_device_symname, "dev_list"): | ||
for fields in self._gather_net_dev_info(net_dev): | ||
yield 0, fields | ||
|
||
def run(self): | ||
headers = [ | ||
("NetNS", int), | ||
("Index", int), | ||
("Interface", str), | ||
("MAC", str), | ||
("Promiscuous", bool), | ||
("IP", str), | ||
("Prefix", int), | ||
("Scope Type", str), | ||
("State", str), | ||
] | ||
|
||
return renderers.TreeGrid(headers, self._generator()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also looks like it could be a python Enum?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm here changing this to an Enum makes the code a bit complicated... have a look at how it's used in
_get_flag_choices()
and_get_net_device_flag_value()
to support both kernels <3.15 and >=3.15.