def decode(self, work): if work: job = Object() if not "target" in work: work["target"] = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000" binary_data = work["data"].decode("hex") data0 = np.zeros(64, np.uint32) data0 = np.insert(data0, [0] * 16, unpack("IIIIIIIIIIIIIIII", binary_data[:64])) job.target = np.array(unpack("IIIIIIII", work["target"].decode("hex")), dtype=np.uint32) job.header = binary_data[:68] job.merkle_end = np.uint32(unpack("I", binary_data[64:68])[0]) job.time = np.uint32(unpack("I", binary_data[68:72])[0]) job.difficulty = np.uint32(unpack("I", binary_data[72:76])[0]) job.state = sha256(STATE, data0) job.f = np.zeros(9, np.uint32) job.state2 = partial(job.state, job.merkle_end, job.time, job.difficulty, job.f) job.targetQ = 2 ** 256 / int("".join(list(chunks(work["target"], 2))[::-1]), 16) if self.phatk2: calculateF2(job.state, job.merkle_end, job.time, job.difficulty, job.f, job.state2) else: calculateF(job.state, job.merkle_end, job.time, job.difficulty, job.f, job.state2) return job
def _getblobfilename(self, blobid): if self.blobdir is None: raise RuntimeError("no blobs seen, so no blob directory created") - # XXX should escape ":" for windows - return os.path.join(self.blobdir, "blob-" + blobid) + h = sha256(blobid).hexdigest() + h_comp = list(grouper(h, 3, ''))
def decode(self, server, block_header, target, job_id = None, extranonce2 = None): if block_header: job = Object() binary_data = block_header.decode('hex') data0 = np.zeros(64, np.uint32) data0 = np.insert(data0, [0] * 16, unpack('IIIIIIIIIIIIIIII', binary_data[:64])) job.target = np.array(unpack('IIIIIIII', target.decode('hex')), dtype=np.uint32) job.header = binary_data[:68] job.merkle_end = np.uint32(unpack('I', binary_data[64:68])[0]) job.time = np.uint32(unpack('I', binary_data[68:72])[0]) job.difficulty = np.uint32(unpack('I', binary_data[72:76])[0]) job.state = sha256(STATE, data0) job.f = np.zeros(8, np.uint32) job.state2 = partial(job.state, job.merkle_end, job.time, job.difficulty, job.f) job.targetQ = 2**256 / int(''.join(list(chunks(target, 2))[::-1]), 16) job.job_id = job_id job.extranonce2 = extranonce2 job.server = server calculateF(job.state, job.merkle_end, job.time, job.difficulty, job.f, job.state2) if job.difficulty != self.difficulty: self.set_difficulty(job.difficulty) return job
def test_sha256(): msg = string_to_bytes("abc") h = sha256(msg) assert h == 0xBA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD msg = string_to_bytes("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") h = sha256(msg) assert h == 0x248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 msg = string_to_bytes("abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu") h = sha256(msg) assert h == 0xcf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1 # 1024 bit message msg = string_to_bytes("9l5mXBb7Lprxjzb62CEvl2rBWGoFa5dmE45TmMFPQyjgM4wgZy2rmAK51sSCAAzcw5bw1S4k5MG8PZJr1lr6ZPdjPIzhHZnH79qvLcbBPFbkgF8l1HCL9FNKQMJ8aqyl") h = sha256(msg) assert h == 0x60342523c09563657e7063cb2ec72dd32bf57318c18e6410eb7a538b63906250
def ticket531(key): job64 = attachment(key,'531','job') job = base64.b64decode(job64) mac = attachment(key,'531','mac') lenData = (16+len(job))*8 lenP = 64-((16+len(job)%64)) p = [] p.append(0x80) for i in range(lenP-3): p.append(0x00) p.append(lenData>>8 & 0xff) p.append(lenData & 0xff) s= [ 0x0 ] newJob = list(job) + p + s newmac = sha256(s=bytes(s),IV=mac).hexdigest() print(gateway(key,'/service/police/request','/dev/pr1nt0rz','POST',job=base64.b64encode(bytes(newJob)).decode(),mac=newmac))
def ticket562(self): job64 = self.srequest('GET', '/bin/police_hq/ticket/562/attachment/job', {}, 'police') job = base64.b64decode(job64) mac = self.srequest('GET', '/bin/police_hq/ticket/562/attachment/mac', {}, 'police') lenData = (16+len(job))*8 lenP = 64-((16+len(job)%64)) p = [] p.append(0x80) for i in range(lenP-3): p.append(0x00) p.append(lenData>>8 & 0xff) p.append(lenData & 0xff) s= [ 0x0 ] newJob = list(job) + p + s newmac = sha256(s=bytes(s),IV=mac).hexdigest() print(self.srequest('POST','/dev/pr1nt0rz',{'job':base64.b64encode(bytes(newJob)).decode(),'mac':newmac}, 'police'))
def ticket531test(key,mac2): job = "This is the job" clef = "Ceci est la clef" #mac = sha256((clef+job).encode()).hexdigest() #print(mac) lenData = (16+len(job))*8 lenP = 64-((16+len(job)%64)) p = [] p.append(0x80) for i in range(lenP-3): p.append(0x00) p.append(lenData>>8 & 0xff) p.append(lenData & 0xff) s= [ 0x0 ] newJob = list(clef.encode()) + list(job.encode()) newJob += p newJob += s print(newJob) #newmac = sha256(bytes(s),IV=mac2).hexdigest() #print(newmac) realmac = sha256(bytes(newJob)).hexdigest() print(realmac) print(gateway(key,'/service/police/request','/bin/sha256sum','POST',M=base64.b64encode(bytes(newJob)).decode()))
def decode(self, server, block_header, target, job_id=None, extranonce2=None): if block_header: job = Object() binary_data = block_header.decode('hex') data0 = np.zeros(64, np.uint32) data0 = np.insert(data0, [0] * 16, unpack('IIIIIIIIIIIIIIII', binary_data[:64])) job.target = np.array(unpack('IIIIIIII', target.decode('hex')), dtype=np.uint32) job.header = binary_data[:68] job.merkle_end = np.uint32(unpack('I', binary_data[64:68])[0]) job.time = np.uint32(unpack('I', binary_data[68:72])[0]) job.difficulty = np.uint32(unpack('I', binary_data[72:76])[0]) job.state = sha256(STATE, data0) job.f = np.zeros(8, np.uint32) job.state2 = partial(job.state, job.merkle_end, job.time, job.difficulty, job.f) job.targetQ = 2**256 / int(''.join(list(chunks(target, 2))[::-1]), 16) job.job_id = job_id job.extranonce2 = extranonce2 job.server = server calculateF(job.state, job.merkle_end, job.time, job.difficulty, job.f, job.state2) if job.difficulty != self.difficulty: self.set_difficulty(job.difficulty) return job
def decode(self, work): if work: job = Object() if not 'target' in work: work['target'] = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000' binary_data = work['data'].decode('hex') data0 = np.zeros(64, np.uint32) data0 = np.insert(data0, [0] * 16, unpack('IIIIIIIIIIIIIIII', binary_data[:64])) job.target = np.array(unpack('IIIIIIII', work['target'].decode('hex')), dtype=np.uint32) job.header = binary_data[:68] job.merkle_end = np.uint32(unpack('I', binary_data[64:68])[0]) job.time = np.uint32(unpack('I', binary_data[68:72])[0]) job.difficulty = np.uint32(unpack('I', binary_data[72:76])[0]) job.state = sha256(STATE, data0) job.f = np.zeros(8, np.uint32) job.state2 = partial(job.state, job.merkle_end, job.time, job.difficulty, job.f) job.targetQ = 2**256 / int(''.join(list(chunks(work['target'], 2))[::-1]), 16) calculateF(job.state, job.merkle_end, job.time, job.difficulty, job.f, job.state2) return job
def origSha256(string): return sha256(string.encode('utf-8')).hexdigest()
from Crypto.Cipher import DES3 from Crypto.Cipher import AES from sha256 import * # from https://github.com/thomdixon/pysha2/blob/master/sha2/sha256.py hash0, hash1, hash2, hash3 = (0x37833c82aec93c6d, 0x668592081ed67c95, 0x2219c1888c430c17, 0x77aebde7e52e924f) aeskey0, aeskey1, aeskey2, aeskey3 = (0x3e434b0b0aa93bb2, 0x82b03e164d85ce2a, 0x845d334203640aee, 0x2011a08bd4310e26) # encrypted data from server serverdata = binascii.a2b_hex("9095410de22a3275db680010ba0c9942e28a84ca1264f2a222529d7d992e67fba149bb634882b48495bd783c6852d132b637c0d9413969518fbcfd5823e545c7") cr = AES.new(struct.pack(">QQQQ", aeskey0, aeskey1, aeskey2, aeskey3), AES.MODE_ECB) keydata = cr.decrypt(serverdata) # keydata goes through one internal round of SHA256 but initial values are nonstandard h = sha256() h._h = (hash0 >> 32, hash0 & 0xffffffff, hash1 >> 32, hash1 & 0xffffffff, hash2 >> 32, hash2 & 0xffffffff, hash3 >> 32, hash3 & 0xffffffff) h._sha256_process(keydata) # decrypt creds.txt file iv0, iv1 = (0xb6fa1d15ed46055d, 0x96e7f1e8cb561781) ct = open("creds.txt", "rb").read() cr = AES.new(struct.pack(">IIIIIIII", h._h[0], h._h[1], h._h[2], h._h[3], h._h[4], h._h[5], h._h[6], h._h[7]), AES.MODE_CBC, struct.pack(">QQ", iv0, iv1)) print cr.decrypt(ct) # decrypt hacked message with 3DES key0, key1, key2, iv = (0x6011b396042a187a, 0xafebe6d990f0c393, 0x7e7b44705a7100e1, 0x92097f6e08112274) data = open("a.out", "rb").read() ct = data[0x2010:0x2e38] cr = DES3.new(struct.pack(">QQQ", key0, key1, key2), DES3.MODE_CBC, struct.pack(">Q", iv))
self.blobdir = None + self.compress = compress + self.blob_tree = blob_tree + self.blob_tree_depth = blob_tree_depth + def setup(self): """Setup before processing any streams.""" pass @@ -187,12 +200,24 @@ class HgImportProcessor(processor.Import def _getblobfilename(self, blobid): if self.blobdir is None: raise RuntimeError("no blobs seen, so no blob directory created") - # XXX should escape ":" for windows - return os.path.join(self.blobdir, "blob-" + blobid) + h = sha256(blobid).hexdigest() + h_comp = list(grouper(h, 3, '')) + if len(h_comp) > self.blob_tree_depth: + h_comp = h_comp[:self.blob_tree_depth] + [''.join(list(itertools.chain(*h_comp[self.blob_tree_depth:])))] + #self.ui.status("mapping blobid %s to %s\n" % (blobid, h)) + return os.path.join(self.blobdir, *[''.join(x) for x in h_comp]) def getblob(self, fileid): (commitid, blobid) = fileid - f = open(self._getblobfilename(blobid), "rb") + fn = self._getblobfilename(blobid) + try: + if self.compress: + f = gzip.open(fn, "rb") + else: + f = open(fn, "rb")
hash0, hash1, hash2, hash3 = (0x37833c82aec93c6d, 0x668592081ed67c95, 0x2219c1888c430c17, 0x77aebde7e52e924f) aeskey0, aeskey1, aeskey2, aeskey3 = (0x3e434b0b0aa93bb2, 0x82b03e164d85ce2a, 0x845d334203640aee, 0x2011a08bd4310e26) # encrypted data from server serverdata = binascii.a2b_hex( "9095410de22a3275db680010ba0c9942e28a84ca1264f2a222529d7d992e67fba149bb634882b48495bd783c6852d132b637c0d9413969518fbcfd5823e545c7" ) cr = AES.new(struct.pack(">QQQQ", aeskey0, aeskey1, aeskey2, aeskey3), AES.MODE_ECB) keydata = cr.decrypt(serverdata) # keydata goes through one internal round of SHA256 but initial values are nonstandard h = sha256() h._h = (hash0 >> 32, hash0 & 0xffffffff, hash1 >> 32, hash1 & 0xffffffff, hash2 >> 32, hash2 & 0xffffffff, hash3 >> 32, hash3 & 0xffffffff) h._sha256_process(keydata) # decrypt creds.txt file iv0, iv1 = (0xb6fa1d15ed46055d, 0x96e7f1e8cb561781) ct = open("creds.txt", "rb").read() cr = AES.new( struct.pack(">IIIIIIII", h._h[0], h._h[1], h._h[2], h._h[3], h._h[4], h._h[5], h._h[6], h._h[7]), AES.MODE_CBC, struct.pack(">QQ", iv0, iv1)) print cr.decrypt(ct) # decrypt hacked message with 3DES key0, key1, key2, iv = (0x6011b396042a187a, 0xafebe6d990f0c393,
padlen = 512 - (len(tot.encode()) * 8) % 512 - 64 padlen = int(padlen / 8) - 2 print("padd len = ", padlen) tot_len = (len(tot.encode()) * 8 + padlen) / 8 print("longueure totale", tot_len) print(hex(len(tot) * 8)) i = int(hex(len(tot) * 8), base=16) h = "{0:016x}".format(i) print("{0:016x}".format(i)) print(base64.b16decode(h)) padding = b'\x80\x00' + padlen * b'\x00' + base64.b16decode(h) print(padding) ##Ok on a le bon badding, maintenant il nous faut le suffixe s1 = sha256(tot.encode() + padding) h1 = s1.hexdigest() print(h1) tot2 = (k2 + asser['query']).encode() + padding + my_query.encode() i = int(hex(len(tot2) * 8), base=16) h = "{0:016x}".format(i) print(h) padlen = 512 - (len(tot2) * 8) % 512 - 64 padlen = int(padlen / 8) - 2 paddingleft = b'\x80\x00' + padlen * b'\x00' + base64.b16decode(h) print(c.post(bin, M=base64.b64encode(tot2 + paddingleft).decode())) print(paddingleft) final = my_query.encode() + paddingleft print(final)