我使用AES方法加密从txt文件调用的句子。我使用了 GCM 模式并创建了一个特定的密钥。一切正常(代码如下)。
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import scrypt
from Crypto.Util.number import long_to_bytes
number = 1
flag = open("sentance.txt", "rb").read()
key = scrypt(long_to_bytes(number), b"code", 32, N = 2 ** 10, r = 8, p = 1)
HexMyKey = key.hex()
cipher = AES.new(key, AES.MODE_GCM)
ciphertext, tag = cipher.encrypt_and_digest(flag)
enc = cipher.nonce + ciphertext + tag
HexEncryptedOriginalMessage = enc.hex()
Run Code Online (Sandbox Code Playgroud)
我尝试实现解密过程,也就是说我只有密钥(HexMyKeyvalue)和加密消息(HexEncryptedOriginalMessage值),我想解密它。但问题是我错过了一些东西..
我写了下面的代码,但我有那个错误消息。
类型错误:decrypt_and_verify() 缺少 1 个必需的位置参数:'received_mac_tag
from Crypto.Cipher import AES
from Crypto.Protocol.KDF import scrypt
from Crypto.Util.number import …Run Code Online (Sandbox Code Playgroud) 这是缓冲区溢出的二进制文件的摘录。我用 Ghidra 反编译了它。
char local_7 [32];
long local_78;
printf("Give it a try");
gets(local_7);
if (local_78 != 0x4141414141414141) {
if (local_78 == 0x1122334455667788) {
puts ("That's won")
}
puts("Let's continue");
}
Run Code Online (Sandbox Code Playgroud)
我想了解为什么可能会发生缓冲区溢出。
我检查了“0x4141414141414141”十六进制值,发现它与“A”字符串有关。但是与“0x4141414141414141”和“0x1122334455667788”相关的条件究竟是做什么的?更准确地说,用户可以回答什么来获得消息(“那是赢了”)?
任何解释将不胜感激,谢谢!
___EDIT ___
我必须补充一点,我在使用“disas main”命令时看到了这两个十六进制值:
0x00000000000011a7 <+8>: movabs $0x4141414141414141,%rax
0x00000000000011e6 <+71>: movabs $0x4141414141414141,%rax
0x00000000000011f6 <+87>: movabs $0x1122334455667788,%rax
Run Code Online (Sandbox Code Playgroud)
我尝试使用python3 -c "print ('A' * 32 +'\x88\x77\x66\x55\x44\x33\x22\x11')" | ./ myBinary.
但我总是有"Let's continue"消息。我离解决方案不远了,但我想我错过了一件事..你能帮我什么吗?
___EDIT 2 ___ 在获取之前:
char local_7 [40];
long local_78;
local_78 = 0x4141414141414141;
printf("Give it a …Run Code Online (Sandbox Code Playgroud)