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:
- Identify Four (4) vulnerabilities that exist in the code and discuss on the possible attack that can be performed to the code.
- Simulate on the attack and show detail evidence(s) on how the attack can be done with screenshot and detail explanation.
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started