Encryption
知道明文機密的前 8 個字元後,如何解密 RC4 加密文本?
我在解密作為 CTF 的一部分的秘密消息時遇到困難,我想知道如何解密已使用 pycrypto RC4 加密的加密文本以及何時知道純文字機密的前 8 個字元。這是程式碼中的秘密:
secret = b'Sff3az11oTAChXcnaCvx2i/P7pZWLMPWX7xV0zxFY2XYRhqbik8bS6kQOymHYi3j0ZoP4NFLTtJHR8iXFtljDcDpoFeEnZU0KqQNYPR+ovQ9eQ2iNE0+yCl3+5gLKp838zH26Wdu/N1rr43fYIahah2OxpahqpG/7RmUbhjpSttu+UFk0lytQOM82IIo8B1aPgbBVFNJIxb1f+UQIcUHksW5aG8nQq3/4XNYvMAN2wCWsigvGJAalXShoiA3YSGQCVrMyOlKaJteeU9aehYXzzHyNGEcz1twpVJwfSB/rJ/gYtVh44locd+oCfuKP2UkvFF/PkRm5Cg4Ps1Nn0GBWFzKNR7zwVlQQSx7xEF6yEpR7YH5otNdK55/+LgjXREAR6oD91xL0uY1FossRnAZFag3NxW17wEpeGUwS5yw9GwnB6lhy3jnmZpS2FIRJkl6r6RMXCBIC6lTj0IGm87dNygmoB3pi98exSFsT+l+gFtij36HQp5BOE3UsDz8prfvjM7KQsSI4xWCwC7H+q0MxZXGdfOWlWaYxEJigQ11N53+DUResbWpMA2cwDeLhDIuou2YP90EryOrvvL512FVQWiYblE983sDpRUvtY+jYQuYAu8qeSCA5yRXT//EMZC0z6QaLavZUnZqA54JilNxiZydK9ib46A+cHgKeq7yh1eIKiMph7uMuH67Y9tcDRVMQd5aACmEYSejkCggRoNVkVn+xYsf2nadJ03+L0D33IXGDesbgPciW6bBrvMQn4XG7WB8DR/7i28DhHnBWNtpDmZ196hWa5ANxS89LHeBZA/cazb/8YVRFVKiewjgsHwdncR722uL+isklguTa6C+JS+hhr476Wccf+Ey7R4D7SFnZ+hiUPYMXcmerGpGn2HJE3aalKxgatbL+LhEqwNJFYrT63hbDDJ6GSUCjULQlq39jdOcRCPMM0Mss+Df5pSw/aavrtsCDs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RLeSPontP6WEl9woWURpan2Ysipv5ehjAPFgDMQYTyyZkYM0a3J+Mh1hQfqbTUycrJh9t6Dxc6nId5pkFX13pUnlXsghdmLc4+ezy5iE55SO8oK93MuFUMo0E5A+B/amsfGgBiQa90C7XXClX3UXtPm4cpYQ6GRQT+cND5VoGiDrEycqXVntRWWJDMPRnhxBC4nP9CL/2jEukiFeOT6n3FLrJZM2KhsVq9g='
以下是解密文本的前 8 個字元:
VQ0NCgAA
這也是為任何想知道的人提供的完整程式碼:
import base64 import marshal import io from Crypto.Cipher import ARC4 key = input('Enter correct key: ').encode('utf8') cipher = ARC4.new(key) secret = b' ---- snip -----' plain = cipher.decrypt(base64.b64decode(secret)) if b'VQ0NCgAA' == plain[:8]: print('Correct') bytescode = io.BytesIO(base64.urlsafe_b64decode(plain)) bytescode.seek(16) implant = marshal.load(bytescode) exec(implant) else: print('Wrong')
抱歉,如果這是一個菜鳥問題,但我是密碼學的新手,並且真的很好奇如何實現這樣的事情。
顯而易見的方法是暴力破解它。也許密鑰很短,或者類似於字典中的單詞。至少我想不出更好的辦法。
附言。一旦你找到了密鑰,我希望你不會在不先修改它的情況下執行該程式碼。如果前綴匹配,它將載入並執行加密有效負載中的任何程式碼。您是否絕對 100% 相信它不會破壞您的系統或安裝隱藏的後門?我不會……
答案似乎是找到正確的鑰匙。也許你應該更加努力?
我找到了一個生成所需明文的密鑰,植入程序列印出 R0VOWntoMG5leV9oMG5leV9oMG5leV9wMHRfZnVsbF9vZl9tMG5leX0K 但是,這似乎只是垃圾。也許還有其他答案。