Follow us on twitter

Donate Bitcoins

About

This level takes a look at code flow hijacking in data overwrite cases.

This level is at /opt/protostar/bin/heap1

Source code

 1#include <stdlib.h>
 2#include <unistd.h>
 3#include <string.h>
 4#include <stdio.h>
 5#include <sys/types.h>
 6
 7  
 8
 9struct internet {
10  int priority;
11  char *name;
12};
13
14void winner()
15{
16  printf("and we have a winner @ %d\n", time(NULL));
17}
18
19int main(int argc, char **argv)
20{
21  struct internet *i1, *i2, *i3;
22
23  i1 = malloc(sizeof(struct internet));
24  i1->priority = 1;
25  i1->name = malloc(8);
26
27  i2 = malloc(sizeof(struct internet));
28  i2->priority = 2;
29  i2->name = malloc(8);
30
31  strcpy(i1->name, argv[1]);
32  strcpy(i2->name, argv[2]);
33
34  printf("and that's a wrap folks!\n");
35}
36

Discussion