Question: You are given the code below: #include #include #include int check_authentication(char *password) { int auth_flag = 0; char *password_buffer; char *dept; password_buffer = (char *)

You are given the code below:

#include

#include

#include

int check_authentication(char *password) {

int auth_flag = 0;

char *password_buffer;

char *dept;

password_buffer = (char *) malloc (16);

dept = (char *) malloc(10);

strcpy(password_buffer, password);

if(strcmp(password_buffer, "AsiaPacificInst") == 0){

printf("Your Department:");

gets(dept);

printf(" User from Department: ");

printf(dept);

if(strcmp(dept,"NSF")==0) {

auth_flag = 1;

}

}

else if(strcmp(password_buffer, "AsiaPacificUni") == 0){

printf("Your Department:");

gets(dept);

printf(" User from Department: ");

printf(dept);

if(strcmp(dept,"TM")==0) {

auth_flag = 1;

}

}

else {

auth_flag = 0;

}

return auth_flag;

}

int main() {

char errmsg[512];

char outbuf[512];

char user[20];

char password[20];

printf("Username: ");

gets(user);

if (strcmp(user,"Adm1n") == 0){

printf("Authorised User ");

sprintf(errmsg, "Authorised User %400s",user);

sprintf(outbuf,errmsg);

printf("Password: ");

gets(password);

if(check_authentication(password)) {

printf(" -=-=-=-=-=-=-=-=-=-=-=-=-=- ");

printf(" Access Granted. ");

printf("-=-=-=-=-=-=-=-=-=-=-=-=-=- ");

} else {

printf(" -=-=-=-=-=-=-=-=-=-=-=-=-=- ");

printf(" Access Denied. ");

printf(" -=-=-=-=-=-=-=-=-=-=-=-=-=- ");

}

}

else {

printf("Unauthorised user! ");

exit(0);

}

}

Perform the static and dynamic code analysis to:

  1. Identify Four (4) vulnerabilities that exist in the code and discuss on the possible attack that can be performed to the code.
  2. Simulate on the attack and show detail evidence(s) on how the attack can be done with screenshot and detail explanation.
  3. Amend the code to provide solution in preventing the attack that being simulated in b) and explain in detail the solution(s) provided.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Network Questions!