#include <stdio.h>
char user_name[20] = " ";
char password[20] = " ";
char users[][2][20] =
{ { "root", "98765" },
{ "me", "hello" },
{ "abc", "password" },
{ "", "" }
};
int check_name()
{
int i;
gets(user_name);
gets(password);
for(i=0; users[i][0][0] != 0; i++)
{
if(strcmp(user_name, users[i][0]) == 0 &&
strcmp(password, users[i][1]) == 0)
return 1;
}
return 0;
}
void logon()
{
printf("Welcome! \n");
exit(1);
}
void reject()
{
printf("Connection closed !\n");
printf("Real username: \n");
printf(users[0][0]);
printf("\n");
printf("Real password: \n");
printf(users[0][1]);
printf("\n");
exit(0);
}
main()
{
if(check_name())
logon();
else
reject();
}
Hey guys, I kind of understand the theory behind buffer overflow, but I can't seem to make it work here.
Note that I added extra printf
to output real username and password to see how much I overwrote in memory.
I tried writing a random letter x
.
First I did: username = 20 x
s, password = 60 x
s, the output was:
Real user:
xxxxxxxxxxxxxxxxxxxxxxxxxxxx // 28 x's
Real pass:
xxxxxxxx // 8 x's
So I added 12 x
s to the password to make it the maximal size of 20, so password = 72 x
s and the output was:
// with input user = 20 x's and pass = 72 x's
Real user:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // 40
Real pass:
xxxxxxxxxxxxxxxxxxxx // 20
Ultimately I thought by updating my input username to 40 x
s it would work, but it didn't. Output was identical as the last one (40 x's for real user and 20 x's for real password) but still couldn't "hack" it.
I'm not sure what to do at this point. Thanks in advance!