Bonus Points


July 21, 20252 minutes

Para este reto se proporciona un binario

undefined8 main(void)

{
  uint __seed;
  int iVar1;
  char local_1a [10];
  int local_10;
  uint local_c;
  
  local_c = 0;
  __seed = getpid();
  srand(__seed);
  iVar1 = rand();
  local_c = iVar1 % 100;
  puts("Hello, here you can get some bonus points for the competition.");
  puts("You cannot get more than 100 bonus points.");
  puts("If you go above 1000 you win.");
  printf("Your score is currently %u\n",(ulong)local_c);
  printf("How many bonus points do you want?\n>>> ");
  fflush(stdout);
  fgets(local_1a,8,stdin);
  local_10 = atoi(local_1a);
  if (local_10 < 0x65) {
    local_c = local_c + local_10;
    printf("Your new score is %u\n",(ulong)local_c);
    if (local_c < 0x3e9) {
      puts("You should try to get more points");
    }
    else {
      puts("Congratulations! Here is your flag:");
      fflush(stdout);
      system("cat flag.txt");
    }
  }
  else {
    puts("Stop cheating!");
  }
  return 0;
}

Al principio se calcula un número aleatorio ente 0 y 100 y se almacena en local_c

  __seed = getpid();
  srand(__seed);
  iVar1 = rand();
  local_c = iVar1 % 100;

Luego imprime dicho número y le pide al usuario cuantos más puntos quiere, los puntos que quiere el usuario se almacenan en local_10, local_10 es un unsigned int, eso hace que no guarde números negativos.

Por ejemplo al ponerle -1000 es como si se le pusiera 4294966296, eso pasaría la primera validación de sí el input del usuario es < 0x65 y luego al sumarle el número generado aleatoriamente no cumpliría esta condición local_c < 0x3e9 haciendo que muestre la flag

[d3bo@archlinux bonus_points]$ nc localhost 4000
Hello, here you can get some bonus points for the competition.
You cannot get more than 100 bonus points.
If you go above 1000 you win.
Your score is currently 96
How many bonus points do you want?
>>> -1000
Your new score is 4294966392
Congratulations! Here is your flag:
FCSC{XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}