Description

We all know that prime numbers are quite important in cryptography. Can you help me to find some?

Solution

Connecting to the running service, I was greated with a message asking for the next prime number after [number]

So with some quick python hackery I ended up with this code.

#!/usr/bin/env python

from pwn import *

def get_next_prime(number):
    """Get next prime after number"""
    for num in range(number+1, number*2):
        if num > 1:
            for y in range(2,num):
                #print '> num %% y = %d %% %d ='%(num,y),(num % y)
                if (num % y) == 0:
                    break
            else:
                return num

host = '188.166.133.53'
port = 11059

r = remote(host, port)
r.recv(1024)
while True:
    orig_data = r.recv(1024)
    data = orig_data.split(' ')[-1]
    log.info(orig_data)
    number = int(data.strip().rstrip(':'))
    next_prime = str(get_next_prime(number))
    log.info('Next prime after %d is %s'%(number, next_prime))
    r.send(next_prime)
    log.info(r.recv(1024))

r.close()

It ran for a little bit before crashing, which I expected, and returning the flag.

Flag: IW{Pr1m3s_4r3_!mp0rt4nt}

Rekt Sec

InternetWatche 2016 CTF - The Secret Store (Web 70)

InternetWatche 2016 CTF - The Secret Store (Web 70) Continue reading