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

*/

Advertisement

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.