1 #include <libcgc.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 /* CGC DECREE binary exploitation test */
6
print_banner()7 static void print_banner()
8 {
9 printf("Welcome to Addr\n");
10 }
11
print_menu()12 static void print_menu()
13 {
14 printf("1) Add number to the array\n");
15 printf("2) Add random number to the array\n");
16 printf("3) Sum numbers\n");
17 printf("4) Exit\n");
18 }
19
main(int secret_flag_i)20 void __attribute__((fastcall)) main(int secret_flag_i)
21 {
22 unsigned idx, val;
23 char cmd[2];
24 int sum = 0;
25 int i;
26 unsigned iarr[32] = {0};
27
28 void *secret_page = (void *)secret_flag_i;
29
30 while(1) {
31 print_menu();
32 receive(0, &cmd, 2, NULL);
33
34 switch(cmd[0]) {
35 case '1':
36 printf(" Index: ");
37 receive(0, &idx, 4, NULL);
38 if (idx > 0x32) {
39 printf("Bad index\n");
40 break;
41 }
42 receive(0, &val, 4, NULL);
43 iarr[idx] += val;
44 printf("\n");
45 break;
46 case '2':
47 iarr[0] = *((int *)secret_page);
48 printf("Randomness added\n");
49 break;
50 case '3':
51 for(i=0;i<sizeof(iarr)/sizeof(int);i++)
52 sum += iarr[i];
53 printf("Sum: (");
54 transmit(1, &sum, 4, NULL);
55 printf(")\n");
56 break;
57 case '4':
58 return;
59 default:
60 printf("Bad CMD\n");
61 }
62 }
63
64 }
65