Buffer Overflow problem (C)

#include <stdio.h>
#include <string.h>

int main(void) {
char buff[15];
buff[14] = 0;

printf(“\n Enter the password : \n”);
gets(buff);

if(strcmp(buff, “password”)) {
printf (“\n Wrong Password \n”);
} else {
printf (“\n Correct Password \n”);
buff[14] = 1;
}

if(buff[14]) {
/* Now Give root or admin rights to user*/
printf (“\n Root privileges given to the user \n”);
}

return 0;
}

/*

Output:
mnvsngv@M17xR4:~/C$ ./BufferOverflow

Enter the password :
password

Correct Password
mnvsngv@M17xR4:~/C$ ./BufferOverflow

Enter the password :
wrongpassword

Wrong Password
mnvsngv@M17xR4:~/C$ ./BufferOverflow

Enter the password :
wrongpassof15+chars

Wrong Password

Root privileges given to the user

*/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s