Doubler

Description

pwn/doubler (by hmmm) | 392 points

A very simple program.

nc doubler.hsctf.com 1337

Downloads: challarrow-up-right, chall.carrow-up-right

Analysis

Program wants value of -100, but input cannot be negative number.

Since program is written in C (Statically typed language), we can cause an overflow of type int which when overflowed will cycle to lowest number (negative 2**31)

Solution

#include <stdio.h>
#include <limits.h>

int main() {
    int max = INT_MAX, doubled;
    for (int i=0; i < 100; i++) {
        doubled = (max - i) * 2;
        if (doubled == -100) {
            printf("%d\n", max - i);  
            break;
        } 
    }
    
    return 0;
}

Note: You can use an Online Compilerarrow-up-right to run the program

Last updated