 Hey, how's it going everybody? My name is John Hammond, and I'm still looking at some of the last the CTF challenges Challenge I'm on right now is pixels and it looks like a little steganography or forensics challenge thing So it looks like we intercepted these messages image 1 and image 2, but we don't know how they go together Figure out the hidden message. All right, so let's download these images. It looks like the file name is qr1 So I'm just gonna assume we're working with some qr images Some some qr codes. I have already solved this challenge. I'm just gonna go through the demonstration of how I did it Over in here. I do see the code that I've already written for one thing and let's look at those qr codes It looks like qr1 It's just all of this junk, which is not that helpful But if I press the arrow keys ultimately between the two of them You'll see the pixel shifting and you can see that it looks like there is a qr code if I hold down the arrow keys You can see them really really like rapidly changing if you look in the corners You can see these like The edges of a qr code being made so all of the things on the left right Although the whole border is normally white in a regular qr code, right and then everything else That's not in this case. You can kind of see it shifting in everything. That's different is gonna be black, right? It looks like we're just trying to take the difference between these two images So we can probably write some code that does that in fact. I just did so let's see how we can do it together I'm just gonna kind of run through the syntax and everything. I'll just write a little get flag script to do this Hopefully you can follow along if there is any code, of course, you haven't seen before I mean I recommend recommend do a little bit of research and be asking around doing some cool stuff But let's go ahead and from PIL we can import these image library and we can start to look at some of these Let's go image one equals image dot open and that is qr1.png, right? Let's do the same thing with image two Let's go ahead and close these things just so some good programming practice in here Oh, we didn't a new one at the end Let's get that data from it, right? Because we want to be able to look through it image one let's just call it data one equals image one dot load the same thing for image two so we'll get all of the Pixels from it and we want to be able to create a new image that will save the difference in So we'll call it qr, right? We're gonna do image new It needs the mode which will be RGBA. It needs the size So let's actually get the size of all the others with height equals image one Both of these are the same size. It doesn't matter which I use your image one or image two We just got to use one of them size and Let's close qr as well And let's actually just show it to see what it is right now So okay, so we got a black screen and a black blank image Let's actually get those colors set since we'll want them 255 255 255 do the same thing for black See if I can do a quick search and replace with zero In one line whoa fail It totally would have been faster for me to just actually type this whatever oh I didn't even get multiple Total fail. All right, and let's just make the whole background white. So now we have a full white image cool Now let's actually go through that loop, right? Let's do for I Let's go why for why in range length? No, we don't need the length because height and width are already Already integers, right? So now for x in range of width Now our current pixel Which we can use for both is going to be image either one or two. It doesn't really matter x and Why we can access all the images. So let's do it Let's test if For each pixel image one is equal to x y is equal to the other images x and y So look just checking it testing a difference if they are equal that means of the same pixel That means we can pretty much in our let's get qr's data for one thing. We haven't even done that yet New data. Let's call it qr dot load Now qr's x and y would be equal to white in this case Since it's already a white image. We've already made all of that a white background Let's just continue to go on this loop. Otherwise if there is a difference, we're gonna end up setting these to black, right? Now when we run this oh, I fail. What did I do wrong? If image one. Oh, I got to use data my bad data one and data two As we're using the actual like pixel maps not the image handles themselves and do the same thing with data or new data, right? This is already commented out doesn't really matter But now when we run this hey, we got ourselves a qr code now We just got to be able to scan this thing, right? So I'm gonna do that with z bar image, which is a command line thing if you've not seen that before I'll zoom in this a little bit. You can run z bar image and that would give you it's like it can read a qr value So it's pretty nifty. So let's actually do that in our Python script. I'm gonna call sub process I'm actually sub process the module to be able to call that. So I'm a from sub process I'm gonna import check output and That's that's all I need for now We don't have to show the qr code anymore, but I will just comment that out Now we can use check outputs with z bar image Actually, it's gonna need a file name, right? Yeah. Yeah, it needs an image file to like read out of so let's go ahead and save this somewhere Let's get a save name equals found qr.png that's fine And let's do qr.save with that save name So now it saves it z bar image and let's concatenate on that save name. Now we run this No such file directory. That's a sub process error because this has to be actually a list of arguments Subprocess is weird like that now when we run check output scan barcode symbols from one image in point zero two seconds. Whoa How don't we get anything? Oh, we got actually print out the output for one thing. Cool. Let's print this out Hey Qr code two isn't always better than one and we get a flag here nifty. Let's trim that down Split it as for unusual let's get the last thing so we'll get the flag But all this scan one barcode stuff. I don't really want and that looks like it's coming out of Standard error. So let's just redirect that somewhere else I'm an import pipe from sub process and then in my check output I'm just gonna say center error should go to pipe now we just get simply the flag and that is everything that we need Make that executable in our shell Get flag run it and hey, that's our flag. Let's go ahead and submit that Get a couple more points Submit and that's correct 90 more points for us. Good stuff guys. Cool. Hope you're able to follow a lot of that I did already write this code. So I ran through it a little bit before. This is the code that I written initially and Mine looks my current one looks pretty identical Yeah, this is like it's literally the same exact code that I just wrote with you So cool. I hope you guys enjoyed it The python image library is really really awesome Especially for interesting ccs like this when we're working with images and doing different things with them scraping pixel data stuff like that So hope you guys enjoyed. We got another flag Good stuff and I'll see you in the next tutorial or video Bye