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
| #include<stdio.h> #include <math.h> #include <stdio.h> #include<unistd.h> #include <dirent.h> #include <string.h> #include <sys/stat.h> #include <sys/prctl.h> #include <linux/filter.h> #include <linux/seccomp.h>
void sandbox(){ struct sock_filter filter[] = { BPF_STMT(BPF_LD+BPF_W+BPF_ABS,4), BPF_JUMP(BPF_JMP+BPF_JEQ,0xc000003e,0,2), BPF_STMT(BPF_LD+BPF_W+BPF_ABS,0), BPF_JUMP(BPF_JMP+BPF_JEQ,59,0,1), BPF_STMT(BPF_RET+BPF_K,SECCOMP_RET_KILL), BPF_STMT(BPF_RET+BPF_K,SECCOMP_RET_ALLOW), }; struct sock_fprog prog = { .len = (unsigned short)(sizeof(filter)/sizeof(filter[0])), .filter = filter, }; prctl(PR_SET_NO_NEW_PRIVS,1,0,0,0); prctl(PR_SET_SECCOMP,SECCOMP_MODE_FILTER,&prog); }
int init(){ setvbuf(stdin, 0LL, 2, 0LL); setvbuf(stdout, 0LL, 2, 0LL); return setvbuf(stderr, 0LL, 2, 0LL); }
int num = 0; char *heaparray[0x10]; size_t realsize[0x10];
void create(){ if(num >= 0x20){ puts("no more"); return; } int size; puts("Size of Heap : "); scanf("%d",&size); heaparray[num]=(char *)malloc(size); realsize[num]=size; num++; }
void show(){ int idx ; char buf[4]; printf("Index :\n"); read(0, buf, 4); idx = atoi(buf); if(idx < 0 || idx >= 0x10){ puts("Out of bound!"); _exit(0); } if(heaparray[idx]){ printf("Size : %ld\nContent : %s\n",realsize[idx],heaparray[idx]); puts("Done !"); }else{ puts("No such heap !"); } }
void edit(){ int idx ; char buf[4]; printf("Index :\n"); read(0, buf, 4); idx = atoi(buf); if(idx < 0 || idx >= 0x10){ puts("Out of bound!"); _exit(0); } if(heaparray[idx]){ int size; puts("Size of Heap : "); scanf("%d",&size); printf("Content of heap : \n"); read(0,heaparray[idx],size); puts("Done !"); }else{ puts("No such heap !"); } }
void dele(){ int idx ; char buf[4]; printf("Index :\n"); read(0,buf,4); idx = atoi(buf); if(idx < 0 || idx >= 0x10){ puts("Out of bound!"); _exit(0); } if(heaparray[idx]){ free(heaparray[idx]); realsize[idx] = 0 ; heaparray[idx] = NULL; puts("Done !"); num--; }else{ puts("No such heap !"); } }
void menu(void){ puts("1.create"); puts("2.dele"); puts("3.edit"); puts("4.show"); }
void main(){ init(); sandbox(); int choice; while(1){ menu(); scanf("%d",&choice); switch(choice) { case 1:create();break; case 2:dele();break; case 3:edit();break; case 4:show();break; default:puts("error"); } } }
|