Created
August 26, 2017 11:11
-
-
Save quandqn/83cf812aded9b439b6ef16433b0df157 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
import re | |
import time | |
import socket | |
import hashlib | |
import scrypt as sc | |
IP = '47.88.216.38' | |
PORT = 20013 | |
def md5(bytestring): | |
return hashlib.md5(bytestring).digest() | |
def sha(bytestring): | |
return hashlib.sha1(bytestring).digest() | |
def blake(bytestring): | |
return hashlib.blake2b(bytestring).digest() | |
def scrypt(bytestring): | |
l = int(len(bytestring) / 2) | |
salt = bytestring[:l] | |
p = bytestring[l:] | |
return sc.hash(p, salt=salt, N=2**16, r=8, p=1) | |
def xor(s1, s2): | |
return b''.join([bytes([s1[i] ^ s2[i % len(s2)]]) for i in range(len(s1))]) | |
list_hashes = { | |
'md5' : md5, | |
'sha' : sha, | |
'blake' : blake, | |
'scrypt' : scrypt | |
} | |
def recv_until(conn, e): | |
buf = bytes() | |
while not buf.decode().endswith(e): | |
buf += conn.recv(1) | |
return buf | |
conn = socket.socket() | |
conn.connect((IP, PORT)) | |
data = recv_until(conn, 'now!\n').decode() | |
regexr = '\'(.)+\'' | |
m = re.search(regexr, data) | |
import base64 | |
final_hash = base64.b64decode(m.group(0)[1:-1]) | |
print(len(final_hash)) | |
regexpr = '(blake|sha|md5|scrypt)' | |
hash_rounds = re.findall(regexpr, data) | |
interim_salt = final_hash[:64] | |
interim_hash = final_hash[64:] | |
for i in range(31, -1, -1): | |
interim_hash = xor(interim_hash, list_hashes[hash_rounds[i]](interim_salt)) | |
interim_salt = xor(interim_salt, list_hashes[hash_rounds[-1-i]](interim_hash)) | |
h = interim_salt + interim_hash | |
print(h) | |
a = input().encode() | |
conn.send(a + b'\n') | |
print(conn.recv(1024)) | |
print(conn.recv(1024)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment