-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
45 lines (31 loc) · 931 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from glob import glob
from binascii import a2b_hex
from time import sleep
from flask import Flask, request, abort
app = Flask(__name__)
known_hashes = set()
def init():
for name in glob("data/*/*/*/*/*"):
h = name.split("/")[-1]
known_hashes.add(a2b_hex(h))
init()
@app.route("/index.mth", methods=["POST"])
def index_mth():
data = request.data
if not data.startswith("MTHS"):
abort(400)
result = set()
count = (len(data) - 6) / 20
for i in range(count):
h = data[6 + i * 20:26 + i * 20]
if h in known_hashes:
result.add(h)
response = "MTHS\x00\x01"
response += "".join(result)
print "Found {} files, not found {} files.".format(len(result), count - len(result))
return response
@app.route("/")
def root():
return "This server knows {} files.".format(len(known_hashes))
if __name__ == "__main__":
app.run(debug=True)