Cryptohack_SYMMETRIC CIPHERS(1)

SYMMETRIC STARTER Passwords as Keys

爆破:

import requests
import tqdm
from Crypto.Cipher import AES
import hashlib
from Crypto.Util.number import *
import tqdm
import random
import binascii

result = requests.get('http://aes.cryptohack.org/passwords_as_keys/encrypt_flag')
ciphertexthex = result.json()["ciphertext"]
print(ciphertexthex)
# ciphertexthex='c92b7734070205bdf6c0087a751466ec13ae15e6f1bcdd3f3a535ec0f4bbae66'
with open('D:/2023/crypto/words.txt', 'r')as f:
    for words in f.readlines():
        words=words.strip()
        #print(words)
        key_1 = hashlib.md5(words.encode()).hexdigest()
        key = bytes.fromhex(key_1)
        cipher = AES.new(key, AES.MODE_ECB)
        ciphertext = bytes.fromhex(ciphertexthex)
        decrypted = cipher.decrypt(ciphertext)
        if b'crypto{' in decrypted:
            print(decrypted)
            break
        #print(decrypted)

BLOCK CIPHERS  ECB CBC WTF

CBC加密 ECB解密,key一样,消除iv等影响即可

result = requests.get('https://aes.cryptohack.org/ecbcbcwtf/encrypt_flag/')
ciphertexthex = result.json()["ciphertext"]
print(ciphertexthex)
iv=ciphertexthex[0:32]
c=ciphertexthex[32:]
c1=int(c[0:32],16)
c2=int(c[32:],16)
print(iv,c)
print(len(c))
result = requests.get('https://aes.cryptohack.org/ecbcbcwtf/decrypt/'+c)
plaintexthex = result.json()["plaintext"]
p1=int(plaintexthex[0:32],16)
p2=int(plaintexthex[32:],16)
iv=int(iv,16)
m1=p1^iv
m2=p2^c1
print(long_to_bytes(m1))
print(long_to_bytes(m2))

BLOCK CIPHERS  ECB Oracle

盲注:


flag="crypto{p3n6u1n5"
while len(flag)<15:
    tmp0='a'*(15-len(flag))
    result = requests.get('https://aes.cryptohack.org/ecb_oracle/encrypt/'+tmp0.encode().hex())
    ciphertexthex = result.json()["ciphertext"]
    ctmp0=ciphertexthex[0:32]
    print(ctmp0)
    for kk in sprint:
        tmp0 = 'a' * (15 - len(flag)) + flag+kk
        result = requests.get('https://aes.cryptohack.org/ecb_oracle/encrypt/' + tmp0.encode().hex())
        ciphertexthex = result.json()["ciphertext"]
        ctmp1 = ciphertexthex[0:32]
        if ctmp1==ctmp0:
            flag+=kk
            print(flag)
            break
print(flag[-15:])
while len(flag)<31:
    tmp0 = 'a' * (31 - len(flag))
    result = requests.get('https://aes.cryptohack.org/ecb_oracle/encrypt/' + tmp0.encode().hex())
    ciphertexthex = result.json()["ciphertext"]
    ctmp0 = ciphertexthex[32:64]
    print(ctmp0)
    for kk in sprint:
        tmp0 =  flag[-15:] + kk
        result = requests.get('https://aes.cryptohack.org/ecb_oracle/encrypt/' + tmp0.encode().hex())
        ciphertexthex = result.json()["ciphertext"]
        ctmp1 = ciphertexthex[0:32]
        if ctmp1 == ctmp0:
            flag += kk
            print(flag)
            break

BLOCK CIPHERS Flipping Cookie

验证时IV可控

expires_at = "11231"
cookie = f"admin=False;expiry={expires_at}".encode()
print(cookie)
padded = pad(cookie, 16)
hex1=padded.hex()
print(hex1)
cookie = f"admin=True;expiry={expires_at}".encode()
print(cookie)
padded = pad(cookie, 16)
hex2=padded.hex()
print(hex2)
bb=int(hex1[0:32],16)^int(hex2[0:32],16)#改造iv

result = requests.get('https://aes.cryptohack.org/flipping_cookie/get_cookie/')
ciphertexthex = result.json()["cookie"]
print(ciphertexthex)
iv=ciphertexthex[0:32]
ivnew=hex(int(iv,16)^bb)[2:]#改造iv
c=ciphertexthex[32:]
print(iv,c,ivnew)
result = requests.get('https://aes.cryptohack.org/flipping_cookie/check_admin/'+c+"/"+ivnew)
print(result.text)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值