Add module to detect Docker and LXC containers
Detect Docker by: - Presence of .dockerenv file. - Finding "docker" in /proc/1/cgroup Detect LXC by: - Finding "lxc" in /proc/1/cgroupbug/bundler_fix
parent
83cd0bc977
commit
9858147dae
|
@ -135,7 +135,7 @@ module Msf::DBManager::Host
|
|||
# +:arch+:: -- one of the ARCH_* constants
|
||||
# +:mac+:: -- the host's MAC address
|
||||
# +:scope+:: -- interface identifier for link-local IPv6
|
||||
# +:virtual_host+:: -- the name of the VM host software, eg "VMWare", "QEMU", "Xen", etc.
|
||||
# +:virtual_host+:: -- the name of the virtualization software, eg "VMWare", "QEMU", "Xen", "Docker", etc.
|
||||
#
|
||||
def report_host(opts)
|
||||
|
||||
|
|
|
@ -167,19 +167,19 @@ module Msf::Post::Common
|
|||
end
|
||||
|
||||
#
|
||||
# Reports to the database that the host is a virtual machine and reports
|
||||
# the type of virtual machine it is (e.g VirtualBox, VMware, Xen)
|
||||
# Reports to the database that the host is using virtualization and reports
|
||||
# the type of virtualization it is (e.g VirtualBox, VMware, Xen, Docker)
|
||||
#
|
||||
def report_vm(vm)
|
||||
def report_virtualization(virt)
|
||||
return unless session
|
||||
return unless vm
|
||||
vm_normal = vm.to_s.strip
|
||||
return if vm_normal.empty?
|
||||
vm_data = {
|
||||
return unless virt
|
||||
virt_normal = virt.to_s.strip
|
||||
return if virt_normal.empty?
|
||||
virt_data = {
|
||||
:host => session.target_host,
|
||||
:virtual_host => vm_normal
|
||||
:virtual_host => virt_normal
|
||||
}
|
||||
report_host(vm_data)
|
||||
report_host(virt_data)
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
##
|
||||
# This module requires Metasploit: https://metasploit.com/download
|
||||
# Current source: https://github.com/rapid7/metasploit-framework
|
||||
##
|
||||
|
||||
class MetasploitModule < Msf::Post
|
||||
include Msf::Post::File
|
||||
|
||||
def initialize(info={})
|
||||
super( update_info( info,
|
||||
'Name' => 'Linux Gather Container Detection',
|
||||
'Description' => %q{
|
||||
This module attempts to determine whether the system is running
|
||||
inside of a container and if so, which one. This module supports
|
||||
detection of LXC and Docker.},
|
||||
'License' => MSF_LICENSE,
|
||||
'Author' => [ 'James Otten <jamesotten1[at]gmail.com>'],
|
||||
'Platform' => [ 'linux' ],
|
||||
'SessionTypes' => [ 'shell', 'meterpreter' ]
|
||||
))
|
||||
end
|
||||
|
||||
# Run Method for when run command is issued
|
||||
def run
|
||||
container = nil
|
||||
|
||||
# Check for .dockerenv file
|
||||
if container.nil?
|
||||
if file?("/.dockerenv")
|
||||
container = "Docker"
|
||||
end
|
||||
end
|
||||
|
||||
# Check cgroup on PID 1
|
||||
if container.nil?
|
||||
cgroup = read_file("/proc/1/cgroup")
|
||||
if cgroup
|
||||
case cgroup.tr("\n", " ")
|
||||
when /docker/i
|
||||
container = "Docker"
|
||||
when /lxc/i
|
||||
container = "LXC"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if container
|
||||
print_good("This appears to be a '#{container}' container")
|
||||
report_virtualization(container)
|
||||
else
|
||||
print_status("This does not appear to be a container")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -150,7 +150,7 @@ class MetasploitModule < Msf::Post
|
|||
|
||||
if vm
|
||||
print_good("This appears to be a '#{vm}' virtual machine")
|
||||
report_vm(vm)
|
||||
report_virtualization(vm)
|
||||
else
|
||||
print_status("This does not appear to be a virtual machine")
|
||||
end
|
||||
|
|
|
@ -324,7 +324,7 @@ class MetasploitModule < Msf::Post
|
|||
found ||= xenchk(session)
|
||||
found ||= qemuchk(session)
|
||||
if found
|
||||
report_vm(found)
|
||||
report_virtualization(found)
|
||||
else
|
||||
print_status("#{sysinfo['Computer']} appears to be a Physical Machine")
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue