Ejemplo n.º 1
0
    def _unlock(self, current_sss_tree, key_slot_unlock_data):
        if "key_slot_id" in current_sss_tree:
            key_slot_id = current_sss_tree["key_slot_id"]
            key_slot = self.data["key_slots"][key_slot_id]
            auth_module = AUTH_TYPE_MAP[key_slot["auth_type"]]
            cur_key_slot_unlock_data = key_slot_unlock_data[key_slot_id]

            if cur_key_slot_unlock_data is None:
                return None

            return auth_module.unlock_key_slot(key_slot,
                                               cur_key_slot_unlock_data)

        unlocked_nonces = []
        for child in current_sss_tree["children"]:
            child_nonce = self._unlock(child, key_slot_unlock_data)
            if child_nonce is not None:
                unlocked_nonces.append(child_nonce)

                if len(unlocked_nonces
                       ) == current_sss_tree["required_auth_count"]:
                    break

        else:
            # We don't have enough info to unlock this tree :(
            return None

        return SecretSharer.recover_secret(unlocked_nonces)
def decrypt_secret(fragments):

    total_fragment = str(fragments[0]).count('^') + 1

    data = [[] for _ in range(total_fragment)]

    for line in fragments:
        temp = str(line).split('^')

        for i in range(total_fragment):
            data[i].append(temp[i])

    key = ""

    for i in range(total_fragment):
        tmp = SecretSharer.recover_secret(data[i])
        expected_length = 10
        if (i == total_fragment - 1):
            expected_length = 4

        tmp = "0" * (expected_length - len(tmp)) + tmp

        key += tmp

    return str(key)
Ejemplo n.º 3
0
def shamirs_join(list, str):
    temp = []
    msg_alpha = SecretSharer.recover_secret(list[0:2])
    msg_alpha = '1-' + msg_alpha
    temp.append(msg_alpha)
    temp.append(str)
    text = PlaintextToHexSecretSharer.recover_secret(temp[0:2])
    return text
Ejemplo n.º 4
0
def recover(s):
    db = []

    for i in range(np.shape(s)[1]):
        for j in range(np.shape(s)[2]):
            tmp1 = []
            for k in range(np.shape(s)[0]):
                tmp1.append(str(k + 1) + "-" + str(hex(s[k][i][j]))[2:-1])
            answer = Shamir.recover_secret(tmp1)
            if len(answer) % 2 == 1:
                answer = '0' + answer
            db.append(answer.decode('hex'))
    return db
Ejemplo n.º 5
0
def Recover():
  lines = read_in()
  lines = json.dumps(lines)  # remove [u']
  # print "Recover input:", lines, ",type ", type(lines)
  lines = lines.replace("[", "").replace(
      "]", "").replace('"', "")  # remove [,",]

  lines = lines.split(", ")  # divide by comma,
  # print "lines[0]: ", lines[0]
  # print "lines[1]: ", lines[1]
  # print "len(lines) : ", len(lines)
  f = file("./pk.pem", "r")
  line = f.readline()
  line = line.replace("<PublicKey:", "").replace(">", "")
  pub = PublicKey(int(line))
  g = file("./sk.pem", "r")
  line = g.readline()
  line = line.replace("<PrivateKey:", "").replace(">", "")
  priv = PrivateKey(int(line.split()[0]), int(line.split()[1]))
  cipher = []
  for item in range(0, len(lines)):
    cipher = lines[item].split(" ")
    c1 = cipher[0]
    c2 = cipher[1]
    c3 = cipher[2]
    decrypt_tmp1 = decrypt(priv, pub, int(c1))
    decrypt_tmp1 = str(decrypt_tmp1).decode('hex')
    decrypt_tmp2 = decrypt(priv, pub, int(c2))
    decrypt_tmp2 = str(decrypt_tmp2).decode('hex')
    decrypt_tmp3 = decrypt(priv, pub, int(c3))
    decrypt_tmp3 = str(decrypt_tmp3).decode('hex')
    # print decrypt_tmp1, decrypt_tmp2, decrypt_tmp3,
    shares = ["" for x in range(3)]
    shares[0] = '1-' + str(decrypt_tmp1)
    shares[1] = '2-' + str(decrypt_tmp2)
    shares[2] = '3-' + str(decrypt_tmp3)
    RecoverShare = SecretSharer.recover_secret(shares[0:3])
    print RecoverShare
Ejemplo n.º 6
0
def recover(shares):  #shares:List
    return SecretSharer.recover_secret(shares)
Ejemplo n.º 7
0
 def recoverKey(cls, shares):
     return SecretSharer.recover_secret(shares)
