0
$\begingroup$

I'm having difficulty decrypting a secret message as a part of a CTF and I was wondering how could I decrypt an encrypted text that has been encrypted with pycrypto RC4 and when the first 8 characters of the plain text secret are know. Here is the secret that is in the code:

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/aavrtsCDsTx2w6FS599LARBdHeyJHPZfvFa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5ehjAPFgDMQYTyyZkYM0a3J+Mh1hQfqbTUycrJh9t6Dxc6nId5pkFX13pUnlXsghdmLc4+ezy5iE55SO8oK93MuFUMo0E5A+B/amsfGgBiQa90C7XXClX3UXtPm4cpYQ6GRQT+cND5VoGiDrEycqXVntRWWJDMPRnhxBC4nP9CL/2jEukiFeOT6n3FLrJZM2KhsVq9g='

and here are the first 8 characters of the decrypted text: VQ0NCgAA

Also here is the full provided code for anyone wondering:

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')

Sorry if this is a noob question but I'm new to cryptography and really curious on how something like this can be achieved.

$\endgroup$

2 Answers 2

1
$\begingroup$

The obvious approach would be to brute force it. Maybe the key is short, or something like a dictionary word. At least I can't think of any better way.

Ps. Once you do find the key, I hope you're not going to run that code without modifying it first. If the prefix matches, it will load and execute whatever code is in the encrypted payload. Do you absolutely 100% trust it not to wreck you system or install a hidden backdoor? I wouldn't…

$\endgroup$
1
  • $\begingroup$ yes i did try it against the rockyou.txt word list. Should I try it against other wordlists as well or should i try random strings? And yes don't worry, I did change the script to only print out the output and not execute it $\endgroup$
    – DireHacker
    Feb 3 at 20:20
0
$\begingroup$

The answer seems to be to find the correct key. Maybe you should try harder?

I found one key that produces the desired plaintext, the implant printed out R0VOWntoMG5leV9oMG5leV9oMG5leV9wMHRfZnVsbF9vZl9tMG5leX0K However, this seems like that it is just junk. Maybe there are also other answers.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.