Skip to content

Commit

Permalink
Added report host to virtualization check
Browse files Browse the repository at this point in the history
  • Loading branch information
rad10 committed Apr 27, 2024
1 parent 15a9b59 commit 53ac511
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 36 deletions.
68 changes: 36 additions & 32 deletions lib/msf/core/post/linux/system.rb
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions modules/post/linux/gather/checkcontainer.rb
Expand Up @@ -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

0 comments on commit 53ac511

Please sign in to comment.