Ejemplo n.º 8
0
    passwords = list(set(open(potfile, "r").read().splitlines()))
    current_level = json.load(open(inferno_ball))
    level_hashes = current_level["hashes"]
    level_ciphertext = current_level["ciphertext"]
    level_shares = current_level["shares"]

    shares = []

    for password in passwords:
        password = password.rstrip()
        index = level_hashes.index(password.split(":", 1)[0])
        share = level_shares[index]
        xored = pxor(password.split(":", 1)[1], share)
        shares.append(str(xored))

    secret = SecretSharer.recover_secret(shares)

    decrypted = decrypt(level_ciphertext, secret.zfill(32).decode('hex'))
    try:
        decrypted = json.loads(decrypted)
        print("Level-up success! SECRET: %s" % secret)
        decrypted["ciphertext"] = str(decrypted["ciphertext"])
        decrypted["hashes"] = [str(s) for s in decrypted["hashes"]]
        decrypted["shares"] = [str(s) for s in decrypted["shares"]]
        decrypted["easteregg"] = str(decrypted["easteregg"])
        print("Next level's easter-egg: %s" % decrypted["easteregg"])
        output_hashes = open(output_path + ".hashes", "w")
        output_json = open(output_path + ".json", "w")
        for h in decrypted["hashes"]:
            output_hashes.write(h + "\n")
        json.dump(decrypted, output_json)
Ejemplo n.º 9
0
# print BitcoinToB32SecretSharer.recover_secret(shares[0:7])
s = []

for x in shares:
	x = x.lower()
	s.append(x)
p = s[0]
a1 = s[0:3]
a2 = s[4:7]
a2.append(p)
print '所有密钥值:'.decode('utf-8')
for x in s:print x
print ''

print '组织1 解密文本:'.decode('utf-8')
key1 = SecretSharer.recover_secret(a1)
print key1
print ''
print '组织2 解密文本:'.decode('utf-8')
s.append(s[0])
key2 = SecretSharer.recover_secret(a2)

print key2
print ''
print 'key1:'
print key1.encode('hex')
print 'key2:'
print key2.encode('hex')
print ''
ss = []
ss.append(shares[0].lower())
Ejemplo n.º 10
0
def getInformation(self, input_folder):

    images = []

    for files in os.listdir(input_folder):

        if files.endswith('.png'):
            images.append(os.path.join(input_folder, files))


    self.encrypto_progress.setValue(30)

    kkey, dataList, ivValueList, structLenList, hmacList, checksum = findInformation(images)

    self.encrypto_progress.setValue(40)
    removeList = []

    for n, elem in enumerate(checksum):

        temp = hashlib.sha256(kkey[n].encode() + dataList[n] + hmacList[n]).digest()

        # print(n, elem, temp)

        if elem == temp:

            print("%d CheckSum Assertion Success" % n)

        else:

            print("%d CheckSum Assertion Failed" % n)

            removeList.append(n)

    removeList.reverse()

    for i in removeList:
        del kkey[i]

        del dataList[i]

        del ivValueList[i]

        del structLenList[i]

        del hmacList[i]

        del checksum[i]

    recoverdKey = SecretSharer.recover_secret(kkey)

    self.encrypto_progress.setValue(50)

    if len(recoverdKey) % 64 != 0:
        length = 64 - (len(recoverdKey) % 64)

        recoverdKey = '0' * length + recoverdKey

    recoverdKey = makeKeyFromAscii(recoverdKey)

    self.encrypto_progress.setValue(60)

    for i in range(0, len(dataList)):

        recvFileName = 'recovered_output' + str(i) + '.txt'

        forHmacTest = recoverdKey + dataList[i]

        hashed = hashlib.sha256(forHmacTest).digest()

        if hmacList[i] == hashed:

            print("%d Assertion Success" % i)

        else:

            print("%d Assertion Failed" % i)

        self.encrypto_progress.setValue(80)

        decrypt_file(recoverdKey, ivValueList[i], dataList[i], structLenList[i], out_filename=recvFileName)

        self.encrypto_progress.setValue(90)
Ejemplo n.º 11
0
def recoverSharingKey(shares):
    return makeKeyFromAscii(SecretSharer.recover_secret(shares))
Ejemplo n.º 12
0
Archivo: solve.py Proyecto: welchbj/ctf
#!/usr/bin/env python2

from __future__ import print_function

import binascii

from secretsharing import SecretSharer

SECRETS = [
    '1-9608474170977308238036624146101441469538628637045706610338073590812843162969037926492967854559828114435865261425719619743472419864336210874222029453059741',
    '3-224183841656780872927678242626279871433733831057475254917387185998520511272846647279913467443558309288829498488402883425874249712684215384203475752039681175',
    '4-524164732834933988556388319839274528391312080836319720002737667326861328789556912063222725295339950383555529443266354316704089242529615243887408038702736241',
    '5-1015950427545472565825761297620151258974491880324557727968398393745824130327315926142371765654543965113857776728721730398986530543452098367721676829359089545',
]

hex_secrets = []
for secret in SECRETS:
    idx, num = secret.split('-')
    hex_num = hex(int(num))[2:].rstrip('L')
    hex_secrets.append(idx + '-' + hex_num)

print(hex_secrets)
s = SecretSharer.recover_secret(hex_secrets)
print(s)
print(binascii.unhexlify(s))
Ejemplo n.º 13
0
def send_decrpyted_image(filename,shares,k):
	hexkey = SecretSharer.recover_secret(shares[0:k])
	key = hexkey.decode('hex') 
	aes.decrypt_file(key,filename)