-
Notifications
You must be signed in to change notification settings - Fork 0
/
cards.c
203 lines (188 loc) · 3.96 KB
/
cards.c
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include"SECCOMP.h"
#define TRUE 1
#define FALSE 0
#define SAD 9999
struct sock_filter seccompfilter[]={
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, ArchField),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, AUDIT_ARCH_X86_64, 1, 0),
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL),
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, SyscallNum),
Allow(read),
Allow(write),
Allow(open),
Allow(mprotect),
Allow(rt_sigreturn),
Allow(brk),
Allow(exit),
Allow(exit_group),
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_KILL),
};
struct sock_fprog filterprog={
.len=sizeof(seccompfilter)/sizeof(struct sock_filter),
.filter=seccompfilter
};
typedef struct cardinfo{
long int size_name_card;
long int ncards;
char *name_of_card;
}CARD_INFO;
typedef struct card{
long int cardnumber;
char color[0x8];
CARD_INFO *card;
long int iscard;
}CARD;
int total_cards = 0;
CARD *mycard[0x10];
unsigned int sizes[0x10];
int checks[0x10];
void apply_seccomp(){
if(prctl(PR_SET_NO_NEW_PRIVS,1,0,0,0)){
perror("Seccomp Error");
exit(1);
}
if(prctl(PR_SET_SECCOMP,SECCOMP_MODE_FILTER,&filterprog)==-1){
perror("Seccomp Error");
exit(1);
}
return;
}
void exit_error(char *error)
{
printf("%s.\n",error);
exit(SAD);
}
int return_number()
{
char buff[0x10];
int i;
read(0,buff,0x3);
i = atoi(buff);
return i;
}
void delete()
{
unsigned int idx;
printf("Enter index of the card: ");
idx = return_number();
if(idx>total_cards||checks[idx]){
puts("No");
return;
}
free(mycard[idx]);
free(mycard[idx]->card);
free(mycard[idx]->card->name_of_card);
checks[idx]=1;
printf("Done.\n");
}
void edit_name()
{
unsigned int idx;
printf("Enter the index of the card: ");
idx = return_number();
if(idx>total_cards||!mycard[idx]->iscard) {
puts("Nope");
return;
}
printf("Enter new name: ");
read(0,mycard[idx]->card->name_of_card,sizes[idx]);
puts("Edited");
}
void view()
{
unsigned int idx;
printf("Enter the index of the card: ");
idx = return_number();
if(idx>total_cards||checks[idx]) {
puts("Nope");
return;
}
printf("===============================\n");
printf("Card No: %ld.\n",mycard[idx]->cardnumber);
printf("Card Size: %ld.\n",mycard[idx]->card->size_name_card);
printf("Card name: %s.\n",mycard[idx]->card->name_of_card);
}
void add()
{
unsigned int size;
if(total_cards>0x8) {
exit_error("No");
}
mycard[total_cards] = (CARD*)malloc(0x28);
mycard[total_cards]->cardnumber=total_cards;
printf("Enter size of the name of the card: ");
size=return_number();
if(size>0x100){
exit_error("I'm not sure but you are not allowed to do that");
}
mycard[total_cards]->card = (CARD_INFO *)malloc(0x28);
mycard[total_cards]->card->size_name_card = size;
mycard[total_cards]->iscard = TRUE;
mycard[total_cards]->card->name_of_card = malloc(size);
mycard[total_cards]->card->ncards = total_cards;
printf("Enter card color: ");
read(0,mycard[total_cards]->color,0x7);
printf("Enter name: ");
read(0,mycard[total_cards]->card->name_of_card,size);
printf("Done.\n");
sizes[total_cards]=size;
total_cards++;
}
void menu()
{
printf("=========================\n");
printf("|1.|Add card. ||\n");
printf("|2.|Remove card. ||\n");
printf("|3.|Edit name. ||\n");
printf("|4.|View card. ||\n");
printf("|5.|Exit. ||\n");
printf("=========================\n");
printf("Choice: ");
}
void initialize()
{
setvbuf(stdin,NULL,_IONBF,0);
setvbuf(stdout,NULL,_IONBF,0);
alarm(60);
apply_seccomp();
return;
}
int main()
{
int choice;
char name[0x40];
initialize();
while(TRUE) {
menu();
choice = return_number();
switch(choice) {
case 1:
add();
break;
case 2:
delete();
break;
case 3:
edit_name();
break;
case 4:
view();
break;
case 5:
printf("Bye.\n");
exit(TRUE);
case 6:
printf("Enter your secret name: ");
read(0,name,0x40);
break;
default:
printf("Sad.\n");
break;
}
}
return 0;
}