Filtered
Buffer overflow with a flawed length check
Description
Filter invalid sizes to make it secure!
Backup: nc 167.99.78.201 9001
nc filtered.chal.acsc.asia 9001
Solution
First, the user is asked for the data length. If the length is more than 0x100, the program exits.
int length;
char buf[0x100];
/* Read and check length */
length = readint("Size: ");
if (length > 0x100) {
print("Buffer overflow detected!\n");
exit(1);
}
/* Read data */
readline("Data: ", buf, length);
print("Bye!\n");The length is read using atoi():
I came across this thread. Using 2147483648, an integer overflow is caused since the largest unsigned int is 2147483647. Therefore, length will be a negative signed integer, passing the length check.
However, when calling readline(), the length is passed to a size_t argument.
Now, size_t is unsigned, so the permitted size would instead become a large positive integer. We can try this experiment ourselves:
The output would be:
From here, this is a regular buffer overflow challenge. The offset is 280, and we want to jump to the win function here:
Solver script:
Get the flag:
Last updated
Was this helpful?