 What's up everybody? John Hammond here, still looking at Pico CTF 2017. Moving through the cryptography category, we're now up to this 50 point challenge compute AES. So the challenge prompt is you found this clue laying around, can you decrypt it? Click on this and it says, oh okay, encrypted with AES in ECB mode, all values base 64 encoded. So AES is advanced encryption standard, and it's a form of cryptography. So ECB is electronic codebook, and that is one of the modes or the forms of the operation that it can do. There are other ones like CBC, etc, and we'll explore those more, but AES, sorry, is very leveled in its complexity and its usage. I won't go into the absolute depth of explaining AES right now, but ECB, the electronic codebook version, is not insanely difficult to work with and handle, but this challenge is also very, very simple and boring in that they give you the ciphertext and the key. So there's not a whole lot of critical thinking or figuring out things to do, it's just a matter of doing the operation. These values that are base 64 encoded, that's simply because it's a way of showcasing the data in an easy way, because when it's encrypted or it's raw, it may be lots of pretty gross, nasty, maybe printable characters, but not in the clean ASCII range that is visible, like English text, like letters and numbers, etc. So base 64 helps do that. So let's go ahead and mess with these. Our Linux computer has a base 64 program already like installed in it, so if you wanted to check that out, you can encode and decode base 64 and it typically expects a file, but since we can pipe into it, it'll read standard input, so we can decode data with TACD. If we were to echo that into base 64 TACD, we get gross stuff. Okay, so that doesn't particularly help us. Same thing with the key, likely. We can put that in base 64, decode, it's this. So it's not like we can copy and paste that are easily do with like an online tool. So let's try and figure out a way that we can do this programmatically. Let's make a new directory compute AES and let's create a script, right? Let's create a get flag script in Python, because we can do more interesting and cool stuff in Python. So the shebang line that I'll be using in that case is user bin environment Python and is a command it takes like with the environment that you're looking for as an argument. So I supply Python as with the space in between it. Cool. So we want our cipher text to equal that string that we had before, just defining a variable for this. If you don't know a whole lot of Python, that's okay. Not trying to scare anyone with this stuff, but I want to showcase it with an objective format that we're trying to get a CTF flag here. So we've got a goal and that way we can what we're trying to do to accomplish that goal, I can cover and explain as we work through it. So next we want to actually decode this out of that base 64 form in Python. So Python has some libraries to do this. It has base 64 as a built in library. You don't have to install it or do anything to actually get it. If you're running Linux, you already have it. So you can just import base 64 and then you can run functions like B64 encode or B64 decode from that module from the base 64 module. It'll just take a string s here, and then it will return that response. So if I wanted to import base 64, I can say cipher text is actually base 64 dot B64 decode of this string here. Same thing with the key base 64 dot B64 decode. Now I can print out cipher text and print out key. So you can get an idea that we are working with the same values here ciphertext.top key down here. Now, if we want to try and actually do this operation to decrypt this AES key, or whatever cipher text data that we have here, we can do that in Python too, or Python as well. Decrypt AES. Remember, not afraid to Google, not afraid to research. There's a lot of explanations and stuff on how to do this. I've seen the cryptography library be pretty cool. I've also seen PyCrypto work very well, which they also cover in this link here. If you don't have these installed, which you may very well not, if you are following along and just doing this from a raw flat vanilla Linux image, like a new BUNSTU installation that we just did, you can install things on that Linux system by using sudo or super user do, and then apt being your like package manager aptitude is going to be the original there. That's the command that we want to run arguments are install, and then a package name that you want to install because Linux uses repositories that online resource that has a bunch of packages and software you can install and compile and download and use. So Python hyphen pip is, and again, you'll have to enter your user password. No output through that because the Linux doesn't want anyone looking over your shoulder to see the password. But if you get it installed, you may have to hit yes to go through that pip will go ahead and act as your Python package manager. So you can run sudo pip install, and then pycrypto is a valuable option. In this case, we can run crypto, pycrypto, and that will install it if you don't already have it installed. So if you do have it installed, you can import AES through that crypto dot cipher module. This is the first time and I don't often see a whole lot of capital names in modules, but whatever. Let's check out what this is doing along with this. Because they give a little bit of an example here, they showcase this with an encryption suite. So if AES is running just like that with a new object, we have a key that we can use based off of CBC, oh, with an initial value or initialization vector, but CBC is not what we're using, we're using mode ECB. So we can assume that that exists inside of that AES module that works just fine for us. And then we can decrypt by using that like decryption suite to decrypt. Okay, neat. Let's try and do that. Let's say we have AES dot new with our key, right, because that's what it needs as an argument here. And then we got to specify the mode. So we can assume that constant mode underscore ECB probably exists. And if you needed to check out the documentation, you can track that down online. So let's just call this AES lowercase, because we are using that AES like encryption scheme here. So then we can run AES dot decrypt on the ciphertext. And that will return the plaintext for us, right? So let's say plaintext equals this. Now let's print out that plaintext and see what we have. Let's run get flag flag, do not let machines win. Okay, cool. So it looks like this has padding here. Looks like it has a lot of underscores here. That's because AES has to be part of that block size. If you want to go into the in the weeds of AES that maybe we'll cover eventually. But I don't want to go too in depth just yet. It is working with blocks of data. So typically 16 or 32 bit, et cetera, et cetera. And that is how you handle Okay, it looks like 128 bits, blah, blah, blah. That is how you handle that cryptography standard. And the modes can do a lot of very, very cool things. But in this case, just a simple decrypt with the key in the ciphertext that's given to us. And we can move on. So there's the flag. Let's actually save that to keep track of it. And let's go ahead and move that compute AES to complete. So all that was was a little bit of research again, just learning how to use some cryptography libraries and Python and then getting the syntax right to do cool things with it. So sweet. Hope you guys are learning bit by bit some interesting modules of things you may not have seen before. And maybe a little bit of a walkthrough and guide through Pico CTF challenges. So let's go ahead and submit this flag. We only want the curly braces part. We don't need the padding. Submit that and we're good. Cool. Hey, I want to give a special shout out to my supporters, people that donate to me through Patreon. And thank you so much. Every little bit that you do or every big bit that you do really does help the channel grow. I cannot thank you enough. I'm very excited to keep this list growing because $1 a month will give you a special shout out just like this at the end of every video. $5 a month is early access to everything that I create. And if you did like this video, please do press that like button. Maybe leave me a comment if you're willing to subscribe. And if you really want to support me, check me out on Patreon. Thanks guys. See you soon.