Hello and welcome back to the final day of live CTF at DEF CON Finals. This has been a day. We're starting late, so without further ado, let's just kick it off. Final thumbs up? Let's roll. All right. Five, four, three, two, one. Let's go. All right, so first off, we're gonna be taking a look at Macaroni. Yeah, so we've got Macaroni versus MMM. At this point, we're looking at the lower bracket. They're fighting to survive. They still have a chance. They're very close to the finals at this point. Both of these teams have only lost one match on their runs. So, it's double elimination bracket. Whichever team loses this is out in, what is this, fourth place? Fifth place? One of those. Something like that. They had a good run. They're in the top half. We know that for sure. Definitely. You've had to win a lot to get this far. Yeah. So going into this challenge, is uleb4096 written by our very own Glenn, who's been running production for a large part of us? This is a pretty straightforward challenge. It's a challenge. In terms of the construction, right? It presents and says, give me some decoded shellcode. Yeah. And so the uleb is a reference to the unsigned little endian byte encoding. Yeah. Which is a pretty simple encoding, but it's something that I had never seen before I looked at this challenge. Same. But I mentioned it to our resident Mac and iOS expert, and she was just like, she took one look at the function, she's like, oh, this is web. Wow. I'm like, are you kidding me? I could have asked you. I was trying to verify this thing for so long. Yeah. So apparently some people know it very well. So let's hope the competitors do. At least one. Yeah. Well, I mean, so the good news is, is it's just encoding. It's not encryption. It's not crazy. So even if you aren't familiar with it, which I wasn't, you know, you can Google this. There are functions online in Stack Overflow that talk about how to use this. Heck, you can ask ChatGPT to write a functional ULIB decoder and it can do that. Really? Yep. Did you try that? I did. Oh my goodness. I'm not ashamed to say it. I installed the Python lev128 package. Which was the right thing to do. I did that too, but then I fell back to the ChatGPT function because I had made a mistake and it wasn't working. So we see over on MMM, PPP, ducks. They've had a lot of names. They've had so many names. They're going through. He's running just straight, you know, shellcraft-sh-shellcode, seeing what happens to it. And then going back into S-tray, seeing what the actual calls are, wondering like, did my registers get messed up? What's going on? No, this actually changes the encoding. Or I guess decoding? Right. This is a little bit of a weird challenge to think about because normally you'd think, oh, I've got my bytes. I want to encode them into some sort of encoding. But this is actually asking for decoded. And so you're kind of having to do the mental math of saying, okay, how do I go from decoded to encoded? Because what gets encoded is what's going to be run as shellcode. Yeah. So it's kind of reminiscent of like a targeted plain text attack. Like, it's really weird. It's mental gymnastics to get around. And actually, over on Macaroni, they're looking at the Leb128 Python package we were just talking about. It's just a matter of time. And I was thinking about that. I was interested to see how long would they look at the challenge before looking at the encoding? Because it's definitely necessary to look at the encoding in this one because the encoding itself enforces a constraint that's actually very difficult for shellcode and really I think is the crux of this problem. Yeah. And honestly, one thing I'm learning from this is we can make people install whatever package we want just by making a challenge around it. You know, I want to say that CTS was the one who famously had said you can use a CTF problem to get people to do work for you. Oh, it's so true. We were talking about like, oh, what if we have a challenge where it's please fix our CMake config? Yeah, exactly. You know, we can get some of the best hackers in the world to look at it for 48 hours for free. Imagine, we just need to give them fake points. People will do anything for internet points. Honestly, I've stayed up 48 hours straight CTFs just for like a couple of 500 point challenges. So over on MMM, we see them walking through and they're just trying to get a normal like push A rep. Right. So I think what they're doing here is that they're exploring the constraint. And if I recall, the constraint is that... So ULAB 128 is the actual encoding decoding going on here, which is to say you can take 128 bits and pack them into bytes is kind of how it ends up. And so what that means is you don't get the high bit to use as your shellcode. And that really limits the instructions you can use for your shellcode here. Now, is it that you don't get the high bit or that it sets the high bit for you? So you need to pass. Can you only use... You can only use instructions that have the high bit set. Yes, you're correct. Sorry. I'm just making sure here because like I said, mental gymnastics, looking at this thing, like trying to verify after casting and running offs all day. It's been a lot, man. It's been a lot. I think Carl was saying that our bingo card is getting full for things that can go wrong. Absolutely. We had hardware failure. We had just at the venue, there was a suspicious package that kicked everyone out. That's right. They kicked everyone out for it. We, this morning, had capture card failures. We had network problems. We had proxy issues. It was, oh, okay. Now we see MMM finding the same Leb128, PwnedToolsLeb128. I wish. That would have made my life easier. But they have a lot of things. They don't have everything. But looking at that same Leb128 crate over on Macaroni, they were just looking at usage docs for it. I think they're going to, yep, they're doing it. They're going to plug in the code to chat GPT. See? Can you explain this function? Great minds think alike. I love it. You know, but this is a real thing, right? AI is here. These LLMs are extremely powerful, can help with a lot of varied things. You know that it might be showing you some things that are incorrect, right? But it's still better than nothing, especially when you're pressed for time. This could give you a little bit of a leg up. Oh, absolutely. That forward training and just throwing a question at such a large, like, well, LLM, way better than MLM. And I only got to see the response there for a second, but it did seem to have recognized it as uleb. It did. I'm wondering if that's just from the name and if it's going to give information that might lead him down a rabbit hole. Good point. Yeah, you can't trust those AIs. Just like my grandmother always said. Over on MMM, we don't see any LLMs, which is surprising because it just rolls off the tongue. We saw him staring for a second just at the code, trying to get a mental model of what's going on and understanding, OK, so it transforms my code, but my code also needs to match a certain set of constraints. Yeah, and like I said, this encoding, if you're not familiar with it, which I don't think that either of these players are based on what we've seen in terms of them looking at packages and asking questions about what can this do, what does this do, the constraints aren't clear. If you read the Wikipedia page on this encoding, the constraint isn't clear. And so what I think we're seeing on the MMM side is that sort of interactive exploration. So he had a push instruction, I believe it was a push of a 64-bit register, which all of those instructions are going to have the high bit not set. And so, like I said, this forcing the high bit actually puts you in a weird spot with the x86 instruction set. Oh yeah, no, and I mean, unless these guys know off the top of their head, you know, the instruction space blocks and the distribution of them, I think this is going to take them some work. Yeah, I was asking around on our team for the other folks that had looked at this problem, how did you go about trying to figure out what instructions you had available given that constraint? Because it's kind of a weird thing to ask. Oh, it's super weird. And I think that Jordan's answer was, well, you just go straight to the Intel manual and start reading, right? Which is valid. Oh, very, yeah. And Glenn said, oh, there's a table linked from Stack Overflow somewhere that actually has a pretty decent, oh, here's your leading byte, and then it sort of broke down by the value of the leading byte, what instruction categories you could get, which was pretty helpful. That's really nice. And honestly, Stack Overflow is a great resource we've seen used earlier today. It's had some misleading information that led people down side paths and rabbit holes for a bit. But for weird knowledge like this, it's kind of invaluable. Yeah, yeah, definitely. And while it is definitely within the realm of CTF tricks to point people to resources that aren't quite correct, we're not going to be playing those games here. No, definitely not. Everything you need for the challenge is laid out in front of you, and if you just experiment with it, you can get it. Yeah, and we want the competitors to be able to solve this speed challenge. We know that this is challenging, and we are getting down to the finals here, right? So we know that these players are the very best, and we want it to be challenging, but we also want it to be solvable. And I think that the hints for this challenge, we did address that and try to give some good hints. Yeah, the hints are definitely explaining a lot of the theory behind it. And if they're off in wrong directions, push them back to the right one. Right, which if I recall, I think the first hint sort of lays out the constraint that you have to deal with. The first hint does the chat GPT, can you please explain this code to me? But a little nicer because it's from the author. And we saw over on MMM actually, experimenting with different size mobs, or mob of different size registers, and kind of looking at the first byte result of those. So I'm curious if he's figured this out, and he's just writing the constraints now, what he needs to end up with. Very interesting. Yeah, and I think that that experimentation is exactly what I would expect. You can see he's sort of laying out what he needs and what the constraints are. So the real kicker with that constraint, and I think that Glenn designed it this way, is that you can't get 64-bit instructions for a lot of the ones that you're going to want. Yeah. And so moving the shellcode around, or your shellcode has to be able to read or write memory typically. It's harder when you don't have the full-width registers, which you would be expecting to use. You have to find some alternatives. Absolutely, yeah. And move of the lower half register, so EAX, EBX, et cetera, operations on low-byte registers, POPs of the low four-byte registers, clears out top four bytes, which is going to be really nice when you end up needing, like, OX3, BNREX. Oh, and now we see it on the MMSI. They're looking for that opcode table, and that's exactly the table that I was referencing. Awesome. Oh, my. This table terrifies me, honestly. They are reading it very fast. I love BOP code. That was a challenge recently, wasn't it? Was it? I thought it was a DEF CON CTF. Oh, I don't know. I'm not sure. Anyhoo. Okay, but let's see. So, I honestly have no idea what he's writing in this. I don't know what that syscall equals OX05 CD88 question mark, like... I believe that he's laying out what the bytes are for the syscall opcode. Okay. I think OX05 is syscall. Okay. Well, honestly, oh, man. I don't look at bytes for disassembly anymore. We have, like, on trips to CTFs, done just kind of, like, back and forth trivia of, like, who can name more opcodes to bytes. Or, like, instructions to bytes. In RPI's sake, we did this, you know, when we were taking the train to and from Seesaw and stuff like that. Oh, and see, this experimentation is exactly what I think you're going to see on both sides, is how do I do clever little things where I can set the bytes just right or at least get that high bit set? What can I do to have equivalent operations or at least get the primitives that I need to shape a shellcode without breaking the constraint? Yeah, absolutely. And it looks like he's finding some really funky instructions to work with here. Over on Macaroni, we see experimenting in the same sort a little more targeted. It looks like they're trying to get generic control of written bytes. Instead of targeting exactly what they need, they're trying to come up with just a system for writing arbitrary bytes. I got stuck on this for a long time because I didn't focus on writing, you know, just one instruction at a time, get the state closer and closer and closer. I tried to make a function to just decode. That's so weird to say. Decode my shellcode into the right form and then push it to the server. So I'm hoping Macaroni does that here. They have, oh, it looks like just a PwnTemplate thing. Yeah, well, that's really the two approaches I think is that I would expect to see on this challenge is on one hand, just start experimenting and see what makes it through. And then the other side is the more static approach, which is let me understand the encoding really well and then I can write a function that will allow me to pass whatever I want through unscathed. Yeah, but understanding the encoding that deeply, you know, it sounds fairly simple, but looking at the code, your brain gets kind of jumbled because it's just so much bit shifting, oring and spacing that it's easy to lose track of where you are and what byte you're working on. Yeah, we see here, it looks simple, but if you actually trace through the path, it's funky. Yeah, it's simple enough, but when you're under this kind of time pressure, you really do feel like, man, how much time do I have to sit and think about this and really understand it? Yeah, exactly. And I think, yeah, we see anger coming out. Oh, now that is an interesting idea. That's a very interesting idea. None of us tried that as far as I know. No, and it's just encoding, so there's nothing that should really stop anger from working. It should be able to solve right through that. But the question is, you still have to have some shellcode that's going to run unscathed. You do, but I'm wondering if this is going to be able to find a way to write arbitrary bytes. Because if you can just use the shellcraft-sh and it'll write arbitrary bytes for you, who knows? Well, you won't be able to use the shellcraft-sh, actually. It'll probably return that there's no path available. Right, right. I think if you were trying to push things that aren't going to be possible with the constraint through, anger is just going to come back and say it's unsat, it's not solved. Yeah, and actually, Z3 would be pretty good for this, too. Well, we'll see how that works out for them. Over on the MMM side, we're looking at the encoder. This is definitely what the reference solution sort of did, which was understand, can I have a limited set of operations that allow me to write out or encode, decode? I think they're going to be self-modifying shellcode. Yeah, definitely. I think that's the approach they're doing. Because they're looking up PwnTools, Zortools. Yeah, and that would totally work. If you can write a short decoder stub that stays within the constraint, then that's a great solution. That's super smart. Yeah. Or even if you get an off-by-one instruction, then you just ink RIP. Yeah, I want to say... Ink RIP and not. Add RIP, too. Oh, and so now we see that he's... So this is a key insight that we're looking over on the MMM side. He's realized that he doesn't have access to RSI, RAX, but he does have access to EDX, ESI within the constraint. That's right. Key insight. So this is great progress. I'm trying to mix and match, see what the different first byte turns out to be. Right, and he's using sub as the operation, subtract instead of move, because maybe you want to fix up by using... or write bytes by subtracting constants. There's a lot of different ways to do this. Oh, there are so many different ways. I mean, as far as I know, x86 is turning complete. I was really waiting there. I'm like, oh, God, no, that one fell really flat. Okay, so we see... I think in that shellcode there was still a V. Where would that be? No, that has upper bit set. I remember looking at the load string instructions. That was definitely something that I explored. No, V is 0x70 something. It's before 0x7F, so it doesn't have upper bit set. That's right. That good old 7-bit ASCII. Good old ASCII should never belong in the same sentence, honestly. Let's switch to UTF-16 for everything. That's a way better encoding, right? I prefer that every byte needs two bytes, and the second byte is a null. Having written a Unicode decoder, this entire thing is bringing back some PTSD. I think encoding has to be one of the least favorite topics of most hackers. I don't know anybody that really loves encoding. Take this concept, transform it into an entirely new space, and then operate on that. It's easy, right? Every programmer wants to needlessly complicate things. Everyone has the best new encoding. That's true. There should be a standard. Who can make a standard? You need some sort of consortium for that. This is how we end up with new standards. So how is Macaroni doing? Macaroni, looking through, making sure they have a solid understanding of the code here. In IDA dark theme, this makes it really easy for us to keep track of, because we have light theme versus dark theme. I do appreciate that. Light side versus dark side. I'm not taking sides by saying that. But looking through, leaning back in the chair, understanding, okay. So it's seven bits per byte. But you encode it. So you need to pass a normal byte, and it only takes seven bits from that, and sets the top bit. That's right. That's right. And this is... The encoding itself is actually for arbitrarily sized numbers. And so even... Just the idea of like, this isn't a, oh yeah, you just provide your bytes, and it encodes, decodes. Base 64, for example, right? This is... No, it's for integers. It's for integers, which definitely was a little confusing for me when I was reading through it. Oh, yeah. No, that library does not work nicely for it. Does not work nicely for arbitrary bytes, rather. And the decode method just returns an int, so you should see like, where is it? Like bytes to hex in these people's solve scripts. And we saw a macaroni a second ago, checking for the hint. First hint was coming out in 20 seconds, so it should be out now. We don't see either team looking at it. Which is interesting, but we see mhacaroni. Yeah. Encoding... 7... Oh, 7 bits from binary output. Yeah, I think that they're trying to graphically print out what their bytes have. I think this is exploring the constraint. Oh, it absolutely is. I'm wondering if this is going to work, because this looks very similar to my script. Or it's starting to, at least. But I don't think... Yeah, shabcd, so those are all the 0x40 range. Those are going to get transformed, and you might be confused by that. But we'll check back. Yeah, there's that long to bytes we saw. Actually, let's see what the script does here before we switch back over to MMM. To send not defined. Yeah, that would help. Do you think that we're going to see the classic, all right, I'm going to look at what I'm sending into the decoder. uleb128 breaks up the input, like base64, into 7-bit blocks, did it say? Yep. So kind of explaining the function to them in English. Right. I think that MMM has an understanding of that. We'll see if that changes. And actually, Macaroni just saw that their 0x41, 0x42, 0x43, 0x44 got transformed to C1, C2, C3, C4. Bingo. So I think they're starting to really understand it. Yep, here we go. And now they're looking for a similar table. Oh, wait, they're one click off. Oh, no, look, over on the right, it has first bytes. Oh, that's helpful. That's so nice. It's not an order, though. It's an alphabetical order. Well, it allows you to reference, if you know what instruction you want, you can check what the opcode ends up being. And here we see Macaroni going to be doing very similar things over to what MMM was just doing in their Python terminal here. And it looks like they're doing the same 7-bit encoding, not using any nice Python helper, though. So they're going to have to write the helper themselves, which is prone to errors. Definitely. If you can download a library and have it do the work for you, you should, right? It's not about writing stuff you don't have to. Absolutely. It's about minimum work, maximum flags. That is the goal. And that's what players are really used to doing here. And it looks like he's just going to be rewriting his helper. So rewriting his unpacker? It's so weird to say. Yeah, okay, this is literally what my script looks like. Except I had, like, a mod in the... Yeah, wait, is he going to do times len mod 2? Because if he does times len mod 2, that is my script. Oh, wow. Okay, so going to be reading through the code again over on MMM. mHackaroni, they just switched, but mHackaroni was just going through PwnTools asm various opcodes. Main has unknown type casted to declare type. Is this true? No, no, you can do this as main here. Weird. I don't know why it failed to disassemble them. Yeah. So they're going to be breaking on the call and trying to understand what's going on there. Yeah, because if you look at the disassembly of main, you see that it basically ends in a call to a register, and so everything's set up. It's just putting the shellcode into a buffer and jumping to that buffer. Yeah, there are no complicated states to get there. You're going to have the same register state. There's no randomness. Well, there's randomness in ASLR and stuff, but you have fixed register entry state. And now we see Macaroni really doing exactly the same thing we saw MMM do, which is let me see what the bytes are for a bunch of instructions that I'm going to want to use. Absolutely. And they're going to be going through that for a bit. Over on MMM, you see he finished writing the repacker. Ah, re-unpacker. The un-repacker? And he's going to be going through, finding the right instructions to put there. His shellcode is not assembled instructions. It's just bytes. He's just writing the raw bytes, which honestly makes sense, because that way you don't have to go back from assemble shellcode to integer back and forth and try and keep a mental model of it. It's just laid out clearly for you. Yeah, that was something as I was working on this, I definitely had... I wanted to see the mnemonic. I wanted to see the opcodes. It was... There's not really a good tool for that that I can think of. I don't know. I'm sure there's one out there, but I haven't used one as far as I know. I mean, I did some work in Binja, just assembling stuff in and then doing show opcode bytes. Yeah. And then that was my play for a little bit. But this is not an easy thing to do. Yeah, I was working with Disasm.pro in the browser, just because I'm a browser tool kind of guy, and just typing stuff in, seeing what top byte is, moving stuff around, similar to what we saw these players doing earlier. And it looks like... Okay, MMM just getting calls right. Yeah, passing bytes of int. I mean, the speed at which that they're putting these things together is really impressive. And I mean, there definitely is an argument here, because the encoding is not really complicated, that maybe writing your own keeps you from having to deal with maybe an API issue if you don't like what the module is presenting. We talked about you have to figure out your big integer, so to speak, and then hex encoding it, and figuring out that stuff. Yeah, and it's very much like the ease of use of using that package, that API, versus understanding the internals and making sure that you have access to intermediate states. And kind of the overhead of learning a new thing versus writing your own thing is really something you have to weigh out. And going back and changing your approach to do the other from either is going to be a decent-sized lift, and you're going to be making mistakes on assumptions that don't exist anymore. Exactly, and that's what I was going to bring up, is that when you're using a library, you're limited to the assumptions that they made. Whereas if you're just looking at the assembly and you see exactly what this is doing, does it really matter if it's truly encoding the way it's supposed to be? Because the assembly is the truth. Yeah, I mean, that's really all that matters in the end, is what your state is when you get to that call racks. Exactly. And actually, call racks, you're going to have the... you could do self-modifying there, because you have racks equal to what your current rip is. Right, you do have a register that points... you have a register that points right to the beginning of your shellcode. If I recall, the register state's not that bad. We see MMM going into their debugger. I actually really love to see the debugger integrated with your disassembly, decompiler, RE framework, in this case IDA. I think that's a really powerful move, because I hate switching between windows. And if you've got a script, a debugger, a decompiler, you're flipping between these three things. It's just easier when you've got everything in one view. Yeah, and over on Macaroni, we see them printing out every instruction that matches the constraint that they were given. And lots of new lines. Yep, looks like there's an extra new line in there. Yeah, check if the string is empty, continue. Grep one line, or I'll filter that out for you. Oh, yeah, just grep. Oh, yeah, because they're printing one line in between instead of one line after every valid one. Oh, man. Yeah, I mean, this is CTF code, through and through. This is what we would expect to see. And honestly, this is... if you've got something that prints things out exactly the way you see, that can be a lot more useful than a Wikipedia page, which somebody else put together, probably for people doing sane things instead of CTF. CTF is sane? What are you talking about? It's just writing shellcode and 7-bit unpacking for an integer encoding. Exactly. Oh, I get your point. You know, I started off in CTF, reversing, all of that stuff, and I didn't realize how weird it was until I started dealing with real software people. Oh, yeah. No, I was talking with, once again, the iOS, macOS cat who's helping us behind the scenes. And we were staring at this problem, and she was just like, wait, no, this doesn't make any sense. This is so stupid. And we were staring at this thing for like 30, 40 minutes. And she'd never played a CTF before. And I turned to her and I'm like, congrats, this is what playing a CTF feels like. And she's like, oh, no. This doesn't make sense. This is so stupid. Yep, that sounds like CTF. Exactly. You either solve it or you look at the solution and you're like, wow, yeah. Yeah, not to date myself too much here, but when Python 3 came out and they made it a little bit more difficult to deal with bytes because you had to worry about strings versus bytes, I argued vehemently about why Python 2 had gotten it right. And all of the hackers that I knew were like, yeah, no, it's a lot easier to deal with. But everybody else in the world was like, you're crazy. Have you heard of internationalization? No, absolutely the same thing. I argued completely against it. RPISec's internal tools, I believe, still use Python 2. Oh, my gosh. Some of them. Hey, look, OK. At this point, that's cruel. RPISec, you know, we haven't really been playing CTFs much in the past couple of years. But, yeah, I argued completely against it. And now I'm, like, strong Python 3. Me too. Yeah. Me too. Now when I see tools that are still written for Python 2, it's like, hey, man. Yeah, it's kind of like, come on. I had to switch my code over. Python 2 was EOL. It's been EOL for a while. It's true. So getting back to it, we're looking at Macaroni, still looking through the tables, finding the opcodes that they can use, giving the constraints. Oh, going into XMM registers. Wait a minute. Oh, clever. You know, I wondered about that. Oh. I didn't explore that myself. Gosh. But I thought maybe, you know, you could use these extended registers. To move things around, you know? I'm wondering if they're going to go into, like, AVX 512. And I'm like, does my CPU support it? Yeah, okay, good. We're good. Oh, man. How much of a heartbreaker would that be if you write this beautiful shellcode and then it just doesn't support those extensions? Yeah. No. New CPU, supports just about everything. Really hope they're not going to do the... What's the new one? Zenbleed downfall? Oh. Which one was the AMD one again? Well, I know Zenbleed was, but... What are they looking at here? Is this Python codecs? Yeah, it's Python codecs. All right. So, switching back over to the MMM side, you can see they've got their interactive debugger within IDA. They're flipping back and forth. I really feel like this is the right view, or at least a view that is very helpful. Because it allows you to see, hey, this is the memory. He's got that hex view with the bytes of memory. You can see the disassembly, swap back and forth, the decompilation, and the registers all in one window. I think that helps you move faster. Yeah, absolutely. It gives you kind of the full context in one view, which is really nice. At the end of the day, we're only people. We only have like max one set of eyes. So, keeping track of all these different things, we're going to have that context switch overhead. Right, and as I said, you like to have it as much as you can in one view, but now he's got... He's got his IDE that has a script and two terminal windows open. He's got flipping back and forth to the... The big table. The browser, yeah, with the table. This is a lot. You've got to cross-reference a lot of information here. Oh, absolutely. Be able to organize it in your head. I really like in CTFs having like a dual monitor setup, a little external monitor, because you can have your reference up there, you can have a chat up there if you're talking back and forth to someone, or just like a notepad to keep track of. But live CTF, you do need a mirror screen, so it is... So it is harder. And we see... I don't want to leak Mhacaroni's file system there, but they were searching their file system and funny files came up. It was like, challenges to hack and code better. Well, you know, I've got some friends that are really interested in starting a school, you know, for... School of hacking for kids that want to learn to... Kids that want to learn to hack and be good. Hack good. Hack good. Yeah. Okay, well, I'm going to switch over to Mhacaroni, because they're looking for... Maple CTF CPO 37 write-up. Oh, I think that they're looking for a reference solution to another challenge that might mirror this one. Car set constraint shellcode. Another challenge. And I think they're hoping that they can just plug the constraints in. CPO 37 not found. Oh, yeah, look. They're like, I solved this challenge before, right? Like I solved one very similar. So they're trying to find their own solution on GitHub because they couldn't find it on a file system. That's pretty good when you have that kind of flashback and you're like, wait a minute, I've been here. And I think that that's really a thing in the CTF community is that if you have played a lot of CTF, you kind of have that knowledge bank. You've got an understanding of what are the kinds of problems that people ask you, and you can pull different pieces, even if it wasn't exactly the same challenge. Maybe you can pull like a real slick encoder or a bit of shellcode to do a very specific thing. Oh, yeah, or a Z3 script would be gold. Exactly. Yeah. But going through... Yeah, no, I mean, I know personally my CTF folder. I have some of my CTF solutions uploaded to GitHub. The other ones are too gross for me to upload. And I think that folder is like five gigs now. It's giant. Oh, no. I thought I saw, you know, a controlled exit there, like setting racks properly. But it looks like it was just... Yeah, exit zero. Oh, but it looks like they might have code then if they like got a proper ret. Yeah, looking at what they're doing... Oh, no, I'm sorry. This is their own code. Right. I was thinking they might be compiling something and then ripping out the bytes for it. Oh, they could, but they still need to either jump to a read or... Well, yeah, wait. No, because they'd need a move racks RDI and then they'd need to unset other args and then they'd need a read. I think once you've got... If it's only register manipulation, that's not so bad. But I think that the tricky part here was trying to get the code that you need, sort of your final shellcode that you're going to execute, getting that written to memory cleanly was really the difficulty. And it looks like here, over on Macaroni, they're working with CL now. So that's the lower byte in any register. And I think they found out that that meets the constraint that they can change that low byte, which is going to be BIN. Yeah, and that's what I... We see them writing BINSH now, which is going to be living in their input. So they know they have RIP in racks. Well, they have RIP and RIP also. They have access to every register. So they know relative offset of their BINSH string. You can control lower byte writes. And I believe also second byte writes. Not 100% on that one. I think you can get a 16-bit register right. You can get 16-bit register right, or do you have to do AL and AH? Look, I'm not the Intel manual. I don't know. Believe it or not. Yeah, I definitely had a similar approach. I was using the sort of one-byte register with instructions. And so there's really, at this point, I think two different ways you could be going. You could be looking at the encoder style. Hey, just write an encoder stub, and then decode my shellcode and jump to it. Or you could do sort of a byte or a chunk at a time where you have essentially a mini-decoder stub, where it's more like a writer stub that writes the byte that you want to a targeted area in memory and then jump to that. Yeah, absolutely. Because where you are, it's RWX, I believe. Oh, here we go. And you're not limited. Use 16 and 8-bit RWOFs to get a real write primitive and write a second-stage payload with real shellcode. Exactly what you were saying. Exactly, right. And that works in this case because you're not really limited on size. You're just really limited by this constraint that's really tricky to get around. And with this hint now, we see... Oh, we still can't operate on RAC. Oh, no, RACCL. Yeah. Exactly. So this is where that's exactly the instruction that they need. But the hint there, the 16-bit or 8-bit read-write ops, you can't use RAX there because it's going to violate that constraint. But you can use things like EAX. The 4-bit width, 4-byte width operations for writing to memory should work. Can you use EAX or do you have to use AX? I believe you can use something like MOV, dereference, EDX. Oh, okay. So the deref might... You're right. I'm going to trust you on this because, once again, I'm not a disassembler. But... We still love you anyways, Josh. Oh, thank you so much, guys. Even though I don't have 8,000 pages and so many mistakes. Some of my best friends are manuals. I have a friend named manual. MOV, byte point, okay. So therefore my string is broken. So they need to add brackets around the J. So we'll see them figure that out eventually. There's a lot of experimentation. It's so much easier being a commentator, honestly. I mean, I definitely banged my head on this challenge for a bit. Oh my gosh, same. So the hints are released at 20 minutes in and 35 minutes in. So that means we are max, like, 15 minutes away from sudden death. That's right. Yeah, we are getting near the end. We knew that these challenges are hard. Sudden death was sort of always on our minds as it might come down to that. I'm hoping that that's not going to be the case. I have faith in our competitors here. I think that they're going to figure this one out. I think they are. I think they're both making really good progress towards the final goal of setting up that second stage payload. Well, final goal. Towards the intermediate goal of making that second stage payload. Right. You know, I think that MMM, they kind of got to the idea pretty quick. They have been spending a bit of time now working through how to get things lined up. I think that they're on the right track. Yeah, well, I see a lot of Zord D-word pointers. You know, RSP plus 0x7B89, like, these random offsets. So, I think they're getting close, but they might get hung up on some small details of, like, I have a null byte in the middle of my shellcode somewhere that I just missed. Yeah, it's always something that you can just have the littlest thing mess you up. You don't catch it, or you've got, like, 99% of the solution, right? It totally happens in CTF. Absolutely, in this challenge, those mistakes are cascading. They will mess up everything after them. You know, potentially around them, like on either side, too. So, catching one is going to be hard, and you might just think to yourself, like, I'm messing all this up. What I really liked doing in this challenge was setting up a known good beginning write that was just garbage. You know, it was a bunch of nops. It was just a bunch of A's, whatever. Just to make sure that my write primitive still works. Like, I can still write that first stage shellcode. Yeah, I think that there's a lot of... This is one of those challenges where you want to have those sanity checks. I definitely was printing out my disassembly. I was checking the hex dump every time I ran it. So, if something did change, I would at least be able to see, oh, the pattern changed there. Something went wrong. I've got to go back and fix that. Yeah, like I'm doing stir of bytes instead of dot decode or dot encode. God, now this has me backwards. Again, this is a challenge that on the face of it seems simple, but is actually really kind of a mind bender and a weird constraint that... It's a simple concept with really hard execution. Right. And I think all of Glenn's challenges kind of follow the same principle of, you know, it's this kind of a little away from normal idea. And you're like, oh, that's close enough. I can just do this. And then you get to actually implementing a solution for it, and you're like, oh, my God, I know nothing about computers. These were a mistake. Yeah, I think that this is one of those challenges where it's like, I know what I want to do, but I just can't do it. And that's how I felt when I was working on this. Yeah, no, absolutely same. I really had the layout down, but actually writing, like, that first stage payload was not a good time. And it took me way longer than it probably should have. So it looks like MMM debugging their writes not working out quite right. And, okay, so here over on Macaroni, we see them using debug assembly, which is a great feature of Puntles. And just trying to figure out, they have a move racks. Oh, they're trying to figure out what's the, they're trying to make a stack frame via enter. Oh, that's clever. Yeah, I wonder, I mean, you could SROP here, SIGROP, but I'm not 100% sure if that's what they're going to go for. That seems a little overkill in my opinion. Well, you know, I never count the competitors out for coming up with clever solutions that we didn't expect. Exactly, yeah. And it could be easier for them. Like, they might be, like, SIGROP masters or something. Sure. And they're just like, I don't know how to write shellcode math. Yeah, they could be like, no, I invented this technique. Yeah, really, really. Well, I mean, we have Jinmo on MMM right now, and we were talking about it. He had a solution yesterday that was, I think, eight minutes. And we're looking at each other, and we're just kind of like, did this happen? And we look at the username on the screen that says Jinmo, and we're like, oh, yeah. Okay, that explains it. Yeah, we've got some truly impressive competitors here. Absolutely. Anybody who has won against this many other competitors at this level. Yeah. Top tier. Exactly. No, these are all fantastic hackers. We need to point that out, that these challenges, they have little to no time to get acquainted with them. Their mind is still on, you know, the challenge they've been staring at for the past 12 hours in DEF CON CTF. You know, the non-live version. And just they have so much going on in their mind. They have someone sitting directly across from them that they're hacking against. And even that adds its own stress. They're on stream. That adds more stress. It's a foreign concept, you know. They don't have tools set up for this. They don't know that, like, oh, yeah, this is normally like a Pwn CTF, like DEF CON finals usually is. It's new territory for them. And I think that can be really daunting. And the first step in this isn't getting acquainted with the program. It's kind of getting your bearings and resetting, you know, getting focused on what you need to do and the order you need to do it. Yeah, DEF CON CTF really could include challenges in any weird area. I mean, I think we had a competitor ask us, hey, can you specify what architecture this is on? And so far we've only seen x86. But with the finals, anything goes. Well, we had your Python shellcode challenge, too. That's true, that's true, which, you know, technically you didn't need to care about the native implementation. We had people walk up to us. I don't know if you know this, but we had people walk up to us. And the category we gave them was Python, I think Python shellcode. And they walk up to us and they're like, hey, can you be more specific? What exactly does that mean? And we're like, what do you mean more specific? And it's like, well, like, is it Python written to shellcode? Is it like shellcode that has to be valid Python? And we're like, dude, you have an hour for these challenges. It's not going to be like Python bytecode that's also valid shellcode. Oh, was it? No, it would be interesting to try something like that. I'm like, did we do that? No, no. So in that challenge, you didn't need to go low level. You could just ask Python to compile the bytecode for you. Yeah, OK, OK. No, I didn't think we'd have them, you know, do a polyglot challenge like that. See, and coming up with stuff is hard. So having a challenge that involves the topics that you're interested in, that you think will be fun for competitors, but also, you know, reasonable for the time frame. Yeah, it's not always easy. Well, we were talking, just organizing this, that I think writing the challenges is easy. Coming up with the ideas is hard. And then talking with Glenn and Carl, I think, they said, oh, the ideas are easy. Writing the challenges are hard. And I'm like, wait a minute. It's very much like, you've got chocolate on my peanut butter, you've got peanut butter on my chocolate. It's the perfect team that works out. And that's why it's great to have people that think differently on your team. Oh, yeah. And if we switch back to the MMM side, it looks like what they're doing is having a handwritten decoder there that's just decoding a D word at a time via XOR. Oh, they're just, wait, but they're just XORing. So they're just only using shell code that doesn't have top bit set. Which is definitely easier because when I tried to solve this, that's what I thought the constraint was at first. And so I wrote this nice shell code. No top bit set. But it's working. They have a syscall. They have syscall. They don't have bin sh. So they probably just determined... Error no 14. I love how they search error no 14. It says, oh, yeah, HTTP error 404. Wow. So that's a really clever idea. And it looks like there might have been some corruption on their shell code. But other than that, they're looking like they're on the right track. I think they don't. So they've got a big NOP sled. They've got their payload that they're going to XOR back. And then... Which that's totally valid. Great idea. Yep. Got EOF reading and interactive. So NOP's going to have the top bit set. So your vanilla x86 NOP. Oh, yeah, yeah. So now he's just troubleshooting what went wrong with that, right? Is the shell code intact? Was the string reference the address of bin sh? Pop rdi, push rdx, pop rsi, syscall. Does he have bin sh on the stack? I think he forgot about bin sh. Oh, no, he's using shellcraft down there. Hidden under his two global area terminals. Okay, so it's just NOP. Do you recall if the shellcraft shellcode, if that just uses a move to push the string into a register and then out? I believe it does. And I think it also sets all the register states, so he should be good there. I was going to say that's one of the things that this is a little nonstandard, but every challenge you have to understand what your register states are. There may be some implicit assumptions in your shellcode. Yes, absolutely. But I think it's really nice that the path to your shellcode being executed is so simple that you don't really need to worry about any randomness outside of ASLR. Stack offset is already in a register. You have RAP in two different registers, so you have different possibilities for instructions there. Wow, I think that he's getting very close here. I think MMM is really close. Macaroni? Macaroni? Macaroni? Not sure. Still looking at instruction encodings, trying to figure out which one they can use. It looks like they're iterating through all the possible registers and figuring out what can encode correctly or what can encode and match the constraints. Yes, and like we mentioned, all of those R prefixes on those registers indicating the 64-bit width, pretty sure that those aren't going to be able to be used with this constraint. Oh, and it looks... oh my God. Wait, they just got immediately... MMM just immediately solved. Did they solve? They solved. 40 seconds before sudden death we heard. Let's double check here. Yeah, Team 2 made... yeah, MMM won match 19. Wow, incredible. Incredible. Oh my goodness. Just an outstanding job throwing together this, getting it at the last moment. This is a tough challenge. We can see that Macaroni was also having a real hard time. This is, again, sound simple, hard challenge, excellent work. Very close for a long time there. And then MMM really had the idea of setting up their second stage payload using XOR, which top bit unset is going to be a lot easier in 64-bit x86. Yeah, I think they just did XOR negative 1 because negative 1 is going to have all the bits set. And then away you go. And then you just flip-flop everything. Yeah, they had 40 seconds left until sudden death. Wow. That's crazy. So that could have been really close. That could have been a big upset in sudden death too. Well, a great challenge. Outstanding job to our competitors. Absolutely. Difficult, came down to the wire. I'm glad we got to see that solved. And so MMM will be going into the finals of the lower bracket. So they'll have a chance to fight all the way back to the finals and maybe even win it. We'll see. Maybe see them in grand finals against one of Hypeboi and Strawhat coming up next. We're going to go ahead and get those teams swapped over and we'll see you back for the next match very shortly. Alright.