Doubler
Description
pwn/doubler (by hmmm) | 392 points
A very simple program.
nc doubler.hsctf.com 1337
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 Compiler to run the program
└─$ gcc solve.c -o solve
./solve
{OUTPUT}
└─$ nc doubler.hsctf.com 1337
Input: {OUTPUT}
Doubled: -100
flag{REDACTED}
Last updated