paxtest-0.9.15/0000755000000000000000000000000012743043200011767 5ustar rootrootpaxtest-0.9.15/getshlib.c0000644000000000000000000000161112743042554013746 0ustar rootroot/* getshlib.c - Get the address of a function in a shared library and print it * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include /* OpenBSD 3.5 doesn't define RTLD_DEFAULT */ /* OpenBSD 3.6 does but it doesn't actually handle (segfaults on) RTLD_DEFAULT, sigh... */ #ifdef __OpenBSD__ #undef RTLD_DEFAULT #define RTLD_DEFAULT "libc.so" #elif defined(__FreeBSD__) #undef RTLD_DEFAULT #define RTLD_DEFAULT "libc.so.7" #endif int main( int argc, char *argv[] ) { void *handle; handle = dlopen( RTLD_DEFAULT, RTLD_LAZY ); if( handle != NULL ) { void *sprintf; dlerror(); /* clear any errors */ sprintf = dlsym( handle, "sprintf" ); if( dlerror() == NULL ) { printf( "%p\n", sprintf ); } dlclose( handle ); } } paxtest-0.9.15/randmain2.c0000644000000000000000000000057312743042554014026 0ustar rootroot/* randmain2.c - Tests the randomization of the ET_DYN main executable * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Main executable randomization (PIE) "; const char testprog[] = RUNDIR"/getmain2"; paxtest-0.9.15/fastrandbody.c0000644000000000000000000000200212743042554014620 0ustar rootroot/* fastrandbody.c - This part is shared by the randomization tests * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #define COUNT (25) extern const char testname[]; extern const char testprog[]; int main( int argc, char *argv[] ) { FILE *fp; int i; unsigned long tmp; unsigned long and; unsigned long or; int bits; int ret; printf( "%s: ", testname ); and = ~0L; or = 0L; for( i = 0; i < COUNT; i++ ) { fp = popen( testprog, "r" ); if( fp == NULL ) { perror( testprog ); exit( 1 ); } ret = fscanf( fp, "%lx", &tmp ); if (ret != 1) { perror ( testprog ); exit( 1 ); } and &= tmp; or |= tmp; pclose( fp ); } if( and == or ) { printf( "No randomization\n" ); } else { tmp = and ^ ~or; tmp = or & ~tmp; bits = 0; while( tmp != 0 ) { bits += (tmp%2); tmp >>= 1; } printf( "%d bits (guessed)\n", bits ); } exit( 0 ); } paxtest-0.9.15/randstack1.c0000644000000000000000000000056412743042554014206 0ustar rootroot/* randstack.c - Tests the randomization of the stack pointer. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Stack randomization test (SEGMEXEC) "; const char testprog[] = RUNDIR"/getstack1"; paxtest-0.9.15/debian/0000755000000000000000000000000012743042554013224 5ustar rootrootpaxtest-0.9.15/debian/manpage.1.ex0000644000000000000000000000353012743042554015332 0ustar rootroot.\" Hey, EMACS: -*- nroff -*- .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" other parameters are allowed: see man(7), man(1) .TH PAXTEST SECTION "May 19, 2003" .\" Please adjust this date whenever revising the manpage. .\" .\" Some roff macros, for reference: .\" .nh disable hyphenation .\" .hy enable hyphenation .\" .ad l left justify .\" .ad b justify to both left and right margins .\" .nf disable filling .\" .fi enable filling .\" .br insert line break .\" .sp insert n+1 empty lines .\" for manpage-specific macros, see man(7) .SH NAME paxtest \- program to do something .SH SYNOPSIS .B paxtest .RI [ options ] " files" ... .br .B bar .RI [ options ] " files" ... .SH DESCRIPTION This manual page documents briefly the .B paxtest and .B bar commands. This manual page was written for the Debian distribution because the original program does not have a manual page. Instead, it has documentation in the GNU Info format; see below. .PP .\" TeX users may be more comfortable with the \fB\fP and .\" \fI\fP escape sequences to invode bold face and italics, .\" respectively. \fBpaxtest\fP is a program that... .SH OPTIONS These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the Info files. .TP .B \-h, \-\-help Show summary of options. .TP .B \-v, \-\-version Show version of program. .SH SEE ALSO .BR bar (1), .BR baz (1). .br The programs are documented fully by .IR "The Rise and Fall of a Fooish Bar" , available via the Info system. .SH AUTHOR This manual page was written by Peter Busser , for the Debian GNU/Linux system (but may be used by others). paxtest-0.9.15/debian/paxtest.sgml0000644000000000000000000001332312743042554015602 0ustar rootroot Javier"> Fernandez-Sanguino"> November 8, 2003"> 1"> jfs@computer.org"> PAXTEST"> Debian"> GNU"> ]>
&dhemail;
&dhfirstname; &dhsurname; 2003 Peter Busser &dhdate;
&dhucpackage; &dhsection; &dhpackage; program to test buffer overflow protection &dhpackage; logfile DESCRIPTION &dhpackage; is a program that attempts to test kernel enforcements over memory usage. Some attacks benefit from kernels that do not impose limitations. For example, execution in some memory segments makes buffer overflows possible. It is used as a regression test suite for PaX, but might be useful to test other memory protection patches for the kernel. &dhpackage; runs a set of programs that attempt to subvert memory usage. For example: Executable anonymous mapping : Killed Executable bss : Killed Executable data : Killed Executable heap : Killed Executable stack : Killed Executable anonymous mapping (mprotect) : Killed Executable bss (mprotect) : Killed Executable data (mprotect) : Killed Executable heap (mprotect) : Killed Executable shared library bss (mprotect) : Killed Executable shared library data (mprotect): Killed Executable stack (mprotect) : Killed Anonymous mapping randomisation test : 16 bits (guessed) Heap randomisation test (ET_EXEC) : 13 bits (guessed) Heap randomisation test (ET_DYN) : 25 bits (guessed) Main executable randomisation (ET_EXEC) : No randomisation Main executable randomisation (ET_DYN) : 17 bits (guessed) Stack randomisation test (SEGMEXEC) : 23 bits (guessed) Stack randomisation test (PAGEEXEC) : 24 bits (guessed) Return to function (strcpy) : Vulnerable Return to function (strcpy, RANDEXEC) : Vulnerable Return to function (memcpy) : Vulnerable Return to function (memcpy, RANDEXEC) : Vulnerable Executable shared library bss : Killed Executable shared library data : Killed Writable text segments : Killed The Executable ... tests basically put an instruction in a place that is supposed to be data (i.e. malloced data, C variable, etc.) and tries to execute it. The (mprotect) tests try to trick the kernel in marking this piece of memory as executable first. Return to function tests overwrite the return address on the stack, these are hard to prevent from inside the kernel. The last test tries to overwrite memory which is marked as executable. A normal Linux kernel (unpatched to protect for buffer overflows) will show all tests as Vulnerable and no stack randomisation or 6 bits (due to stack colouring). In other words, on a normal Linux kernel you can execute any data inside a process's memory or overwrite any code at will. This manual page was written for the &debian; distribution because the original program does not have a manual page. OPTIONS This program takes only a single option: a file to which log all the test results (by default it will log to stdin/stdout) SEE ALSO For more information see PaX Documentation. AUTHOR &dhpackage; was written by Peter Busser. This manual page was written by &dhusername; &dhemail; for the &debian; system (but may be used by others) based on the information in the source code and Peter Busser's comments sent to public mailing lists. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Public License, Version 2 or any later version published by the Free Software Foundation.
paxtest-0.9.15/debian/dirs0000644000000000000000000000002112743042554014101 0ustar rootrootusr/bin usr/sbin paxtest-0.9.15/debian/changelog0000644000000000000000000000616712743042554015110 0ustar rootrootpaxtest (0.9.13-1) stable; urgency=low * Added VDSO randomization test * Added basic entropy quality testing, subtracts weak bits from entropy count * Increased iterations for all randomization tests but the exhaustion tests paxtest (0.9.12-1) stable; urgency=low * Added ARM support paxtest (0.9.11-1) stable; urgency=low * Added display of exhaustion tests paxtest (0.9.10-1) stable; urgency=low * Fixed compilation problem reported on forums * Added display of argv/env randomization paxtest (0.9.9-1) stable; urgency=low * added SPARC/64 support * added PPC/64 support (return to function tests should be ignored for PPC64) * added 32/64bit target support * added shellode.h to easily support additional architectures * made paxctl generate the PT_PAX_FLAGS header for binaries that didn't have one paxtest (0.9.7-1) stable; urgency=low * Fixed some tests on OpenBSD and FreeBSD (thanks to paxtest@hunger.hu and mux@freebsd.org) * Fixed return address acquisition, still gcc specific * Switched to paxctl on gentoo * Fixed setting up LD_LIBRARY_PATH in genpaxtest (Peter S. Mazinger) * Added uClibc support (Peter S. Mazinger) * Fixed the executable shared library data/bss tests (thanks to paxtest@hunger.hu) paxtest (0.9.6-1) stable; urgency=low * Made the do_mprotect() call in body.c optional, thereby introducing two modes: script kiddie mode (which does not perform the do_mprotect()) and blackhat mode, which does. * Added a README file * Added Adamantix paxtest results * Removed -etdyn from the Adamantix make file * Replaced mprotect() in body.c with pthread calls (which eventually have the same result) * Added a nested function, to measure the effect of nested functions on the level of protection. * Added paxtest result from Gentoo hardened (thanks to Ned Ludd) * Added a new Makefile for Gentoo (thanks to Ned Ludd) * Fixed spelling errors (thanks to pageexec@freemail.hu) -- Peter Busser Wed, 25 Feb 2004 20:24:53 +0200 paxtest (0.9.5-1) unstable; urgency=low * Fixed the shlibbss and shlibdata tests (pageexec@freemail.hu) * Non-executable page tests expose incomplete implementations (pageexec@freemail.hu) -- Peter Busser Tue, 04 Nov 2003 16:37:26 +0200 paxtest (0.9.4-1) unstable; urgency=low * Fixed mprotanon (pageexec@freemail.hu) * Fixed rettofunc[12] (pageexec@freemail.hu) * Fixed shared library data/bss tests (pageexec@freemail.hu) * Introduced return-to-libc detection as proof-of-concept (pageexec@freemail.hu) -- Peter Busser Tue, 22 Oct 2003 21:00:05 +0200 paxtest (0.9.3-1) unstable; urgency=low * Changed e-mail addresses in source files to peter@adamantix.org * Added copyright message printing in the run script. * Upgraded to chpax v0.5 (pageexec@freemail.hu) * Split randheap in two parts, one as ET_EXEC and the other as ET_DYN -- Peter Busser Sun, 12 Oct 2003 10:58:52 +0200 paxtest (0.9.0-1) unstable; urgency=low * Initial Release. -- Peter Busser Mon, 19 May 2003 13:44:39 +0200 paxtest-0.9.15/debian/manpage.sgml.ex0000644000000000000000000001070012743042554016131 0ustar rootroot manpage.1'. You may view the manual page with: `docbook-to-man manpage.sgml | nroff -man | less'. A typical entry in a Makefile or Makefile.am is: manpage.1: manpage.sgml docbook-to-man $< > $@ The docbook-to-man binary is found in the docbook-to-man package. Please remember that if you create the nroff version in one of the debian/rules file targets (such as build), you will need to include docbook-to-man in your Build-Depends control field. --> FIRSTNAME"> SURNAME"> May 19, 2003"> SECTION"> peter@dev"> PAXTEST"> Debian"> GNU"> ]>
&dhemail;
&dhfirstname; &dhsurname; 2001 &dhusername; &dhdate;
&dhucpackage; &dhsection; &dhpackage; program to do something &dhpackage; DESCRIPTION This manual page documents briefly the &dhpackage; and bar commands. This manual page was written for the &debian; distribution because the original program does not have a manual page. Instead, it has documentation in the &gnu; Info format; see below. &dhpackage; is a program that... OPTIONS These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. For a complete description, see the Info files. Show summary of options. Show version of program. SEE ALSO bar (1), baz (1). The programs are documented fully by The Rise and Fall of a Fooish Bar available via the Info system. AUTHOR This manual page was written by &dhusername; &dhemail; for the &debian; system (but may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.
paxtest-0.9.15/debian/docs0000644000000000000000000000013212743042554014073 0ustar rootrootCOPYING README results/Results.README results/Adamantix.kiddie results/Adamantix.blackhat paxtest-0.9.15/debian/rules0000644000000000000000000000400112743042554014274 0ustar rootroot#!/usr/bin/make -f # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 # This is the debhelper compatibility version to use. export DH_COMPAT=3 # # The directory where the test programs and shared library are going to live # RUNDIR=/usr/lib/paxtest export RUNDIR # # The directory where the test script (paxtest) is going to live # BINDIR=/usr/bin export BINDIR ifneq (,$(findstring debug,$(DEB_BUILD_OPTIONS))) CFLAGS += -g endif ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS))) INSTALL_PROGRAM += -s endif configure: configure-stamp configure-stamp: dh_testdir # Add here commands to configure the package. touch configure-stamp build: build-stamp build-stamp: configure-stamp dh_testdir # Add here commands to compile the package. $(MAKE) -f Makefile.Adamantix #/usr/bin/docbook-to-man debian/paxtest.sgml > paxtest.1 touch build-stamp clean: dh_testdir dh_testroot rm -f build-stamp configure-stamp # Add here commands to clean up after the build process. -$(MAKE) -f Makefile.Adamantix clean dh_clean install: build dh_testdir dh_testroot dh_clean -k dh_installdirs # Add here commands to install the package into debian/paxtest. $(MAKE) -f Makefile.Adamantix install DESTDIR=$(CURDIR)/debian/paxtest # Build architecture-independent files here. binary-indep: build install # We have nothing to do by default. # Build architecture-dependent files here. binary-arch: build install dh_testdir dh_testroot # dh_installdebconf dh_installdocs dh_installexamples dh_installmenu # dh_installlogrotate # dh_installemacsen # dh_installpam # dh_installmime # dh_installinit dh_installcron dh_installman dh_installinfo # dh_undocumented dh_installchangelogs dh_link dh_strip dh_compress dh_fixperms # dh_makeshlibs dh_installdeb # dh_perl dh_shlibdeps dh_gencontrol dh_md5sums dh_builddeb binary: binary-indep binary-arch .PHONY: build clean binary-indep binary-arch binary install configure paxtest-0.9.15/debian/control0000644000000000000000000000171612743042554014634 0ustar rootrootSource: paxtest Section: main Priority: optional Maintainer: Peter Busser Build-Depends: debhelper (>> 3.0.0), gcc, binutils Standards-Version: 3.5.2 Package: paxtest Architecture: i386 Depends: ${shlibs:Depends} Description: a-: Test suite for the PaX kernel patch PaX is a Linux kernel patch which adds much stricter control on how memory is being used by applications. A normal Linux kernel leaves the control to the application and does not implement any enforcement. Especially buffer overflow attacks benefit from the absense of kernel enforced memory control. PaX tries to do its best to enforce this control of memory used by applications, thereby making it harder to successfully exploit buffer overflows. . Paxtest provides a regression test suite that covers most (but not all) of PaX functionality. It can also be used to test other memory protection patches. . For more information about PaX, see http://pax.grsecurity.net/. paxtest-0.9.15/debian/copyright0000644000000000000000000000060712743042554015162 0ustar rootrootpaxtest is copyright (c)2003 by Peter Busser Paxtest is licened under the terms of the GNU General Public License (GPL), version 2.0 or later, as published by the Free Software Foundation. See the file COPYING [included], /usr/share/common-licenses/GPL, or for the terms of the latest version of the GNU General Public License. paxtest-0.9.15/mprotheap.c0000644000000000000000000000205012743042554014142 0ustar rootroot/* mprotheap.c - Tests whether code on the heap can be executed after trying to * use mprotect() to make it executable. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable heap (mprotect) "; void doit( void ) { char *buf; fptr func; buf = malloc( MAX_SHELLCODE_LEN ); if( buf == NULL ) { fprintf( stderr, "Out of memory\n" ); exit( 1 ); } copy_shellcode(buf); /* Try to make the buffer executable by using mprotect() */ /* Due to a FreeBSD bug PROT_READ is required */ do_mprotect( buf, MAX_SHELLCODE_LEN, PROT_READ|PROT_EXEC ); /* Convert the pointer to a function pointer */ func = (fptr)buf; /* Call the code in the buffer */ func(); do_mprotect( buf, MAX_SHELLCODE_LEN, PROT_READ|PROT_WRITE ); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/randheap1.c0000644000000000000000000000060512743042554014012 0ustar rootroot/* randheap1.c - Tests the randomization of the heap of ET_EXEC main executable. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Heap randomization test (ET_EXEC) "; const char testprog[] = RUNDIR"/getheap1"; paxtest-0.9.15/rettofunc1x.c0000644000000000000000000000176512743042554014441 0ustar rootroot/* rettofunc1.c - Tests whether return to function exploits work or not. * * Copyright (c)2003,2004 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include "body.h" #include "paxtest.h" const char testname[] = "Return to function (strcpy, PIE) "; static const fptr overflow[32] = { itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, NULL }; void doit( void ) { char buf[sizeof(unsigned long)]; if (strlen((const char *)overflow) > sizeof(overflow[0])) { forced_strcpy( buf, (const char *)overflow ); } else { fprintf( stderr, "paxtest: return address contains a NULL byte.\n" ); exit(1); } } paxtest-0.9.15/getstack.c0000644000000000000000000000056412743042554013760 0ustar rootroot/* getstack.c - Get the location of the stack and print it * (Idea by Peter Roozemaal) * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include int main( int argc, char *argv[] ){ char a; printf( "%p\n", &a ); exit( 0 ); } paxtest-0.9.15/mprotdata.c0000644000000000000000000000173712743042554014151 0ustar rootroot/* mprotdata.c - Tests whether code in the .data segment can be executed after * trying to use mprotect() to make it executable. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable data (mprotect) "; char buf[PAGE_SIZE_MAX] __pagealigned = { 'A' }; void doit( void ) { fptr func; copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)&buf; /* Try to make the data executable first by using mprotect */ /* Due to an OpenBSD bug PROT_READ is required */ do_mprotect( &buf, sizeof(buf), PROT_READ|PROT_EXEC ); /* Call the code in the buffer */ func(); do_mprotect( &buf, sizeof(buf), PROT_READ|PROT_WRITE ); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/rettofunc1.c0000644000000000000000000000176012743042554014244 0ustar rootroot/* rettofunc1.c - Tests whether return to function exploits work or not. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include "body.h" #include "paxtest.h" const char testname[] = "Return to function (strcpy) "; static const fptr overflow[32] = { itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, NULL }; void doit( void ) { char buf[sizeof(unsigned long)]; if (strlen((const char *)overflow) > sizeof(overflow[0])) { forced_strcpy( buf, (const char *)overflow ); } else { fprintf( stderr, "paxtest: return address contains a NULL byte.\n" ); exit(1); } } paxtest-0.9.15/randmain1.c0000644000000000000000000000057012743042554014022 0ustar rootroot/* randmain1.c - Tests the randomization of ET_EXEC main executable * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Main executable randomization (ET_EXEC) "; const char testprog[] = RUNDIR"/getmain1"; paxtest-0.9.15/ChangeLog0000644000000000000000000001011512743042554013552 0ustar rootrootpaxtest (0.9.15-1) stable; urgency=low * Change default location of logfile & add info to log file, from Javier Fernandez-Sanguino (jfs@debian.org) * Squelch _FORTIFY_SOURCE redefinition warning and various other compiler warnings, from Kees Cook (keescook@chromium.org) * Validate that ET_DYN is separately randomized from shlibs From Kees Cook (with fixes from Brad Spengler) * Show output during result collection, from Kees Cook * Free/HardenedBSD support, from Oliver Pinter (oliver.pinter@hardenedbsd.org) * Two build fixes from David Sterba (dave@jikos.cz) * Use correct address for PIE, didn't affect PaX results as it uses the same entropy levels for PIE and mmap, from Ismael Ripoll and Hector Marco-Gisbert paxtest (0.9.14-1) stable; urgency=low * Various fixes/cleanups including ensuring an overflowing strcpy/memcpy isn't optimized away, from Mathias Krause (mathias.krause@secunet.com) * Updated the representative results paxtest (0.9.13-1) stable; urgency=low * Added VDSO randomization test * Added basic entropy quality testing, subtracts weak bits from entropy count * Increased iterations for all randomization tests but the exhaustion tests paxtest (0.9.12-1) stable; urgency=low * Added ARM support paxtest (0.9.11-1) stable; urgency=low * Added display of exhaustion tests paxtest (0.9.10-1) stable; urgency=low * Fixed compilation problem reported on forums * Added display of argv/env randomization paxtest (0.9.9-1) stable; urgency=low * added SPARC/64 support * added PPC/64 support (return to function tests should be ignored for PPC64) * added 32/64bit target support * added shellode.h to easily support additional architectures * made paxctl generate the PT_PAX_FLAGS header for binaries that didn't have one paxtest (0.9.7-1) stable; urgency=low * Fixed some tests on OpenBSD and FreeBSD (thanks to paxtest@hunger.hu and mux@freebsd.org) * Fixed return address acquisition, still gcc specific * Switched to paxctl on gentoo * Fixed setting up LD_LIBRARY_PATH in genpaxtest (Peter S. Mazinger) * Added uClibc support (Peter S. Mazinger) * Fixed the executable shared library data/bss tests (thanks to paxtest@hunger.hu) paxtest (0.9.6-1) stable; urgency=low * Made the do_mprotect() call in body.c optional, thereby introducing two modes: script kiddie mode (which does not perform the do_mprotect()) and blackhat mode, which does. * Added a README file * Added Adamantix paxtest results * Removed -etdyn from the Adamantix make file * Replaced mprotect() in body.c with pthread calls (which eventually have the same result) * Added a nested function, to measure the effect of nested functions on the level of protection. * Added paxtest result from Gentoo hardened (thanks to Ned Ludd) * Added a new Makefile for Gentoo (thanks to Ned Ludd) * Fixed spelling errors (thanks to pageexec@freemail.hu) -- Peter Busser Wed, 25 Feb 2004 20:24:53 +0200 paxtest (0.9.5-1) unstable; urgency=low * Fixed the shlibbss and shlibdata tests (pageexec@freemail.hu) * Non-executable page tests expose incomplete implementations (pageexec@freemail.hu) -- Peter Busser Tue, 04 Nov 2003 16:37:26 +0200 paxtest (0.9.4-1) unstable; urgency=low * Fixed mprotanon (pageexec@freemail.hu) * Fixed rettofunc[12] (pageexec@freemail.hu) * Fixed shared library data/bss tests (pageexec@freemail.hu) * Introduced return-to-libc detection as proof-of-concept (pageexec@freemail.hu) -- Peter Busser Tue, 22 Oct 2003 21:00:05 +0200 paxtest (0.9.3-1) unstable; urgency=low * Changed e-mail addresses in source files to peter@adamantix.org * Added copyright message printing in the run script. * Upgraded to chpax v0.5 (pageexec@freemail.hu) * Split randheap in two parts, one as ET_EXEC and the other as ET_DYN -- Peter Busser Sun, 12 Oct 2003 10:58:52 +0200 paxtest (0.9.0-1) unstable; urgency=low * Initial Release. -- Peter Busser Mon, 19 May 2003 13:44:39 +0200 paxtest-0.9.15/execdata.c0000644000000000000000000000122212743042554013721 0ustar rootroot/* execdata.c - Tests whether code in the .data segment can be executed * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable data "; char buf[MAX_SHELLCODE_LEN] = { 'A' }; void doit( void ) { fptr func; copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)&buf; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/randstack2.c0000644000000000000000000000056412743042554014207 0ustar rootroot/* randstack.c - Tests the randomization of the stack pointer. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Stack randomization test (PAGEEXEC) "; const char testprog[] = RUNDIR"/getstack2"; paxtest-0.9.15/getamap.c0000644000000000000000000000114512743042554013565 0ustar rootroot/* getamap.c - Get the address of the first anonymous mapping * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif int main( int argc, char *argv[] ) { char *buf; buf = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if( buf == MAP_FAILED ) { fprintf( stderr, "mmap() returned NULL\n" ); exit( 1 ); } printf( "%p\n", buf ); exit( 0 ); } paxtest-0.9.15/getshlibdelta.c0000644000000000000000000000211512743042554014760 0ustar rootroot/* getshlibdelta.c - Get the delta between a function in .text and a function in a * shared library and print it * * Copyright (c)2003 by Peter Busser * Copyright (c)2014 by Kees Cook * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include /* OpenBSD 3.5 doesn't define RTLD_DEFAULT */ /* OpenBSD 3.6 does but it doesn't actually handle (segfaults on) RTLD_DEFAULT, sigh... */ #ifdef __OpenBSD__ #undef RTLD_DEFAULT #define RTLD_DEFAULT "libc.so" #endif void __attribute__ ((noinline)) foo(void) { unsigned long ptr = (unsigned long)__builtin_return_address(0); void *handle; handle = dlopen( RTLD_DEFAULT, RTLD_LAZY ); if (handle != NULL) { unsigned long sprintf; dlerror(); /* clear any errors */ sprintf = (unsigned long)dlsym( handle, "sprintf" ); if (dlerror() == NULL) { printf( "%p\n", (void *)(ptr - sprintf) ); } dlclose( handle ); } } int main(int argc, char *argv[]) { foo(); exit(0); } paxtest-0.9.15/mprotshdata.c0000644000000000000000000000352012743042554014474 0ustar rootroot/* mprotshdata.c - Tests whether code in the .data segment of a shared library * can be executed after trying to use mprotect() to make it * executable. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable shared library data (mprotect)"; void doit( void ) { fptr func; char *shdata, *shdata2; void *handle1, *handle2; handle1 = dlopen( "shlibtest.so", RTLD_LAZY ); if( handle1 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shdata = dlsym( handle1, "shdata" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shdata", "shlibtest.so" ); exit( 1 ); } handle2 = dlopen( "shlibtest2.so", RTLD_LAZY ); if( handle2 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shdata2 = dlsym( handle2, "shdata2" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shdata2", "shlibtest2.so" ); exit( 1 ); } copy_shellcode(shdata); copy_shellcode(shdata2); /* Convert the pointer to a function pointer */ func = shdata < shdata2 ? (fptr)shdata : (fptr)shdata2; /* Try to make the memory region executable by using mprotect() */ /* Due to an OpenBSD bug PROT_READ is required */ do_mprotect( func, MAX_SHELLCODE_LEN, PROT_READ|PROT_EXEC ); /* Call the code in the buffer */ func(); do_mprotect( func, MAX_SHELLCODE_LEN, PROT_READ|PROT_WRITE ); /* It worked when the function returns */ itworked(); dlclose( handle1 ); dlclose( handle2 ); } paxtest-0.9.15/paxtest.h0000644000000000000000000000152112743042554013642 0ustar rootroot#ifndef _PAXTEST_H_ #define _PAXTEST_H_ #include #include /* * ARMv6 and ARMv7 do not like 64k alignment, 32k is ok */ #if defined(__arm__) && __ARM_ARCH >= 6 && __ARM_ARCH <= 7 #define PAGE_SIZE_MAX (32768) #else #define PAGE_SIZE_MAX 0x10000 /* 64k should cover most arches */ #endif #ifndef __aligned #define __aligned(x) __attribute__((aligned(x))) #endif #define __pagealigned __aligned(PAGE_SIZE_MAX) #define __use(x) asm volatile ( "" : : "m" (x) ); static inline char *forced_strcpy(char *dst, const char *src) { strcpy(dst, src); /* ensure the compiler won't optimize the strcpy() away */ __use(dst); return dst; } static inline void *forced_memcpy(void *dst, const void *src, size_t n) { memcpy(dst, src, n); /* ensure the compiler won't optimize the memcpy() away */ __use(dst); return dst; } #endif paxtest-0.9.15/README0000644000000000000000000002020512743042554012661 0ustar rootrootPaxtest v0.9.13 README file Copyright (c)2004 by Peter Busser Additional architecture/target support, tests, & fixes by Brad Spengler This file has been released under the GNU GPL version 2 or later. History: ------- When I started the Adamantix project, one of the first things I did was to add PaX functionality to the kernel. PaX is a process memory protection patch. Anything that happens outside the kernel on a UNIX system happens inside a process. There are many attacks on the Internet that try to corrupt the process memory, in order to make it do something for which it was not intended. One example of such an attack is the so called buffer overflow attack. This kind of attack is one of the most popular at this moment. PaX protects against such attacks. Or so the author claims. When I started to add PaX to Adamantix, almost nothing happened. A few libraries broke, but that was easy to fix, and that was it. I expected many programs to break. So I started to wonder: ``Does this patch really do anything?'' Instead of speculating, I decided to write a test suite. After some time, the first version of paxtest was ready. More functionality was added. With the addition of every test, it proved that PaX was working just fine. I decided to publish paxtest, because it can be useful for other people to test the functionality of the memory protection of their system(s). Compiling paxtest: ----------------- Compiling paxtest should be quite straightforward. First unpack paxtest. Then cd into the directory. And then run one of the following: make linux (to create Linux binaries) make openbsd (to create OpenBSD binaries) (Type make to get the above list.) Running paxtest: --------------- In order to run paxtest, type the following: ./paxtest kiddie (to run paxtest in script kiddie mode) or ./paxtest blackhat (to run paxtest in blackhat mode) This will create a file paxtest.log in the user's home directory. Kiddie and blackhat mode: ------------------------ Paxtest provides two modes. The first mode is the so called kiddie mode, which makes paxtest behave rather nicely. This simulates the level of sophistication displayed by script kiddies. Good results in this mode do not necessarily mean that the security level of your system is high. The second mode, the blackhat mode, makes paxtest use of a few tricks to try to get around the protection of the kernel. The attacks done by paxtest in this mode can be performed in real life by attackers too. But the level of sophistication is somewhat higher than those of the kiddie mode and the chance of success is somewhat lower. But there is still a realistic chance of success. People who are concerned about the security of their systems should look at the blackhat mode results. The tests: --------- There are two types of tests in paxtest. First there are tests which try different ways to write and then run exploit code. The more different exploits are stopped, the better the protection provided by the system. Note that the tests simulate what an exploit could (and would) do, not what an application does normally. This is especially important in the mprotect tests because some people claim that normal applicatons do not do this - indeed, but that is not what these tests are about, they simulate exploits, not applications. Second, there is a number of tests that measure the randomization of the system. Randomisation does not provide any security, but only makes it harder for the attacker to guess where to attack (it is in fact security through obscurity). It is like rearranging the furniture in a pitch dark room every time someone enters. The more random the furniture is placed, the more likely it is that someone stumbles over it. The same applies to randomization in this context, randomization makes it more likely that an attack does not succeed. In short: More random bits is better. Zero bits means: No randomization. Executable anonymous mapping Executable bss Executable data Executable heap Executable stack These tests try to write data to memory and then try to execute it as if it was executable code. This is exactly what most buffer exploits do. There are five tests, each test tests one specific memory area. Executable anonymous mapping (mprotect) Executable bss (mprotect) Executable data (mprotect) Executable heap (mprotect) Executable stack (mprotect) These tests do the same as the previous tests. But now the test also tries to disable the memory protection in the kernel using mprotect(). It changes the protection status of memory. An attacker can use it to try to switch off memory protection and execute shellcode as usual. Executable shared library bss (mprotect) Executable shared library data (mprotect) These tests try to overwrite two different data areas in a shared library. After that, it tries to execute the data as if it was code. Again, these tests try to switch off the memory protection using mprotect(). Anonymous mapping randomization test Anonymous mappings are used for dynamically allocating memory in a program. This test tries to figure out the number of random bits used when such an anonymous mapping is requested. More bits is better. Heap randomization test (ET_EXEC) Heap randomization test (ET_DYN) The heap is used for allocating small chunks of memory in a program. There there are two different types of executables, ET_EXEC (normal executables) and ET_DYN (basically executable shared libraries). The randomization can depend on the kind of executable, therefore there are two tests. Most Linux distributions ship with ET_EXEC executables only. So for those the ET_EXEC randomization is the most relevant. Adamantix ships with mostly ET_DYN executables, so the ET_EXEC randomization is not very relevant, but the ET_DYN randomization is. Normally ET_DYN randomization is bigger than the ET_EXEC randomisation. Main executable randomization (ET_EXEC) Main executable randomization (ET_DYN) Same here, two tests, because the two different types of executables can have different randomization. Shared library randomization test Shared libraries can be located at random addresses too, which is what this test tries to find out. Stack randomization test (SEGMEXEC) Stack randomization test (PAGEEXEC) The stack is used for storing intermediate data. It also contains addresses that influence the way programs run. That combination makes the stack a popular memory area for attacks. Randomisation makes it harder though, which is what these test try to find out. Return to function (strcpy) Return to function (strcpy, RANDEXEC) Return to function (memcpy) Return to function (memcpy, RANDEXEC) Return to function attacks are very nasty. These tests are hard to stop by kernel patches, but they show that there you should not expect perfect protection from this kind of security patches. Executable shared library bss Executable shared library data These tests try to overwrite two different data areas in a shared library. After that, it tries to execute the data as if it was code. Writable text segments When an attacker can overwrite code, he can basically alter the program while it runs. This test tries to do that. Perfect protection: ------------------ Perfect protection is not possible. That is also the reason why there are so called return to function tests in paxtest. PaX does not prevent return to function attacks. Neither do any of the other memory protection patches. But it is important that people who use kernel patches like PaX do not get a false sense of security. As the PaX documentation points out: There are three different classes of attacks, and at this moment PaX can only guarantee protection against one of them. Further reading: --------------- PaX home page: http://pax.grsecurity.net/ PaX mailing list: http://lists.adamantix.org/ PaX documentation (also a thorough introduction into memory protection): http://pax.grsecurity.net/docs/ An article I wrote about PaX has been published in Linux Magazine. The whole article is available on-line as PDF. It is not very technical, but describes what memory protection is and why it is important. It can be found here: http://www.linux-magazine.com/issue/40 paxtest-0.9.15/.gitignore0000644000000000000000000000111712743042554013772 0ustar rootroot*.o *.core core anonmap execbss execdata execheap execstack getamap getarg1 getarg2 getexhaust1 getexhaust2 getheap1 getheap2 getmain1 getmain2 getshlib getshlibdelta1 getshlibdelta2 getstack1 getstack2 getvdso mprotanon mprotbss mprotdata mprotheap mprotshbss mprotshdata mprotstack paxtest paxtest.log randamap randarg1 randarg2 randexhaust randexhaust1 randexhaust2 randheap1 randheap2 randmain1 randmain2 randshlib randshlibdelta1 randshlibdelta2 randstack1 randstack2 rettofunc1 rettofunc1x rettofunc2 rettofunc2x randvdso shlibbss shlibdata shlibtest.so shlibtest2.so writetext paxbin paxtest-0.9.15/shlibtest.c0000644000000000000000000000067212743042554014154 0ustar rootroot/* shlibtest.c - Shared library used by the shared library tests. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include "paxtest.h" char shbss[PAGE_SIZE_MAX] __pagealigned; char shdata[PAGE_SIZE_MAX] __pagealigned = { 'A' }; /* A function which does nothing, it only exists so it can be referenced */ int shlibtest( void ) { return 1; } paxtest-0.9.15/randarg1.c0000644000000000000000000000035112743042554013644 0ustar rootroot/* randarg.c - Tests the randomization of arguments/environment * */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Arg/env randomization test (SEGMEXEC) "; const char testprog[] = RUNDIR"/getarg1"; paxtest-0.9.15/randshlib.c0000644000000000000000000000056712743042554014124 0ustar rootroot/* randshlib.c - Tests the randomization of shared library loading * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Shared library randomization test "; const char testprog[] = RUNDIR"/getshlib"; paxtest-0.9.15/getarg.c0000644000000000000000000000027312743042554013421 0ustar rootroot/* getarg.c - Get the location of an argument and print it * */ #include #include int main( int argc, char *argv[] ){ printf( "%p\n", argv[0] ); exit( 0 ); } paxtest-0.9.15/results/0000755000000000000000000000000012743042554013503 5ustar rootrootpaxtest-0.9.15/results/PaX_x86_64.blackhat0000644000000000000000000000420712743042554016707 0ustar rootrootPaXtest - Copyright(c) 2003-2014 by Peter Busser and Brad Spengler Released under the GNU Public Licence version 2 or later Mode: blackhat Linux debian 4.1.3-grsec+ #2 SMP PREEMPT Sun Jul 26 19:22:38 EDT 2015 x86_64 GNU/Linux Executable anonymous mapping : Killed Executable bss : Killed Executable data : Killed Executable heap : Killed Executable stack : Killed Executable shared library bss : Killed Executable shared library data : Killed Executable anonymous mapping (mprotect) : Killed Executable bss (mprotect) : Killed Executable data (mprotect) : Killed Executable heap (mprotect) : Killed Executable stack (mprotect) : Killed Executable shared library bss (mprotect) : Killed Executable shared library data (mprotect): Killed Writable text segments : Killed Anonymous mapping randomization test : 28 quality bits (guessed) Heap randomization test (ET_EXEC) : 22 quality bits (guessed) Heap randomization test (PIE) : 35 quality bits (guessed) Main executable randomization (ET_EXEC) : No randomization Main executable randomization (PIE) : 27 quality bits (guessed) Shared library randomization test : 28 quality bits (guessed) VDSO randomization test : 28 quality bits (guessed) Stack randomization test (SEGMEXEC) : 35 quality bits (guessed) Stack randomization test (PAGEEXEC) : 35 quality bits (guessed) Arg/env randomization test (SEGMEXEC) : 39 quality bits (guessed) Arg/env randomization test (PAGEEXEC) : 39 quality bits (guessed) Randomization under memory exhaustion @~0: 28 bits (guessed) Randomization under memory exhaustion @0 : 28 bits (guessed) Return to function (strcpy) : paxtest: return address contains a NULL byte. Return to function (memcpy) : Vulnerable Return to function (strcpy, PIE) : paxtest: return address contains a NULL byte. Return to function (memcpy, PIE) : Vulnerable paxtest-0.9.15/results/HardenedBSD-11_x86_64.kiddie0000644000000000000000000000434512743042554020164 0ustar rootrootPaXtest - Copyright(c) 2003-2014 by Peter Busser and Brad Spengler Released under the GNU Public Licence version 2 or later Mode: kiddie FreeBSD opn 11.0-CURRENT-HBSD FreeBSD 11.0-CURRENT-HBSD #24 f60dfcf(op/hardenedbsd/current/master): Mon Sep 21 19:26:46 CEST 2015 root@opn:/usr/obj/usr/src/sys/OP-HBSD amd64 Executable anonymous mapping : Killed Executable bss : Killed Executable data : Killed Executable heap : Killed Executable stack : Killed Executable shared library bss : Killed Executable shared library data : Killed Executable anonymous mapping (mprotect) : Killed Executable bss (mprotect) : Killed Executable data (mprotect) : Killed Executable heap (mprotect) : Killed Executable stack (mprotect) : Killed Executable shared library bss (mprotect) : Killed Executable shared library data (mprotect): Killed Writable text segments : Vulnerable Anonymous mapping randomization test : 30 quality bits (guessed) Heap randomization test (ET_EXEC) : 21 quality bits (guessed) Heap randomization test (PIE) : 22 quality bits (guessed) Main executable randomization (ET_EXEC) : No randomization Main executable randomization (PIE) : 30 quality bits (guessed) Shared library randomization test : 30 quality bits (guessed) VDSO randomization test : 28 quality bits (guessed) Stack randomization test (SEGMEXEC) : 41 quality bits (guessed) Stack randomization test (PAGEEXEC) : 41 quality bits (guessed) Arg/env randomization test (SEGMEXEC) : 42 quality bits (guessed) Arg/env randomization test (PAGEEXEC) : 42 quality bits (guessed) Randomization under memory exhaustion @~0: 30 bits (guessed) Randomization under memory exhaustion @0 : 30 bits (guessed) Return to function (strcpy) : paxtest: return address contains a NULL byte. Return to function (memcpy) : Vulnerable Return to function (strcpy, PIE) : paxtest: return address contains a NULL byte. Return to function (memcpy, PIE) : Vulnerable paxtest-0.9.15/results/PaX_x86.blackhat0000644000000000000000000000410012743042554016366 0ustar rootrootPaXtest - Copyright(c) 2003-2014 by Peter Busser and Brad Spengler Released under the GNU Public Licence version 2 or later Mode: blackhat Linux debian 4.1.3-grsec+ #2 SMP PREEMPT Sun Jul 26 19:22:38 EDT 2015 x86_64 GNU/Linux Executable anonymous mapping : Killed Executable bss : Killed Executable data : Killed Executable heap : Killed Executable stack : Killed Executable shared library bss : Killed Executable shared library data : Killed Executable anonymous mapping (mprotect) : Killed Executable bss (mprotect) : Killed Executable data (mprotect) : Killed Executable heap (mprotect) : Killed Executable stack (mprotect) : Killed Executable shared library bss (mprotect) : Killed Executable shared library data (mprotect): Killed Writable text segments : Killed Anonymous mapping randomization test : 16 quality bits (guessed) Heap randomization test (ET_EXEC) : 22 quality bits (guessed) Heap randomization test (PIE) : 24 quality bits (guessed) Main executable randomization (ET_EXEC) : No randomization Main executable randomization (PIE) : 16 quality bits (guessed) Shared library randomization test : 16 quality bits (guessed) VDSO randomization test : 16 quality bits (guessed) Stack randomization test (SEGMEXEC) : 24 quality bits (guessed) Stack randomization test (PAGEEXEC) : 24 quality bits (guessed) Arg/env randomization test (SEGMEXEC) : 28 quality bits (guessed) Arg/env randomization test (PAGEEXEC) : 28 quality bits (guessed) Randomization under memory exhaustion @~0: 16 bits (guessed) Randomization under memory exhaustion @0 : 8 bits (guessed) Return to function (strcpy) : Vulnerable Return to function (memcpy) : Vulnerable Return to function (strcpy, PIE) : Vulnerable Return to function (memcpy, PIE) : Vulnerable paxtest-0.9.15/randarg2.c0000644000000000000000000000035112743042554013645 0ustar rootroot/* randarg.c - Tests the randomization of arguments/environment * */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Arg/env randomization test (PAGEEXEC) "; const char testprog[] = RUNDIR"/getarg2"; paxtest-0.9.15/getmain.c0000644000000000000000000000062312743042554013573 0ustar rootroot/* getmain.c - Get the address of the main function and print it * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include void __attribute__ ((noinline)) foo(void) { printf( "%p\n", __builtin_return_address(0) ); } int main( int argc, char *argv[] ) { foo(); exit(0); } paxtest-0.9.15/mprotstack.c0000644000000000000000000000152412743042554014337 0ustar rootroot/* mprotstack.c - Tests whether code on the stack can be executed after trying * to make it executable by using mprotect(). * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable stack (mprotect) "; void doit( void ) { char buf[MAX_SHELLCODE_LEN]; fptr func; copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)&buf; /* Try to make the stack executable first */ do_mprotect( &buf, sizeof(buf), PROT_READ|PROT_WRITE|PROT_EXEC ); /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/randexhaust2.c0000644000000000000000000000046612743042554014564 0ustar rootroot/* randexhaust2.c - Tests the randomization under memory exhaustion * when trying to get a fixed address at the bottom of the address space */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Randomization under memory exhaustion @0 "; const char testprog[] = RUNDIR"/getexhaust2"; paxtest-0.9.15/mprotbss.c0000644000000000000000000000171712743042554014025 0ustar rootroot/* mprotbss.c - Tests whether code in the .bss segment can be executed after * trying to use mprotect() to make it executable * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable bss (mprotect) "; char buf[PAGE_SIZE_MAX] __pagealigned; void doit( void ) { fptr func; copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)&buf; /* Try to make the bss executable first by using mprotect */ /* Due to a FreeBSD bug PROT_READ is required */ do_mprotect( &buf, sizeof(buf), PROT_READ|PROT_EXEC ); /* Call the code in the buffer */ func(); do_mprotect( &buf, sizeof(buf), PROT_READ|PROT_WRITE ); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/getexhaust2.c0000644000000000000000000000250312743042554014411 0ustar rootroot#include #include #include #include int main(void) { char *addr; int can_map_above_stack = 0; char **maps; unsigned int num_maps = 0; /* return normal mmap randomization on 64bit systems */ if (sizeof(unsigned long) == 8) { addr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); goto out; } maps = (char **)calloc(1024 * 1024, sizeof(char *)); while (1) { addr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (addr == MAP_FAILED) break; if (addr > (char *)&addr) can_map_above_stack = 1; maps[num_maps++] = addr; } if (!can_map_above_stack) { /* upper end is randomized due to the stack base and PROT_NONE gap inserted above stack */ unsigned int map_size = 0x1000; while (1) { munmap(maps[--num_maps], 0x1000); addr = mmap(NULL, map_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (addr == MAP_FAILED) break; munmap(addr, map_size); map_size += 0x1000; } /* can't insert any bigger mapping, filled mmap -> stack gap, next deallocation is lowest mappable address */ } munmap(maps[num_maps - 1], 0x1000); addr = mmap(NULL, 0x1000, PROT_READ | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); out: printf("%p\n", addr); return 0; } paxtest-0.9.15/shlibbss.c0000644000000000000000000000275312743042554013766 0ustar rootroot/* shlibbss.c - Tests whether code in the .bss segment of a shared library can * be executed * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable shared library bss "; void doit( void ) { char *shbss; char *shbss2; fptr func; void *handle1, *handle2; handle1 = dlopen( "shlibtest.so", RTLD_LAZY ); if( handle1 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shbss = dlsym( handle1, "shbss" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shbss", "shlibtest.so" ); exit( 1 ); } handle2 = dlopen( "shlibtest2.so", RTLD_LAZY ); if( handle2 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shbss2 = dlsym( handle2, "shbss2" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shbss2", "shlibtest2.so" ); exit( 1 ); } copy_shellcode(shbss); copy_shellcode(shbss2); /* Convert the pointer to a function pointer */ func = shbss < shbss2 ? (fptr)shbss : (fptr)shbss2; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); dlclose( handle1 ); dlclose( handle2 ); } paxtest-0.9.15/interp.c0000644000000000000000000000066112743042554013452 0ustar rootroot#ifdef __FreeBSD__ const char __invoke_dynamic_linker__[] __attribute__ ((section (".interp"))) = "/libexec/ld-elf.so.1"; #elif defined(__linux__) && defined(__UCLIBC__) const char __invoke_dynamic_linker__[] __attribute__ ((section (".interp"))) = "/lib/ld-uClibc.so.0"; #elif defined(__linux__) const char __invoke_dynamic_linker__[] __attribute__ ((section (".interp"))) = "/lib/ld-linux.so.2"; #else #error unsupported OS #endif paxtest-0.9.15/randvdso.c0000644000000000000000000000055012743042554013766 0ustar rootroot/* randvdso.c - Tests the randomization of VDSO * * Copyright (c) 2014 by Brad Spengler * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "VDSO randomization test "; const char testprog[] = RUNDIR"/getvdso"; paxtest-0.9.15/getexhaust1.c0000644000000000000000000000116312743042554014411 0ustar rootroot#include #include #include int main(void) { char *addr; char *last_addr; /* return normal mmap randomization on 64bit systems */ if (sizeof(unsigned long) == 8) { addr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); goto out; } while (1) { addr = mmap(NULL, 0x1000, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (addr == MAP_FAILED) break; last_addr = addr; } munmap(last_addr, 0x1000); addr = mmap(NULL, 0x1000, PROT_READ | PROT_EXEC, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); out: printf("%p\n", addr); return 0; } paxtest-0.9.15/COPYING0000644000000000000000000004312712743042554013044 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19yy name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. paxtest-0.9.15/shlibtest2.c0000644000000000000000000000067612743042554014242 0ustar rootroot/* shlibtest2.c - Shared library used by the shared library tests. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include "paxtest.h" char shbss2[PAGE_SIZE_MAX] __pagealigned; char shdata2[PAGE_SIZE_MAX] __pagealigned = { 'A' }; /* A function which does nothing, it only exists so it can be referenced */ int shlibtest2( void ) { return 1; } paxtest-0.9.15/writetext.c0000644000000000000000000000257212743042554014213 0ustar rootroot/* writetext.c - Test whether a .text sections can be written * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include #include #include "body.h" const char testname[] = "Writable text segments "; extern int shlibtest( void ); static void sigsegv( int sig ) { printf( "Killed\n" ); exit( 1 ); } void doit( void ) { char *buf; char c; buf = (char*)shlibtest; signal( SIGSEGV, sigsegv ); /* Try to make the text writable first by using mprotect * * Some people like to disable this call to make the results look * better for their system. * * The purpose of the mprotect() here is to *really* try to write to * that piece of executable memory. If you want to know whether a box * can be opened or not, you try to pull it open. Just looking at it, * seeing that it is closed, and therefore concluding that it cannot * be opened is rather lame. * * But then, it is of course easier to get good paxtest results by * disabling this mprotect than to fix your kernel code and userland. */ do_mprotect( buf, 4096, PROT_READ|PROT_WRITE|PROT_EXEC ); /* Try to write something */ *buf = 'X'; /* It worked when the function returns */ itworked(); } paxtest-0.9.15/genpaxtest0000644000000000000000000000330712743042554014112 0ustar rootroot#!/bin/sh # # Script to run all the PaX memory protection tests # # Copyright(c) 2003,2004 by Peter Busser # This file has been released under the GNU Public Licence version 2 or later. # See the file COPYING for details. # echo $RUNDIR if [ "${RUNDIR}" = "" ] then RUNDIR=. fi cat << __here__ > paxtest #!/bin/sh if [ \$# = 1 -o \$# = 2 ] then if [ "\$1" = "kiddie" ] then PAXTEST_MODE=0 shift elif [ "\$1" = "blackhat" ] then PAXTEST_MODE=1 shift else echo "usage: paxtest [kiddie|blackhat] [logfile]" exit 1 fi else echo "usage: paxtest [kiddie|blackhat] [logfile]" exit 1 fi LOG=\$HOME/paxtest.log [ -n "\$1" ] && LOG=\$1 touch "\$LOG" if [ ! -e "\$LOG" ]; then echo "Could not create logfile in \$LOG" >&2 exit 1 fi export PAXTEST_MODE if [ "\${LD_LIBRARY_PATH}" = "" ] then LD_LIBRARY_PATH=${RUNDIR} else LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:${RUNDIR} fi export LD_LIBRARY_PATH cat <<__end__ | tee \$LOG PaXtest - Copyright(c) 2003-2016 by Peter Busser and Brad Spengler Released under the GNU Public Licence version 2 or later __end__ echo "Mode: \$PAXTEST_MODE" >>\$LOG if [ "\$PAXTEST_MODE" -eq 0 ]; then echo -n "Kiddie" >>\$LOG fi if [ "\$PAXTEST_MODE" -eq 1 ]; then echo -n "Blackhat" >>\$LOG fi echo >>\$LOG echo "Kernel: " >>\$LOG uname -a >>\$LOG echo >>\$LOG if [ -e /usr/bin/lsb_release ]; then echo "Relase information: " >>\$LOG lsb_release -a 2>/dev/null >>\$LOG fi echo "Test results:" >>\$LOG echo "Writing output to \$LOG" echo 'It may take a while for the tests to complete' echo "Test results:" for i in $* do ${RUNDIR}/\$i || echo done 2>&1 | tee -a \$LOG echo __here__ chmod 755 paxtest exit 0 paxtest-0.9.15/randheap2.c0000644000000000000000000000060112743042554014007 0ustar rootroot/* randheap2.c - Tests the randomization of the heap of PIE main executable. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Heap randomization test (PIE) "; const char testprog[] = RUNDIR"/getheap2"; paxtest-0.9.15/body.c0000644000000000000000000000451612743042554013111 0ustar rootroot/* body.c - This part is shared by the test programs (except for the randomization * tests) * * Copyright (c)2003,2004 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include #include #include #include #include #include #include #include #include "body.h" static void *test_thread(void *p) { pause(); return NULL; } int main( int argc, char *argv[] ) { int status; char *mode; /* * This defaults to 1 as a safety mechanism. It is better to fail in * blackhat mode, because kiddie mode can produce overly optimistic * results. */ int paxtest_mode = 1; #ifndef __clang__ /* Dummy nested function */ void dummy(void) {} #endif mode = getenv( "PAXTEST_MODE" ); if( mode == NULL ) { paxtest_mode = 1; } else { if( strcmp(mode,"0") == 0 ) { paxtest_mode = 0; } else if( strcmp(mode,"1") == 0 ) { #ifdef __clang__ printf("INFO: The blackhat mode not supported due to missing nested function support in clang.\n"); paxtest_mode = 0; #else paxtest_mode = 1; #endif } } printf( "%s: ", testname ); fflush( stdout ); if( fork() == 0 ) { #ifdef __clang__ doit(); #else /* Perform a dirty (but not unrealistic) trick to circumvent * the kernel protection. */ if( paxtest_mode == 1 ) { pthread_t thread; pthread_create(&thread, NULL, test_thread, dummy); doit(); pthread_kill(thread, SIGTERM); } else { doit(); } #endif } else { wait( &status ); if( WIFEXITED(status) == 0 ) { printf( "Killed\n" ); exit( 0 ); } } exit( 0 ); } void itworked( void ) { printf( "Vulnerable\n" ); exit( 1 ); } void itfailed( void ) { printf( "Ok\n" ); exit( 2 ); } int do_mprotect( const void *addr, size_t len, int prot ) { void *ptr; int retval; unsigned long pagesize = sysconf(_SC_PAGESIZE); unsigned long offset = (unsigned long) addr & (pagesize - 1); /* Align to a multiple of PAGESIZE, assumed to be a power of two */ ptr = (void *)((unsigned long) addr - offset); len += offset; retval = mprotect( ptr, len, prot ); if( retval != 0 && (errno == EINVAL)) { perror( "could not mprotect():" ); exit( 1 ); } return retval; } paxtest-0.9.15/randexhaust1.c0000644000000000000000000000047112743042554014557 0ustar rootroot/* randexhaust1.c - Tests the randomization under memory exhaustion * when trying to get a fixed address at the upper end of the address space */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Randomization under memory exhaustion @~0"; const char testprog[] = RUNDIR"/getexhaust1"; paxtest-0.9.15/Makefile.FreeBSD0000644000000000000000000001303112743042554014651 0ustar rootroot#!/usr/bin/env make CC=cc ASFLAGS= CC_PIE= CFLAGS= LDFLAGS= SHLDFLAGS= ifndef RUNDIR RUNDIR=. endif ASFLAGS+= --noexecstack CFLAGS+= -O2 CFLAGS+= -DRUNDIR=\"${RUNDIR}\" CFLAGS+= -fno-stack-protector CFLAGS+= -D_FORTIFY_SOURCE=0 LDFLAGS+= -lpthread CC_PIE+= -fPIE -fPIC EXEC_TESTS= \ anonmap \ execbss \ execdata \ execheap \ execstack MPROT_TESTS= \ mprotanon \ mprotbss \ mprotdata \ mprotheap \ mprotstack SHLIB_TESTS= \ shlibbss \ shlibdata MPROTSH_TESTS= \ mprotshbss \ mprotshdata \ writetext RAND_TESTS= \ randamap \ randheap1 \ randheap2 \ randmain1 \ randmain2 \ randshlib \ randvdso \ randstack1 \ randstack2 \ randarg1 \ randarg2 FAST_RAND_TESTS= \ randexhaust1 \ randexhaust2 RET_TESTS= \ rettofunc1 \ rettofunc2 RETX_TESTS= \ rettofunc1x \ rettofunc2x TESTS:= \ ${EXEC_TESTS} \ ${SHLIB_TESTS} \ ${MPROT_TESTS} \ ${MPROTSH_TESTS} \ ${RAND_TESTS} \ ${FAST_RAND_TESTS} \ ${RET_TESTS} \ ${RETX_TESTS} UTILS= getamap \ getheap1 \ getheap2 \ getmain1 \ getmain2 \ getshlib \ getvdso \ getstack1 \ getstack2 \ getarg1 \ getarg2 \ getexhaust1 \ getexhaust2 SHLIBS= shlibtest.so \ shlibtest2.so all: ${SHLIBS} ${TESTS} ${UTILS} paxtest ifdef DESTDIR ifdef BINDIR ifdef RUNDIR install: all mkdir -p ${DESTDIR}/${RUNDIR} cp ${SHLIBS} ${TESTS} ${UTILS} ${DESTDIR}/${RUNDIR} mkdir -p ${DESTDIR}/${BINDIR} cp paxtest ${DESTDIR}/${BINDIR} chmod 755 ${DESTDIR}/${BINDIR}/paxtest endif endif endif body.o: body.c ${CC} ${CFLAGS} -fPIC -o ${.TARGET} -c ${.ALLSRC} rettofunc1x.o: rettofunc1x.c ${CC} ${CFLAGS} -fPIC -o ${.TARGET} -c ${.ALLSRC} rettofunc2x.o: rettofunc2x.c ${CC} ${CFLAGS} -fPIC -o ${.TARGET} -c ${.ALLSRC} paxtest: ${TESTS} genpaxtest sh genpaxtest ${CC} ${TESTS} anonmap: body.o anonmap.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} execbss: body.o execbss.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} execdata: body.o execdata.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} execheap: body.o execheap.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} execstack: body.o execstack.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getheap1: getheap.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getheap2: getheap.o ${CC} ${SHLDFLAGS} -pie -fPIE -o ${.TARGET} ${.ALLSRC} getheap.o: getheap.c ${CC} ${CFLAGS} -fPIC -o ${.TARGET} -c ${.ALLSRC} getamap.o: getamap.c ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getmain1: getmain.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getmain2: getmain2.o ${CC} ${SHLDFLAGS} -pie -fPIE -o ${.TARGET} ${.ALLSRC} getmain2.o: getmain.c ${CC} ${CFLAGS} -fPIC -o ${.TARGET} -c ${.ALLSRC} getshlib: getshlib.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getstack1: getstack.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getstack2: getstack1 rm -f ${.TARGET} cp getstack1 ${.TARGET} chmod +x ${.TARGET} getarg1: getarg.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} getarg2: getarg1 rm -f ${.TARGET} cp getarg1 ${.TARGET} chmod +x ${.TARGET} mprotanon: body.o mprotanon.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} mprotbss: body.o mprotbss.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} mprotheap: body.o mprotheap.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} mprotdata: body.o mprotdata.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} mprotshbss: body.o mprotshbss.o shlibtest.so ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} mprotshdata: body.o mprotshdata.o shlibtest.so ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} mprotstack: body.o mprotstack.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randamap: randbody.o randamap.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randarg1: randbody.o randarg1.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randarg2: randbody.o randarg2.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randheap1: randbody.o randheap1.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randheap2: randbody.o randheap2.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randexhaust1: fastrandbody.o randexhaust1.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randexhaust2: fastrandbody.o randexhaust2.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randmain1: randbody.o randmain1.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randmain2: randbody.o randmain2.o ${CC} ${LDFLAGS} ${SHLDFLAGS} -o ${.TARGET} ${.ALLSRC} randshlib: randbody.o randshlib.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randstack1: randbody.o randstack1.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randstack2: randbody.o randstack2.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} randvdso: randbody.o randvdso.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} rettofunc1: body.o rettofunc1.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} rettofunc1x: body.o rettofunc1x.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} rettofunc2: body.o rettofunc2.o ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} rettofunc2x: body.o rettofunc2x.o ${CC} ${LDFLAGS} -fPIE -pie -o ${.TARGET} ${.ALLSRC} shlibtest.o: shlibtest.c ${CC} ${CFLAGS} -fPIC -c ${.IMPSRC} -o ${.TARGET} shlibtest2.o: shlibtest2.c ${CC} ${CFLAGS} -fPIC -c ${.IMPSRC} -o ${.TARGET} shlibtest.so: shlibtest.o ${CC} ${SHLDFLAGS} -shared -o ${.TARGET} ${.ALLSRC} shlibtest2.so: shlibtest2.o ${CC} ${SHLDFLAGS} -shared -o ${.TARGET} ${.ALLSRC} shlibbss: body.o shlibbss.o shlibtest.so shlibtest2.so ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} shlibdata: body.o shlibdata.o shlibtest.so shlibtest2.so ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} writetext: body.o writetext.o shlibtest.so ${CC} ${LDFLAGS} -o ${.TARGET} ${.ALLSRC} clean: -rm -f *.o *.s *~ core *.core -rm -f ${SHLIBS} ${TESTS} ${UTILS} -rm -f paxtest paxtest.log a.out -rm -f paxbin paxtest-0.9.15/chpax-0.7/0000750000000000000000000000000012743042554013402 5ustar rootrootpaxtest-0.9.15/chpax-0.7/io.c0000640000000000000000000000501212743042554014154 0ustar rootroot/* ** io.c for chpax ** ** The PaX project : http://pax.grsecurity.net/ ** */ #include "chpax.h" #ifndef EM_X86_64 #define EM_X86_64 62 #endif /* Read flags */ int read_header(char *name, int flags) { char *ptr; int size; int block; if ((fd = open(name, flags)) < 0) return 1; ptr = (char *) &header_elf64; size = sizeof(header_elf64); do { block = read(fd, ptr, size); if (block <= 0) return (block ? 1 : 2); ptr += block; size -= block; } while (size > 0); memcpy(&header_aout, &header_elf64, sizeof(header_aout)); memcpy(&header_elf, &header_elf64, sizeof(header_elf)); if (!memcmp(header_elf64.e_ident, ELFMAG, SELFMAG) && FILE_IS_ELF64(header_elf64)) { if (header_elf64.e_type != ET_EXEC && header_elf.e_type != ET_DYN) return 2; if (header_elf64.e_machine != EM_SPARC && header_elf64.e_machine != EM_SPARCV9 && header_elf64.e_machine != EM_ALPHA && header_elf64.e_machine != EM_X86_64 && header_elf64.e_machine != EM_IA_64 && header_elf64.e_machine != EM_PPC64) return 3; header = &header_elf64; header_size = sizeof(header_elf64); get_flags = get_flags_elf64; put_flags = put_flags_elf64; } else if (!memcmp(header_elf.e_ident, ELFMAG, SELFMAG) && FILE_IS_ELF32(header_elf)) { if (header_elf.e_type != ET_EXEC && header_elf.e_type != ET_DYN) return 2; if (header_elf.e_machine != EM_386 && header_elf.e_machine != EM_SPARC && header_elf.e_machine != EM_SPARC32PLUS && header_elf.e_machine != EM_PARISC && header_elf.e_machine != EM_PPC && header_elf.e_machine != EM_MIPS && header_elf.e_machine != EM_MIPS_RS3_LE) return 3; header = &header_elf; header_size = sizeof(header_elf); get_flags = get_flags_elf; put_flags = put_flags_elf; } else if (N_MAGIC(header_aout) == NMAGIC || N_MAGIC(header_aout) == ZMAGIC || N_MAGIC(header_aout) == QMAGIC) { if (N_MACHTYPE(header_aout) != M_386) return 3; header = &header_aout; header_size = 4; get_flags = get_flags_aout; put_flags = put_flags_aout; } else return (2); return (0); } /* Write flags */ int write_header() { char *ptr; int size; int block; if ((off_t)-1 == lseek(fd, 0, SEEK_SET)) return 1; ptr = (char *) header; size = header_size; do { block = write(fd, ptr, size); if (block <= 0) break; ptr += block; size -= block; } while (size > 0); return size; } paxtest-0.9.15/chpax-0.7/aout.c0000640000000000000000000000041612743042554014520 0ustar rootroot/* ** aout.c for chpax ** ** The PaX project : http://pax.grsecurity.net/ ** */ #include "chpax.h" unsigned long get_flags_aout() { return (N_FLAGS(header_aout)); } void put_flags_aout(unsigned long flags) { N_SET_FLAGS(header_aout, flags & ~HF_PAX_RANDMMAP); } paxtest-0.9.15/chpax-0.7/elf64.c0000640000000000000000000000071312743042554014470 0ustar rootroot/* ** elf64.c for chpax ** ** The PaX project : http://pax.grsecurity.net/ ** */ #include "chpax.h" unsigned long get_flags_elf64() { u_long flags; flags = ((u_long) header_elf64.e_ident[EI_PAX + 1] << 8) + (u_long) header_elf.e_ident[EI_PAX]; return (flags); } void put_flags_elf64(unsigned long flags) { header_elf64.e_ident[EI_PAX] = (flags & 0xFF); header_elf64.e_ident[EI_PAX + 1] = ((flags >> 8) & 0xFF); } paxtest-0.9.15/chpax-0.7/chpax.10000640000000000000000000000357112743042554014576 0ustar rootroot.\" -*- nroff -*- .\" .\" chpax.1 .\" .\" This program was written by .\" The PaX Team .\" .\" This manpage was created by: .\" Martin Krafft [ ...] .SH DESCRIPTION \fBchpax\fR is a tool that allows PaX flags to be modified on a per-binary basis. PaX is part of common security-enhancing kernel patches, like GrSecurity. Your system needs to be running an appropriately patched kernel for this program to have any effect. .TP \fB-P\fR enforce paging based non-executable pages .TP \fB-p\fR do not enforce paging based non-executable pages .TP \fB-E\fR emulate trampolines .TP \fB-e\fR do not emulate trampolines .TP \fB-M\fR restrict mprotect() .TP \fB-m\fR do not restrict mprotect() .TP \fB-R\fR randomize mmap() base .TP \fB-r\fR do not randomize mmap() base .TP \fB-X\fR randomize ET_EXEC base .TP \fB-x\fR do not randomize ET_EXEC base .TP \fB-S\fR enforce segmentation based non-executable pages .TP \fB-s\fR do not enforce segmentation based non-executable pages .TP \fB-v\fR view current flag mask .TP \fB-z\fR zero flag mask (next flags still apply) .SH CAVEATS \fBchpax\fR does not currently parse standard command line arguments. Only the first argument is parsed, and it must contain all of the above flags you wish to use. So, instead of, e.g., "-v -p -r" you have to use "-vpr". .SH AUTHOR Written by The PaX Team .PP This manpage was written by Martin F. Krafft for the Debian GNU/Linux Distribution, but may be used by others. .SH "SEE ALSO" .BR gradm (1) .PP The PaX website: http://pax.grsecurity.net .PP The GrSecurity website: http://www.grsecurity.net paxtest-0.9.15/chpax-0.7/flags.c0000640000000000000000000000644212743042554014651 0ustar rootroot/* ** flags.c for chpax ** ** The PaX project : http://pax.grsecurity.net/ ** */ #include "chpax.h" #define USAGE \ "%s %s .::. Manage PaX flags for binaries\n" \ "Usage: %s OPTIONS FILE1 FILE2 FILEN ...\n" \ " -P\tenforce paging based non-executable pages\n" \ " -p\tdo not enforce paging based non-executable pages\n" \ " -E\temulate trampolines\n" \ " -e\tdo not emulate trampolines\n" \ " -M\trestrict mprotect()\n" \ " -m\tdo not restrict mprotect()\n" \ " -R\trandomize mmap() base [ELF only]\n" \ " -r\tdo not randomize mmap() base [ELF only]\n" \ " -X\trandomize ET_EXEC base [ELF only]\n" \ " -x\tdo not randomize ET_EXEC base [ELF only]\n" \ " -S\tenforce segmentation based non-executable pages\n" \ " -s\tdo not enforce segmentation based non-executable pages\n" \ " -v\tview current flag mask \n" \ " -z\tzero flag mask (next flags still apply)\n\n" \ "The flags only have effect when running the patched Linux kernel.\n" \ void usage(char *name) { char *ptr; ptr = (name ? name : "chpax"); printf(USAGE, ptr, CHPAX_VERSION, ptr); exit(1); } unsigned long scan_flags(unsigned long flags, char **argv, int *view) { int index; for (index = 1; argv[1][index]; index++) switch (argv[1][index]) { case 'p': flags |= HF_PAX_PAGEEXEC; continue ; case 'P': flags = (flags & ~HF_PAX_PAGEEXEC) | HF_PAX_SEGMEXEC; continue ; case 'E': flags |= HF_PAX_EMUTRAMP; continue ; case 'e': flags = (flags & ~HF_PAX_EMUTRAMP); continue ; case 'm': flags |= HF_PAX_MPROTECT; continue ; case 'M': flags = (flags & ~HF_PAX_MPROTECT); continue ; case 'r': flags |= HF_PAX_RANDMMAP; continue ; case 'R': flags = (flags & ~HF_PAX_RANDMMAP); continue ; case 'X': flags |= HF_PAX_RANDEXEC; continue ; case 'x': flags = (flags & ~HF_PAX_RANDEXEC); continue ; case 's': flags |= HF_PAX_SEGMEXEC; continue ; case 'S': flags = (flags & ~HF_PAX_SEGMEXEC) | HF_PAX_PAGEEXEC; continue ; case 'v': *view = 1; continue ; case 'z': flags = 0; continue ; default: fprintf(stderr, "Unknown option %c \n", argv[1][index]); usage(argv[0]); } return (flags); } char *pax_short_flags(unsigned long flags) { static char buffer[7]; buffer[0] = (flags & HF_PAX_PAGEEXEC ? 'p' : 'P'); buffer[1] = (flags & HF_PAX_EMUTRAMP ? 'E' : 'e'); buffer[2] = (flags & HF_PAX_MPROTECT ? 'm' : 'M'); buffer[3] = (flags & HF_PAX_RANDMMAP ? 'r' : 'R'); buffer[4] = (flags & HF_PAX_RANDEXEC ? 'X' : 'x'); buffer[5] = (flags & HF_PAX_SEGMEXEC ? 's' : 'S'); return buffer; } void print_flags(unsigned long flags) { printf(" * Paging based PAGE_EXEC : %s \n" " * Trampolines : %s \n" " * mprotect() : %s \n" " * mmap() base : %s \n" " * ET_EXEC base : %s \n" " * Segmentation based PAGE_EXEC : %s \n", flags & HF_PAX_PAGEEXEC ? "disabled" : flags & HF_PAX_SEGMEXEC ? "enabled" : "enabled (overridden)", flags & HF_PAX_EMUTRAMP ? "emulated" : "not emulated", flags & HF_PAX_MPROTECT ? "not restricted" : "restricted", flags & HF_PAX_RANDMMAP ? "not randomized" : "randomized", flags & HF_PAX_RANDEXEC ? "randomized" : "not randomized", flags & HF_PAX_SEGMEXEC ? "disabled" : "enabled"); } paxtest-0.9.15/chpax-0.7/README0000640000000000000000000000050612743042554014264 0ustar rootroot ----------------- CHPAX README FILE ----------------- As you can see, chpax has been partially rewritten . Since ELF64 is now supported (so that we match the Linux-PAX/sparc64 needs), we had to start a modularization of the code . For all the technical details about the improvements, check the Changelog file . paxtest-0.9.15/chpax-0.7/Changelog0000640000000000000000000000136212743042554015217 0ustar rootroot * * Nov 2002 : Added multi{options,files} cmdline, zeroflag, nicer output * (+ double output if flags are changed and -v is specified), more error * handling, more explicit error messages and return values * * Jan 2003 : Packaging, Port to Sparc/ELF64 : flags now stand in e_ident[EI_PAX] and * e_ident[EI_PAX + 1], old chpax version is needed for clearing old flags . * * Feb 2003: Added alpha support. * * Mar 2003: Added parisc support. * * Apr 2003: Added ppc support. * * Oct 2003: Added amd64, ia64 and make install support, short format flags printout. * * Dec 2003: Added mips and mips64 support. * * Feb 2004: Added PT_PAX_FLAGS support. * * Jun 2004: Fixed elf.h include, uses glibc's version now, added ppc64 support. paxtest-0.9.15/chpax-0.7/chpax.h0000640000000000000000000000500112743042554014653 0ustar rootroot/* * Include file for chpax.c * * The PaX project : http://pax.grsecurity.net/ * */ #include #include #include #include #include #include #include #include #include #define CHPAX_VERSION "0.7" #define HF_PAX_PAGEEXEC 1 /* 0: Paging based non-exec pages */ #define HF_PAX_EMUTRAMP 2 /* 0: Emulate trampolines */ #define HF_PAX_MPROTECT 4 /* 0: Restrict mprotect() */ #define HF_PAX_RANDMMAP 8 /* 0: Randomize mmap() base */ #define HF_PAX_RANDEXEC 16 /* 1: Randomize ET_EXEC base */ #define HF_PAX_SEGMEXEC 32 /* 0: Segmentation based non-exec pages */ #define EI_PAX 14 /* Index to read the PaX flags into ELF header e_ident[] array */ #ifndef PT_PAX_FLAGS #define PT_PAX_FLAGS 0x65041580 /* Indicates PaX flag markings */ #define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */ #define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */ #define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */ #define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */ #define PF_MPROTECT (1 << 8) /* Enable MPROTECT */ #define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */ #define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */ #define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */ #define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */ #define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */ #define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */ #define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */ #endif #define XCLOSE(fd) \ do \ { \ if (close(fd)) \ perror("close"); \ } \ while (0) #define FILE_IS_ELF64(h) (h.e_ident[EI_CLASS] == 2) #define FILE_IS_ELF32(h) (h.e_ident[EI_CLASS] == 1) /* Extern variables */ extern Elf32_Ehdr header_elf; extern Elf64_Ehdr header_elf64; extern struct exec header_aout; extern int header_size; extern void *header; extern int fd; extern unsigned long (*get_flags)(); extern void (*put_flags)(unsigned long); /* Function prototypes */ int read_header(char *name, int flags); int write_header(); unsigned long get_flags_elf(); void put_flags_elf(unsigned long flags); unsigned long get_flags_aout(); void put_flags_aout(unsigned long flags); unsigned long get_flags_elf64(); void put_flags_elf64(unsigned long flags); void usage(char *name); unsigned long scan_flags(unsigned long flags, char **argv, int *view); void print_flags(unsigned long flags); char *pax_short_flags(unsigned long flags); paxtest-0.9.15/chpax-0.7/Makefile0000640000000000000000000000107512743042554015046 0ustar rootroot## ## Makefile for chpax.c ## ## The PaX project : http://pax.grsecurity.net/ ## SRC = chpax.c io.c elf32.c elf64.c aout.c flags.c OBJ = $(SRC:.c=.o) RM = rm -f TARGET = chpax CC = gcc CFLAGS = -Wall -W -g3 STRIP = strip #STRIP = touch CP = cp DESTDIR = MANDIR = /usr/share/man/man1/ MKDIR = mkdir -p all : $(OBJ) $(CC) $(CFLAGS) $(OBJ) -o $(TARGET) install : all $(STRIP) $(TARGET) $(MKDIR) $(DESTDIR)/sbin/ $(DESTDIR)$(MANDIR) $(CP) $(TARGET) $(DESTDIR)/sbin/ $(CP) $(TARGET).1 $(DESTDIR)$(MANDIR) clean : $(RM) *.o *~ \#* *\# fclean : clean $(RM) $(TARGET) paxtest-0.9.15/chpax-0.7/elf32.c0000640000000000000000000000070312743042554014462 0ustar rootroot/* ** elf32.c for chpax ** ** The PaX project : http://pax.grsecurity.net/ ** */ #include "chpax.h" unsigned long get_flags_elf() { u_long flags; flags = ((u_long) header_elf.e_ident[EI_PAX + 1] << 8) + (u_long) header_elf.e_ident[EI_PAX]; return (flags); } void put_flags_elf(unsigned long flags) { header_elf.e_ident[EI_PAX] = (flags & 0xFF); header_elf.e_ident[EI_PAX + 1] = ((flags >> 8) & 0xFF); } paxtest-0.9.15/chpax-0.7/chpax.c0000640000000000000000000000373312743042554014660 0ustar rootroot/* * chpax version 0.7 * * This program manages various PaX related flags for ELF32, ELF64, * and a.out binaries. The flags only have effect when running the * patched Linux kernel. * * Written by Solar Designer and placed in the public domain. * * Adapted to PaX by the PaX Team * * Maintained by [jv@grsecurity.net] * */ #include "chpax.h" Elf32_Ehdr header_elf; Elf64_Ehdr header_elf64; struct exec header_aout; int header_size; void *header; int fd; unsigned long (*get_flags)(); void (*put_flags)(unsigned long); int main(int argc, char *argv[]) { unsigned long flags; unsigned long aflags; unsigned int index = 2; int mode; char *current; int error = 0; int view = 0; if (!argv) usage(NULL); if (argc < 3 || !argv[1] || argv[1][0] != '-') usage(argv[0]); flags = scan_flags(0, argv, &view); mode = view & !flags ? O_RDONLY : O_RDWR; for (current = argv[index]; current; current = argv[++index]) { error = read_header(current, mode); switch (error) { case 1: perror(current); continue ; case 2: fprintf(stderr, "%s: Unknown file type (passed) \n", current); XCLOSE(fd); continue ; case 3: fprintf(stderr, "%s: Wrong architecture (passed) \n", current); XCLOSE(fd); continue ; } aflags = get_flags(); flags = scan_flags(aflags, argv, &view); if (view) { printf("\n----[ chpax %s : Current flags for %s (%s) ]---- \n\n", CHPAX_VERSION, current, pax_short_flags(aflags)); print_flags(aflags); puts(""); } put_flags(flags); if (flags != aflags && write_header()) { perror(current); error = 4; } if (error) fprintf(stderr, "%s : Flags were not updated . \n", current); else if (view && aflags != flags) { printf("\n----[ chpax %s : Updated flags for %s (%s) ]---- \n\n", CHPAX_VERSION, current, pax_short_flags(flags)); print_flags(flags); puts(""); } XCLOSE(fd); } return (error); } paxtest-0.9.15/randshlibdelta2.c0000644000000000000000000000065312743042554015214 0ustar rootroot/* randshlibdelta2.c - Tests the randomisation of delta between ET_DYN main * executable and shared libraries * * Copyright (c)2014 by Kees Cook * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Offset to library randomisation (ET_DYN) "; const char testprog[] = RUNDIR"/getshlibdelta2"; paxtest-0.9.15/Makefile0000644000000000000000000000065612743043122013441 0ustar rootroot#!/usr/bin/make # # PaXtest master makefile # Copyright(c) 2003 by Peter Busser # This file has been released under the GNU Public Licence version 2 or later all: @cat targets linux: make -f Makefile.psm linux32: make -f Makefile.psm THEARCH=-m32 linux64: make -f Makefile.psm THEARCH=-m64 openbsd: gmake -f Makefile.OpenBSD freebsd: make -f Makefile.FreeBSD clean: make -f Makefile.psm clean paxtest-0.9.15/rettofunc2.c0000644000000000000000000000151712743042554014245 0ustar rootroot/* rettofunc2.c - Tests whether return to function exploits using memcpy() work * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include "body.h" #include "paxtest.h" const char testname[] = "Return to function (memcpy) "; static const fptr overflow[32] = { itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked }; void doit( void ) { char buf[sizeof(unsigned long)]; forced_memcpy( buf, overflow, sizeof( overflow ) ); } paxtest-0.9.15/shlibdata.c0000644000000000000000000000276712743042554014115 0ustar rootroot/* shlibdata.c - Tests whether code in the .data segment of a shared library can * be executed * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable shared library data "; void doit( void ) { fptr func; char *shdata, *shdata2; void *handle1, *handle2; handle1 = dlopen( "shlibtest.so", RTLD_LAZY ); if( handle1 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shdata = dlsym( handle1, "shdata" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shdata", "shlibtest.so" ); exit( 1 ); } handle2 = dlopen( "shlibtest2.so", RTLD_LAZY ); if( handle2 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shdata2 = dlsym( handle2, "shdata2" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shdata2", "shlibtest2.so" ); exit( 1 ); } copy_shellcode(shdata); copy_shellcode(shdata2); /* Convert the pointer to a function pointer */ func = shdata < shdata2 ? (fptr)shdata : (fptr)shdata2; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); dlclose( handle1 ); dlclose( handle2 ); } paxtest-0.9.15/mprotshbss.c0000644000000000000000000000347712743042554014365 0ustar rootroot/* mprotshbss.c - Tests whether code in the .bss segment of a shared library can * be executed after trying to use mprotect() to make it * executable. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable shared library bss (mprotect) "; void doit( void ) { char *shbss; char *shbss2; fptr func; void *handle1, *handle2; handle1 = dlopen( "shlibtest.so", RTLD_LAZY ); if( handle1 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shbss = dlsym( handle1, "shbss" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shbss", "shlibtest.so" ); exit( 1 ); } handle2 = dlopen( "shlibtest2.so", RTLD_LAZY ); if( handle2 == NULL ) { fprintf( stderr, "dlopen() returned NULL\n" ); exit( 1 ); } dlerror(); /* clear any errors */ shbss2 = dlsym( handle2, "shbss2" ); if( dlerror() != NULL ) { fprintf( stderr, "symbol %s not found in %s\n", "shbss2", "shlibtest2.so" ); exit( 1 ); } copy_shellcode(shbss); copy_shellcode(shbss2); /* Convert the pointer to a function pointer */ func = shbss < shbss2 ? (fptr)shbss : (fptr)shbss2; /* Try to make the memory region executable by using mprotect() */ /* Due to an OpenBSD bug PROT_READ is required */ do_mprotect(func, MAX_SHELLCODE_LEN, PROT_READ|PROT_EXEC ); /* Call the code in the buffer */ func(); do_mprotect(func, MAX_SHELLCODE_LEN, PROT_READ|PROT_WRITE ); /* It worked when the function returns */ itworked(); dlclose( handle1 ); dlclose( handle2 ); } paxtest-0.9.15/getheap.c0000644000000000000000000000070512743042554013565 0ustar rootroot/* getheap.c - Get the address of the first element allocated on the heap and * print it. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include int main( int argc, char *argv[] ) { char *p; p = malloc( 100 ); if( p == NULL ) { perror( "getheap" ); exit( 1 ); } printf( "%p\n", p ); exit( 0 ); } paxtest-0.9.15/randamap.c0000644000000000000000000000056212743042554013734 0ustar rootroot/* randamap.c - Tests the randomization of anonymous mappings. * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Anonymous mapping randomization test "; const char testprog[] = RUNDIR"/getamap"; paxtest-0.9.15/body.h0000644000000000000000000000046312743042554013113 0ustar rootroot#ifndef _BODY_H_ #define _BODY_H_ #include /* provided by body.c */ void itworked( void ); void itfailed( void ); int do_mprotect( const void *addr, size_t len, int prot ); /* provided by individual tests */ typedef void (*fptr)(void); extern const char testname[]; void doit( void ); #endif paxtest-0.9.15/mprotanon.c0000644000000000000000000000361012743042554014163 0ustar rootroot/* mprotanon.c - Tests whether code can be executed in anonymous mappings * after trying to use mprotect() to make it executable. * * Copyright (c)2003,2004 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include #include "body.h" #include "shellcode.h" #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif const char testname[] = "Executable anonymous mapping (mprotect) "; void doit( void ) { char *buf; fptr func; buf = mmap(NULL, PAGE_SIZE_MAX, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if( buf == MAP_FAILED ) { fprintf( stderr, "mmap() returned NULL\n" ); exit( 1 ); } copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)buf; /* Try to make the anonymous mapping executable first by using * mprotect. * * Some people like to disable this call to make the results look * better for their system. * * The whole purpose of this call is to figure out how the system * handles mprotect() calls. If it allows the application to use * mprotect() to override kernel settings, then that is something * the user of this test suite may like to know. * * And yes, I know that this is how UNIX is supposed to work and that * it is a design decision to allow this override. All the more reason * to be honest and open about it and to tell the user why (s)he has * to trade in a bit of security for compatibility. * * But then, it is of course easier to simply disable this mprotect() * call than to fix your kernel and userland. */ /* Due to a FreeBSD bug PROT_READ is required */ do_mprotect( buf, PAGE_SIZE_MAX, PROT_READ|PROT_EXEC ); /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/execheap.c0000644000000000000000000000133612743042554013733 0ustar rootroot/* execheap.c - Tests whether code in the heap can be executed * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable heap "; void doit( void ) { char *buf; fptr func; buf = malloc( MAX_SHELLCODE_LEN ); if( buf == NULL ) { fprintf( stderr, "Out of memory\n" ); exit( 1 ); } copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)buf; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/randshlibdelta1.c0000644000000000000000000000070512743042554015211 0ustar rootroot/* randshlibdelta1.c - Tests the randomisation of delta between ET_EXEC main * executable and shared libraries (should match randshlib) * * Copyright (c)2014 by Kees Cook * This file has been released under the GNU Public Licence version 2 or later */ #ifndef RUNDIR #error RUNDIR not defined #endif const char testname[] = "Offset to library randomisation (ET_EXEC)"; const char testprog[] = RUNDIR"/getshlibdelta1"; paxtest-0.9.15/randbody.c0000644000000000000000000000303712743042554013753 0ustar rootroot/* randbody.c - This part is shared by the randomization tests * * Copyright (c)2003-2014 by Peter Busser , Brad Spengler * This file has been released under the GNU Public Licence version 2 or later */ #include #include #define COUNT (1500) extern const char testname[]; extern const char testprog[]; int main( int argc, char *argv[] ) { FILE *fp; int i, x; unsigned long results[COUNT]; unsigned int quality[8 * sizeof(unsigned long)] = { 0 }; unsigned int weak_bits = 0; unsigned int dupes = 0; unsigned long tmp; unsigned long and; unsigned long or; int bits; int ret; printf( "%s: ", testname ); fflush(NULL); and = ~0L; or = 0L; for( i = 0; i < COUNT; i++ ) { fp = popen( testprog, "r" ); if( fp == NULL ) { perror( testprog ); exit( 1 ); } ret = fscanf( fp, "%lx", &tmp ); if (ret != 1) { perror ( testprog ); exit( 1 ); } results[i] = tmp; and &= tmp; or |= tmp; pclose( fp ); } if( and == or ) { printf( "No randomization\n" ); } else { tmp = and ^ ~or; tmp = or & ~tmp; bits = 0; for (i = 0; i < sizeof(quality)/sizeof(quality[0]); i++) { if (!(tmp & (1UL << i))) continue; for (x = 0; x < COUNT; x++) { if (results[x] & (1UL << i)) quality[i] += 1; } if (quality[i] <= ((COUNT * 35) / 100) || quality[i] >= ((COUNT * 65) / 100)) weak_bits++; } while( tmp != 0 ) { bits += (tmp%2); tmp >>= 1; } printf( "%d quality bits (guessed)\n", bits - weak_bits); } exit( 0 ); } paxtest-0.9.15/execstack.c0000644000000000000000000000120012743042554014111 0ustar rootroot/* execstack.c - Tests whether code on the stack can be executed * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable stack "; void doit( void ) { char buf[MAX_SHELLCODE_LEN]; fptr func; copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)buf; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/Makefile.psm0000644000000000000000000001616012743042554014244 0ustar rootroot#!/usr/bin/make # tested with make-3.79.1/gcc-2.96 (shared) and make-3.80/gcc-3.3.2/3 (pie) # make-3.79.1 does not support $$@ as target requirement (works for make-3.80) # preliminaries: # Gentoo modifies the specs adding pie/nopie to enable/disable ET_DYN binaries CC := gcc LD := ld CC_PIC := -fPIC GCC_SPCS := $(shell $(CC) -print-file-name=${GCC_SPECS:-specs}) check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; \ then echo "$(1)"; else echo "$(2)"; fi) check_as = $(shell if $(CC) -Wa,$(1) -Wa,-Z -c -o /dev/null -xassembler /dev/null > /dev/null 2>&1; \ then echo "-Wa,$(1)"; fi) # stack protector has to be disabled for some tests CC_SSP := $(call check_gcc,-fno-stack-protector,) CC_SSP += $(call check_gcc,-fno-stack-protector-all,) ASFLAGS := $(call check_as,--noexecstack) CC_PIE := $(call check_gcc,-fPIE,-fPIC) CC_TRAMPOLINES := $(call check_gcc,-ftrampolines,) CC_MSECURE_PLT := $(call check_gcc,-msecure-plt,) LD_PIE = $(shell $(LD) --help | grep -q pie && echo "-pie") ifneq ($(LD_PIE),) # Gentoo (hardened specs enabled) CC_ETEXEC = $(shell grep -q "\!nopie" $(GCC_SPCS) && echo "-nopie") LD_ETEXEC = $(CC_ETEXEC) endif ifeq ($(LD_PIE),) LD_PIE = -shared endif # check for installed binaries CHPAXBIN := $(shell if which chpax >/dev/null 2>&1 ; then echo chpax; fi) PAXCTLBIN := $(shell if which paxctl >/dev/null 2>&1 ; then echo paxctl; fi) # should somehow use this to see if we really need paxctl # list=`paxctl -qQv /sbin/paxctl 2>/dev/null`; if echo $list | grep -q "PaX flags" ; then echo paxctl; fi # instead we use both markings to have paxtest running correctly on all platforms ifneq ($(PAXCTLBIN),) DUMMY := $(shell echo '${PAXCTLBIN} $$*' > paxbin) endif # for some reason the .c files need it, else GNU_STACK=RWE OPT_FLAGS := -O2 $(ASFLAGS) PTHREAD := -lpthread # define stripping of binaries/libs here, or set these on make's commandline, # else you'll loose the chpax flags! LDFLAGS := SHLDFLAGS := ifndef RUNDIR RUNDIR := . endif # The Hardened GCC compiler has stack protector on by default, this # could interfere with the results of this test. CFLAGS := $(OPT_FLAGS) -U_FORTIFY_SOURCE -DRUNDIR=\"${RUNDIR}\" $(CC_SSP) $(CC_TRAMPOLINES) ifneq ($(THEARCH),) CFLAGS += $(THEARCH) LDFLAGS += $(THEARCH) SHLDFLAGS += $(THEARCH) endif EXEC_TESTS = anonmap execbss execdata execheap execstack MPROT_TESTS = mprotanon mprotbss mprotdata mprotheap mprotstack SHLIB_TESTS = shlibbss shlibdata MPROTSH_TESTS = mprotshbss mprotshdata writetext RAND_TESTS = randamap randheap1 randheap2 randmain1 randmain2 randshlib randvdso randstack1 randstack2 randarg1 randarg2 randshlibdelta1 randshlibdelta2 FAST_RAND_TESTS = randexhaust1 randexhaust2 RET_TESTS = rettofunc1 rettofunc2 RETX_TESTS = rettofunc1x rettofunc2x TESTS = $(EXEC_TESTS) $(SHLIB_TESTS) $(MPROT_TESTS) $(MPROTSH_TESTS) $(RAND_TESTS) $(FAST_RAND_TESTS) $(RET_TESTS) $(RETX_TESTS) UTILS= getamap getheap1 getheap2 getmain1 getmain2 getshlib getvdso getstack1 getstack2 getarg1 getarg2 getexhaust1 getexhaust2 getshlibdelta1 getshlibdelta2 SHLIBS= shlibtest.so shlibtest2.so ifeq ($(CHPAXBIN),) CHPAXVER := 0.7 CHPAX := chpax-$(CHPAXVER) CHPAXSRC := $(CHPAX)/aout.c $(CHPAX)/chpax.c $(CHPAX)/elf32.c $(CHPAX)/elf64.c $(CHPAX)/flags.c $(CHPAX)/io.c CHPAXBIN := ./chpax all: chpax $(SHLIBS) $(TESTS) $(UTILS) paxtest else all: $(SHLIBS) $(TESTS) $(UTILS) paxtest endif # we need the failure handling, for kernels not supporting EI_PAX DUMMY := $(shell echo '${CHPAXBIN} $$* >/dev/null 2>/dev/null ||:' >> paxbin; chmod +x paxbin) PAXBIN := ./paxbin DL := -ldl clean: -rm -f *.o *.s *~ core -rm -f $(TESTS) $(UTILS) $(SHLIBS) -rm -f paxtest paxtest.log a.out dumpspecs paxbin -rm -f chpax-0.7/*.o -rm -f chpax ifdef DESTDIR ifdef BINDIR ifdef RUNDIR install: all mkdir -p $(DESTDIR)/$(RUNDIR) cp $(SHLIBS) $(TESTS) $(UTILS) $(DESTDIR)/$(RUNDIR) mkdir -p $(DESTDIR)/$(BINDIR) cp paxtest $(DESTDIR)/$(BINDIR) chmod 755 $(DESTDIR)/$(BINDIR)/paxtest endif endif endif chpax: $(CHPAXSRC:.c=.o) $(CC) $(LDFLAGS) -o $@ $^ paxtest: $(TESTS) genpaxtest sh genpaxtest $(CC) $(TESTS) .S.o: $(CC) $(CFLAGS) $(CC_PIE) $(ASFLAGS) -o $@ -c $< .c.o: $(CC) $(CFLAGS) -o $@ -c $< $(EXEC_TESTS) $(MPROT_TESTS): body.o $(CC) $(CFLAGS) -o $@.o -c $@.c $(CC) $(LDFLAGS) -o $@ $< $@.o $(PTHREAD) $(RAND_TESTS): randbody.o $(CC) $(CFLAGS) -o $@.o -c $@.c $(CC) $(LDFLAGS) -o $@ $< $@.o $(FAST_RAND_TESTS): fastrandbody.o $(CC) $(CFLAGS) -o $@.o -c $@.c $(CC) $(LDFLAGS) -o $@ $< $@.o getamap: getamap.o $(CC) $(LDFLAGS) -o $@ $@.o # get heap1/main1 are built w/o PIC get%1.o: get%.c $(CC) $(CFLAGS) $(CC_ETEXEC) -o $@ -c $< # get heap2/main2 are built w/ PIC get%2.o: get%.c $(CC) $(CFLAGS) $(CC_PIE) -o $@ -c $< # Adamantix uses the PIC version (getheap2.o), not necessary for ET_EXEC # build as ET_EXEC (not in Adamantix's Makefile) getheap1: getheap1.o $(CC) $(LDFLAGS) $(LD_ETEXEC) -o $@ $< getmain1: getmain1.o $(CC) $(LDFLAGS) $(LD_ETEXEC) -o $@ $< -$(PAXBIN) -C $@ $(PAXBIN) -SPRXM $@ getshlibdelta1: getshlibdelta1.o $(CC) $(LDFLAGS) $(LD_ETEXEC) -o $@ $< $(DL) -$(PAXBIN) -C $@ $(PAXBIN) -SPRXM $@ getheap2 getmain2: getheap2.o getmain2.o $(CC) $(LDFLAGS) $(LD_PIE) -o $@ $@.o || (echo -e "#!/bin/sh\necho $@ pie not implemented" > $@; chmod +x $@) getshlibdelta2: getshlibdelta2.o $(CC) $(LDFLAGS) $(LD_PIE) -o $@ $@.o $(DL) || (echo -e "#!/bin/sh\necho $@ pie not implemented" > $@; chmod +x $@) getshlib: getshlib.o $(CC) $(LDFLAGS) -o $@ $< $(DL) # ET_EXEC and usage of "m" is not confirmed (as in Gentoo patch) # Adamantix does not use it # Pax Team does not want "m" for getstack1/2 getstack1: getstack.o $(CC) $(LDFLAGS) -o $@ $< -$(PAXBIN) -C $@ $(PAXBIN) -SRpm $@ getstack2: getstack.o $(CC) $(LDFLAGS) -o $@ $< # disable segmexec, kernel else overrides pageexec -$(PAXBIN) -C $@ $(PAXBIN) -PRsm $@ getarg1: getarg.o $(CC) $(LDFLAGS) -o $@ $< -$(PAXBIN) -C $@ $(PAXBIN) -SRpm $@ getexhaust1: getexhaust1.o $(CC) $(LDFLAGS) -o $@ $< -$(PAXBIN) -C $@ $(PAXBIN) -SRpm $@ getexhaust2: getexhaust2.o $(CC) $(LDFLAGS) -o $@ $< -$(PAXBIN) -C $@ $(PAXBIN) -SRpm $@ getarg2: getarg.o $(CC) $(LDFLAGS) -o $@ $< # disable segmexec, kernel else overrides pageexec -$(PAXBIN) -C $@ $(PAXBIN) -PRsm $@ $(MPROTSH_TESTS): body.o shlibtest.so $(CC) $(CFLAGS) -o $@.o -c $@.c $(CC) $(LDFLAGS) -o $@ $@.o $^ $(DL) $(PTHREAD) # used for RANDEXEC'd binaries retbody.o: body.c $(CC) $(CFLAGS) $(CC_ETEXEC) -o $@ -c $< # build as ET_EXEC (recommended by PaX Team, not really a requirement) $(RET_TESTS): retbody.o $(CC) $(CFLAGS) $(CC_ETEXEC) -o $@.o -c $@.c $(CC) $(LDFLAGS) $(LD_ETEXEC) -o $@ $< $@.o $(PTHREAD) # build as ET_EXEC (not in Adamantix's Makefile) $(RETX_TESTS): retbody.o $(CC) $(CFLAGS) $(CC_ETEXEC) -o $@.o -c $@.c $(CC) $(LDFLAGS) $(LD_ETEXEC) -o $@ $< $@.o $(PTHREAD) -$(PAXBIN) -C $@ $(PAXBIN) -SPXM $@ # should also shlibbss.o and shlibdata.o be built w/ PIC? # if yes, remove tes from target and dependency shlibtes%.o: shlibtes%.c $(CC) $(CFLAGS) $(CC_PIC) -o $@ -c $< shlib%.so: shlib%.o $(CC) $(SHLDFLAGS) -shared -o $@ $< $(SHLIB_TESTS): body.o $(SHLIBS) shlibbss.o shlibdata.o $(CC) $(LDFLAGS) -o $@ body.o $@.o $(SHLIBS) $(DL) $(PTHREAD) paxtest-0.9.15/rettofunc2x.c0000644000000000000000000000151712743042554014435 0ustar rootroot/* rettofunc2.c - Tests whether return to function exploits using memcpy() work * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include "body.h" #include "paxtest.h" const char testname[] = "Return to function (memcpy, PIE) "; static const fptr overflow[32] = { itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked, itworked }; void doit( void ) { char buf[sizeof(unsigned long)]; forced_memcpy( buf, overflow, sizeof( overflow ) ); } paxtest-0.9.15/shellcode.h0000644000000000000000000000200312743042554014110 0ustar rootroot#ifndef _SHELLCODE_H_ #define _SHELLCODE_H_ #include "paxtest.h" #define MAX_SHELLCODE_LEN 12 #if defined(__powerpc__) #define SHELLCODE_RETURN "\x4e\x80\x00\x20" #elif defined(__sparc__) && !defined(__arch64__) #define SHELLCODE_RETURN "\x81\xc7\xe0\x08\x81\xe8\x00\x00" #elif defined(__sparc__) && defined(__arch64__) #define SHELLCODE_RETURN "\x9d\xe3\xbf\x40\x81\xcf\xe0\x08\x01\x00\x00\x00" #elif defined(__arm__) && !defined(__arch64__) #define SHELLCODE_RETURN "\x1e\xff\x2f\xe1" #else #define SHELLCODE_RETURN "\xc3" #endif #define SIZE_OF_SHELLCODE_RETURN (sizeof(SHELLCODE_RETURN) - 1) #if defined(__powerpc64__) static inline void copy_shellcode(void *dst) { /* 12 bytes total */ unsigned long dstaddr = (unsigned long)dst + sizeof(dstaddr); forced_memcpy(dst, &dstaddr, sizeof(dstaddr)); forced_memcpy(dst + sizeof(dstaddr), SHELLCODE_RETURN, SIZE_OF_SHELLCODE_RETURN); } #else static inline void copy_shellcode(void *dst) { forced_memcpy(dst, SHELLCODE_RETURN, SIZE_OF_SHELLCODE_RETURN); } #endif #endif paxtest-0.9.15/anonmap.c0000644000000000000000000000161012743042554013575 0ustar rootroot/* anonmap.c - Tests whether code can be executed in anonymous mappings * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable anonymous mapping "; #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif void doit( void ) { char *buf; fptr func; buf = mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); if( buf == MAP_FAILED ) { fprintf( stderr, "mmap() returned NULL\n" ); exit( 1 ); } copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)buf; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/getvdso.c0000644000000000000000000000306712743042554013627 0ustar rootroot/* getshlib.c - Get the address of the maped VDSO and print it * * Copyright (c) 2014 by Brad Spengler * Copyright (c) 2015 by Oliver Pinter * This file has been released under the GNU Public Licence version 2 or later */ #define _GNU_SOURCE #include #include #include #ifdef __FreeBSD__ #include #include #include #include #include #define PROC_AUXV_MAX 256 #define AT_TIMEKEEP 22 #endif int main( int argc, char *argv[] ) { #ifdef __linux__ FILE *f = fopen("/proc/self/maps", "r"); char buf[1024] = { }; if (f == NULL) return 0; while (fgets(buf, sizeof(buf)-1, f)) { if (strstr(buf, "[vdso]")) { char *p = strchr(buf, '-'); unsigned long val; *p = '\0'; val = strtoul(buf, NULL, 16); printf("%p\n", (void *)val); fclose(f); return 0; } } fclose(f); return 0; #elif defined(__FreeBSD__) Elf_Auxinfo *aux, *auxv; int name[4]; size_t len; int ret = 0; name[0] = CTL_KERN; name[1] = KERN_PROC; name[2] = KERN_PROC_AUXV; name[3] = getpid(); len = PROC_AUXV_MAX * sizeof(Elf_Auxinfo); auxv = malloc(len); if (auxv == NULL) { ret = 1; goto out; } if (sysctl(name, 4, auxv, &len, NULL, 0) == -1) { ret = 2; goto out; } for (aux = auxv; aux->a_type != AT_NULL; aux++) { if (aux->a_type == AT_TIMEKEEP) { printf("%p\n", aux->a_un.a_ptr); return 0; } } out: if (auxv != NULL) free(auxv); printf("%p\n", NULL); return ret; #else #error unsupported OS #endif } paxtest-0.9.15/execbss.c0000644000000000000000000000120612743042554013601 0ustar rootroot/* execbss.c - Tests whether code in the .bss segment can be executed * * Copyright (c)2003 by Peter Busser * This file has been released under the GNU Public Licence version 2 or later */ #include #include #include #include "body.h" #include "shellcode.h" const char testname[] = "Executable bss "; char buf[MAX_SHELLCODE_LEN]; void doit( void ) { fptr func; copy_shellcode(buf); /* Convert the pointer to a function pointer */ func = (fptr)&buf; /* Call the code in the buffer */ func(); /* It worked when the function returns */ itworked(); } paxtest-0.9.15/targets0000644000000000000000000000024512743042554013377 0ustar rootrootChoose one of the following make targets: linux Linux (gcc default) linux32 32bit Linux linux64 64bit Linux openbsd OpenBSD freebsd FreeBSD clean Clean up paxtest-0.9.15/Makefile.OpenBSD0000644000000000000000000000564712743042554014707 0ustar rootroot#!/usr/bin/gmake CC=gcc CFLAGS= LDFLAGS= ifndef RUNDIR RUNDIR=. endif CFLAGS+=-O2 -DRUNDIR=\"${RUNDIR}\" -fno-stack-protector -ftrampolines LDFLAGS+=-lpthread TESTS= anonmap \ execbss \ execdata \ execheap \ execstack \ mprotanon \ mprotbss \ mprotdata \ mprotheap \ mprotshbss \ mprotshdata \ mprotstack \ randamap \ randheap1 \ randmain1 \ randshlib \ randstack1 \ randstack2 \ randarg1 \ randarg2 \ rettofunc1 \ rettofunc1x \ rettofunc2 \ rettofunc2x \ shlibbss \ shlibdata \ writetext UTILS= getamap \ getheap1 \ getheap2 \ getmain1 \ getmain2 \ getshlib \ getstack1 \ getstack2 \ getarg1 \ getarg2 SHLIBS= shlibtest.so \ shlibtest2.so all: $(SHLIBS) $(TESTS) $(UTILS) paxtest clean: -rm -f *.o *.s *~ core -rm -f $(SHLIBS) $(TESTS) $(UTILS) -rm -f paxtest paxtest.log a.out ifdef DESTDIR ifdef BINDIR ifdef RUNDIR install: all mkdir -p $(DESTDIR)/$(RUNDIR) cp $(SHLIBS) $(TESTS) $(UTILS) $(DESTDIR)/$(RUNDIR) mkdir -p $(DESTDIR)/$(BINDIR) cp paxtest $(DESTDIR)/$(BINDIR) chmod 755 $(DESTDIR)/$(BINDIR)/paxtest endif endif endif paxtest: $(TESTS) genpaxtest sh genpaxtest $(CC) $(TESTS) anonmap: body.o anonmap.o execbss: body.o execbss.o execdata: body.o execdata.o execheap: body.o execheap.o execstack: body.o execstack.o getheap1: getheap.o $(CC) $(LDFLAGS) -o $@ $+ getheap2: getheap.o $(CC) -shared -o $@ $+ getheap.o: getheap.c $(CC) $(CFLAGS) -fPIC -o $@ -c $< getamap.o: getamap.c getmain1: getmain.o $(CC) $(LDFLAGS) -o $@ $+ getmain2: getmain2.o $(CC) -shared -o $@ $+ getmain2.o: getmain.c $(CC) $(CFLAGS) -fPIC -o $@ -c $< getshlib: getshlib.o getstack1: getstack.o $(CC) $(LDFLAGS) -o $@ $+ getstack2: getstack1 rm -f $@ cp getstack1 $@ chmod +x $@ getarg1: getarg.o $(CC) $(LDFLAGS) -o $@ $+ getarg2: getarg1 rm -f $@ cp getarg1 $@ chmod +x $@ mprotanon: body.o mprotanon.o mprotbss: body.o mprotbss.o mprotheap: body.o mprotheap.o mprotdata: body.o mprotdata.o mprotshbss: body.o mprotshbss.o shlibtest.so mprotshdata: body.o mprotshdata.o shlibtest.so mprotstack: body.o mprotstack.o randamap: randbody.o randamap.o randheap1: randbody.o randheap1.o randheap2: randbody.o randheap2.o randmain1: randbody.o randmain1.o randmain2: randbody.o randmain2.o randshlib: randbody.o randshlib.o randstack1: randbody.o randstack1.o randstack2: randbody.o randstack2.o rettofunc1: body.o rettofunc1.o rettofunc1x: body.o rettofunc1x.o $(CC) $(LDFLAGS) -o $@ $+ rettofunc2: body.o rettofunc2.o rettofunc2x: body.o rettofunc2x.o $(CC) $(LDFLAGS) -o $@ $+ shlibtest.o: shlibtest.c $(CC) $(CFLAGS) -fPIC -c $< -o $@ shlibtest2.o: shlibtest2.c $(CC) $(CFLAGS) -fPIC -c $< -o $@ shlibtest.so: shlibtest.o $(CC) $(SHLDFLAGS) -shared -o $@ $+ shlibtest2.so: shlibtest2.o $(CC) $(SHLDFLAGS) -shared -o $@ $+ shlibbss: body.o shlibbss.o shlibtest.so shlibtest2.so shlibdata: body.o shlibdata.o shlibtest.so shlibtest2.so writetext: body.o writetext.o shlibtest.so