Buffer Overflow Lab

Details

Please use C language.

  1. define ADMINUID as 0x61646D696E
  2. write a structure USER with username in 8 bits buffer and uid
    • variables: username, password(11-bit), uid(5-bit)
  3. write a login function using gets to get the user data
    • if there isn’t the username, then create a new user and random the uid.
  4. write a menu which design 4 options and 1 of them can show only for admin
    • options:
      1
      2
      3
      4
      1. edit
      2. execute
      3. exit
      7963. flag (only for admin)
  5. write a options function which deal with user’s input.

Source Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ADMINUID 0x61646D696E

struct User{
char username[100];
char password[11];
char uid[5];
};

struct User admin = {"admin", "ej03xu3m06", "admin"};
struct User user;
void login();
void menu(char *uid);
void options(int opt);

int main()
{
int userOption;

login();
scanf("%d", &userOption);
options(userOption);
return 0;
}

void login()
{
printf("Name: ");
gets(user.username);
if(strcmp(user.username, admin.username) != 0){
int i;
for(i = 0;i < 5;i++)
user.uid[i] = 'a' + (random() % 26);
printf("User not found. Createing a new user ... \n");
printf("New Password: ");
gets(user.password);
menu(user.uid);
}else{
printf("Password: ");
gets(user.password);
if(strcmp(user.password, admin.password) == 0){
menu(admin.uid);
}else{
printf("Wrong password.");
exit(0);
}
}
}

void menu(char *uid)
{
printf("1. edit\n");
printf("2. execute\n");
printf("3. exit\n");
if(strcmp(uid, "admin") == 0){
printf("7963. flag\n");
}
printf("? ");
}

void options(int opt)
{
if(opt == 7963){
printf("FLAG{C0IVGra+ula+i0IV_y0u_jus+_expl0i+_+he_pr0gram_wi+h_buffer_0verfl0vv}");
}else{
exit(0);
}
}
  • Copyrights © 2019-2021 NIghTcAt

請我喝杯咖啡吧~