Well, you might want to consider using python or any other scripting/programming language to do such things.
The advantages of doing it programmatically are:
- Whenever you'll need to redo something similar, you'll have your code ready.
- You can write comments to explain what is going on, so if you once need to understand what you previously did, hopefully the code plus the comments will allow you to do so.
- Many things such as encoding, byte handling, etc. are easier than in the console
- Most languages are cross platform, so it'll work on Windows, Linux, Android easily, if you once switch your device.
Regarding your problem at hand, it may be solved using python to do everything:
# we import the function we need from common librairies
from base64 import b64decode
from Crypto.Cipher import AES
from binascii import hexlify, unhexlify
# First we decode the message and the key from base64 into bytes:
msg = b64decode("8LBUVZfDfI6wnggG1uUYuQsRoGd08pGwHCN++R5rabMW9PJmWHWcSrjy5Tfffj6L")
key = b64decode("3q1FxGhuZ5fQYbjzDxgQ35==")
# We then instantiate a cipher_suite using AES with the provided key, in ECB mode
cipher_suite = AES.new(key, AES.MODE_ECB)
# We can decrypt the message using our cipher_suite:
recovered = cipher_suite.decrypt(msg)
# We can print it:
print ("plaintext: ", recovered)
# There is some garbage at the end, but if we display it in hexadecimal form:
print ("in hex:", hexlify(recovered))
# We can see it's just padding using '5f', so let's create a function to remove such padding:
def unpad(padded):
# we declare the value of our padding:
paddingByte = unhexlify('5f')
# we do a loop, while the last byte is padding
while padded[-1:]==paddingByte:
# we remove the last byte
padded = padded[:-1]
# once it's done, we return
return padded
# We can now use our function to remove padding:
print ("unpadded: ", unpad(recovered))
Now, if you don't want to learn Python or any other language, and/or if you really want to do it all in your terminal, it is also possible:
then you could do everything directly using pipes to pass the data from one command to the other, command substitution to feed the right key to openssl, and the commands base64
to handle base64 plusxxd
to convert binary data to hex (for the key in openssl), and finally use sed
to remove the 5f
padding:
echo "8LBUVZfDfI6wnggG1uUYuQsRoGd08pGwHCN++R5rabMW9PJmWHWcSrjy5Tfffj6L" | base64 --decode | openssl enc -d -K $(echo "3q1FxGhuZ5fQYbjzDxgQ35==" | base64 --decode | xxd -c 16 -ps) -aes-128-ecb -nosalt -nopad | sed 's/_*$//g'
I don't know why, but I personally find the python approach cleaner.
You also mentioned that you obtained garbage using the way Maarten Bodewes indicated you, this is coming from the fact that you are feeding hexadecimal values to OpenSSL, while you should provide directly the binary data (not the hexadecimal value) for the message, while you should provide the key in hexadecimal:
echo -n f0b0545597c37c8eb09e0806d6e518b90b11a06774f291b01c237ef91e6b69b316f4f26658759c4ab8f2e537df7e3e8b | xxd -r -p | openssl ...
PS: you should probably avoid posting the actual values you encounter in CTFs, since it may spoil the game for people whose first reflex is to google the values.