how to test for page permission enforcement on debian gnu/linux

source : debian-security mailing list.

Warning : the shellcode below launches /bin/sh. It is from Aleph One's Smashing the Stack for Fun and Profit. It is generally a bad idea to blindly run someone else's shellcode on your machine since you don't know what it will do ( unless you've analyzed it ). You can and should verify that the following shellcode is the same as listed in Aleph One's article ( found easily via Google ) before running this example.


static char shellcode[] =
"\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b"
"\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
"\x80\xe8\xdc\xff\xff\xff/bin/sh";

int main() {
void (*function_pointer)(void) = (void *) shellcode;
function_pointer();
return(0);
}
Call it tmp.c.

Now you can test for page permission enforcement :

$ gcc -z execstack tmp.c
$ ./a.out
$ exit  ## <-- this means the stack is executable


$ gcc -z noexecstack tmp.c
$ ./a.out 
Segmentation fault  ## <-- this means the stack is non executable


If ./a.out does not segfault once you have compiled it with -z noexecstack, then page permissions are not being enforced.

The End.
 
 
Creative Commons License
This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
 
 

0 comments :: how to test for page permission enforcement on debian gnu/linux

Post a Comment