diff --git a/lib/msf/core/post/linux/system.rb b/lib/msf/core/post/linux/system.rb index 989254c2721d..d373e8fce9e8 100644 --- a/lib/msf/core/post/linux/system.rb +++ b/lib/msf/core/post/linux/system.rb @@ -394,40 +394,44 @@ def listen_udp_ports # def get_container_type # Checking file paths for solution - if file?('/.dockerenv') || file?('/.dockerinit') - return 'Docker' - elsif file?('/run/.containerenv') - return 'Podman' - elsif directory?('/dev/lxc') - return 'LXC' - end - - # Check for WSL, as suggested in https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364 - if file?('/proc/sys/kernel/osrelease') && read_file('/proc/sys/kernel/osrelease').grep(/WSL|Microsoft/i).any? - return 'WSL' - end - - # Check cgroup on PID 1 - cgroup = read_file('/proc/1/cgroup') - if cgroup - case cgroup.tr("\n", ' ') - when /docker/i - return 'Docker' - when /lxc/i - return 'LXC' + container_type = + if file?('/.dockerenv') || file?('/.dockerinit') + 'Docker' + elsif file?('/run/.containerenv') + 'Podman' + elsif directory?('/dev/lxc') + 'LXC' + elsif file?('/proc/sys/kernel/osrelease') && read_file('/proc/sys/kernel/osrelease').grep(/WSL|Microsoft/i).any? + # Check for WSL, as suggested in https://github.com/Microsoft/WSL/issues/423#issuecomment-221627364 + 'WSL' + elsif (cgroup = read_file('/proc/1/cgroup')) + # Check cgroup on PID 1 + case cgroup.tr("\n", ' ') + when /docker/i + return 'Docker' + when /lxc/i + return 'LXC' + end + else + # Check for the "container" environment variable + case get_env('container') + when 'lxc' + return 'LXC' + when 'systemd-nspawn' + return 'systemd nspawn' + when 'podman' + return 'Podman' + else + 'Unknown' + end end + unless container_type == 'Unknown' + report_host({ + host: rhost, + virtual_host: container_type + }) end - - # Check for the "container" environment variable - case get_env('container') - when 'lxc' - return 'LXC' - when 'systemd-nspawn' - return 'systemd nspawn' - when 'podman' - return 'podman' - end - 'unknown' + container_type end # System end diff --git a/modules/post/linux/gather/checkcontainer.rb b/modules/post/linux/gather/checkcontainer.rb index 6af0996c1eea..80c705d618e2 100644 --- a/modules/post/linux/gather/checkcontainer.rb +++ b/modules/post/linux/gather/checkcontainer.rb @@ -33,11 +33,10 @@ def initialize(info = {}) def run container = get_container_type - if container - print_good("This appears to be a '#{container}' container") - report_virtualization(container) - else + if container == 'Unknown' print_status('This does not appear to be a container') + else + print_good("This appears to be a '#{container}' container") end end end