Stairway to Hell

Challenge:

It seems spookyboi still wants proof you're a top-notch programmer. He wants you to create a program that returns one number on the first line, then two consecutive numbers on the second line, then three consecutive numbers on the third line, and so forth.
Here's an example:

1
2 3
4 5 6

He wants you to start with 666 and give 30 rows.

nc env2.hacktober.io 5001

Solution:

I found this challenge extremely frustrating and spent way too much time getting a working solution, and based on the conversations in the CTF Slack channel I wasn't alone. An admin eventually shared on Slack that we should be stripping newlines, which contradicted the challenge description since instead of generating a string of "stairs" the removal of newlines would result in a single line of consecutive numbers.

That hiccup aside the core of the challenge was still to code a triangular number series generator:

from pwn import *
context.log_level = 'critical'
r = remote('env2.hacktober.io', 5001)
r.recvuntil("\n\n")
stair = 666
answr = ""
for x in range(1, 31):
    for y in range(x):
        answr += f"{stair} "
        stair += 1
r.sendline(answr.rstrip())
print(r.recv().decode())
r.close()

Running the script provides the flag:

$ python3 solve_stairway.py

flag{plung3_to_the_4by55}

Published:

Updated:

Leave a comment