ex:vcode:start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| ex:vcode:start [2023/04/10 21:05] – ebaer | ex:vcode:start [2023/07/31 05:51] (current) – titannet | ||
|---|---|---|---|
| Line 141: | Line 141: | ||
| + | </ | ||
| + | ====== Heap2-2 ====== | ||
| + | |||
| + | |||
| + | <code c> | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Use after free example, original code from https:// | ||
| + | |||
| + | #define SERVICE_SIZE 32 | ||
| + | |||
| + | struct AuthStruct { | ||
| + | char name[32]; | ||
| + | int is_authenticated; | ||
| + | }; | ||
| + | |||
| + | struct AuthStruct *auth; | ||
| + | char *service; | ||
| + | |||
| + | int main(int argc, char **argv) | ||
| + | { | ||
| + | char line[128]; | ||
| + | |||
| + | while(1) { | ||
| + | printf(" | ||
| + | if(fgets(line, | ||
| + | | ||
| + | if(strncmp(line, | ||
| + | auth = malloc(sizeof(*auth)); | ||
| + | memset(auth, | ||
| + | if(strlen(line + 5) < 31) { | ||
| + | strcpy(auth-> | ||
| + | } | ||
| + | } | ||
| + | if(strncmp(line, | ||
| + | free(auth); | ||
| + | } | ||
| + | if(strncmp(line, | ||
| + | service = malloc(SERVICE_SIZE); | ||
| + | strcpy(service, | ||
| + | } | ||
| + | if(strncmp(line, | ||
| + | if(auth-> | ||
| + | printf(" | ||
| + | } else { | ||
| + | printf(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
ex/vcode/start.1681153518.txt.gz · Last modified: 2023/04/10 21:05 by ebaer
