start	end	text
11110	13270	Hello and welcome back to the final day
13270	15450	of live CTF at DEF CON Finals.
15790	17770	This has been a day.
17970	20070	We're starting late, so without further ado,
20070	21070	let's just kick it off.
21070	22330	Final thumbs up?
22330	23090	Let's roll.
23090	23850	All right.
23950	27970	Five, four, three, two, one.
27990	29170	Let's go.
29290	31290	All right, so first off,
31290	33250	we're gonna be taking a look at Macaroni.
33250	36810	Yeah, so we've got Macaroni versus MMM.
37190	39170	At this point, we're looking at
39170	40590	the lower bracket.
40750	41810	They're fighting to survive.
41810	42690	They still have a chance.
42690	44270	They're very close to the finals at this point.
44270	47210	Both of these teams have only lost one match on their runs.
47570	50230	So, it's double elimination bracket.
50310	52350	Whichever team loses this is out in,
52350	54470	what is this, fourth place?
55290	56430	Fifth place?
57350	58090	One of those.
58250	59310	Something like that.
60010	61090	They had a good run.
61090	62090	They're in the top half.
62090	63250	We know that for sure.
63310	63830	Definitely.
63830	65730	You've had to win a lot to get this far.
65730	66190	Yeah.
66190	67570	So going into this challenge,
67570	72290	is uleb4096 written by our very own Glenn,
72290	76130	who's been running production for a large part of us?
76870	79510	This is a pretty straightforward challenge.
79510	80470	It's a challenge.
80670	83590	In terms of the construction, right?
83590	87450	It presents and says, give me some decoded shellcode.
87450	88050	Yeah.
88110	91230	And so the uleb is a reference to the unsigned
91230	94030	little endian byte encoding.
94030	94550	Yeah.
94550	96970	Which is a pretty simple encoding,
96970	99010	but it's something that I had never seen
99010	100510	before I looked at this challenge.
100530	100890	Same.
100890	104330	But I mentioned it to our resident Mac and iOS expert,
104330	105650	and she was just like,
105650	107230	she took one look at the function,
107230	108610	she's like, oh, this is web.
108730	109090	Wow.
109090	110410	I'm like, are you kidding me?
110410	111330	I could have asked you.
111330	113170	I was trying to verify this thing for so long.
114570	114990	Yeah.
115070	117630	So apparently some people know it very well.
117630	119490	So let's hope the competitors do.
119630	120610	At least one.
120630	120970	Yeah.
120970	122470	Well, I mean, so the good news is,
122470	123590	is it's just encoding.
123590	124410	It's not encryption.
124410	125490	It's not crazy.
125490	127310	So even if you aren't familiar with it,
127310	129810	which I wasn't, you know, you can Google this.
129810	132690	There are functions online in Stack Overflow
132690	134510	that talk about how to use this.
134950	138710	Heck, you can ask ChatGPT to write a functional ULIB decoder
138710	140190	and it can do that.
140190	140710	Really?
140710	140970	Yep.
140970	141670	Did you try that?
141670	142230	I did.
142230	142570	Oh my goodness.
142570	143570	I'm not ashamed to say it.
143570	147090	I installed the Python lev128 package.
147090	148570	Which was the right thing to do.
148570	150110	I did that too,
150110	153370	but then I fell back to the ChatGPT function
153370	156570	because I had made a mistake and it wasn't working.
156910	162310	So we see over on MMM, PPP, ducks.
162850	164310	They've had a lot of names.
164310	165570	They've had so many names.
165570	166730	They're going through.
166770	169650	He's running just straight, you know,
169650	172290	shellcraft-sh-shellcode, seeing what happens to it.
172490	174210	And then going back into S-tray,
174210	175610	seeing what the actual calls are,
175610	177250	wondering like, did my registers get messed up?
177250	178330	What's going on?
178790	181890	No, this actually changes the encoding.
181890	184630	Or I guess decoding?
184630	187770	Right. This is a little bit of a weird challenge to think about
187770	191950	because normally you'd think, oh, I've got my bytes.
191950	194950	I want to encode them into some sort of encoding.
195930	198730	But this is actually asking for decoded.
198870	202330	And so you're kind of having to do the mental math of saying,
202330	204830	okay, how do I go from decoded to encoded?
204830	208950	Because what gets encoded is what's going to be run as shellcode.
208950	215910	Yeah. So it's kind of reminiscent of like a targeted plain text attack.
216250	218730	Like, it's really weird.
218730	220130	It's mental gymnastics to get around.
220130	225070	And actually, over on Macaroni, they're looking at the Leb128 Python package
225070	226470	we were just talking about.
226470	228830	It's just a matter of time. And I was thinking about that.
228830	231210	I was interested to see how long would they look at the challenge
231210	233010	before looking at the encoding?
233110	236150	Because it's definitely necessary to look at the encoding in this one
236150	240350	because the encoding itself enforces a constraint
240350	242310	that's actually very difficult for shellcode
242310	244350	and really I think is the crux of this problem.
244470	247330	Yeah. And honestly, one thing I'm learning from this is
247330	249690	we can make people install whatever package we want
249690	251410	just by making a challenge around it.
251490	258050	You know, I want to say that CTS was the one who famously had said
258050	261930	you can use a CTF problem to get people to do work for you.
261930	262950	Oh, it's so true.
263110	265170	We were talking about like, oh, what if we have a challenge
265170	267490	where it's please fix our CMake config?
267670	268990	Yeah, exactly.
269050	272210	You know, we can get some of the best hackers in the world
272210	274490	to look at it for 48 hours for free.
274950	277290	Imagine, we just need to give them fake points.
277550	279430	People will do anything for internet points.
279430	282690	Honestly, I've stayed up 48 hours straight CTFs
282690	285610	just for like a couple of 500 point challenges.
286550	290770	So over on MMM, we see them walking through
290770	294690	and they're just trying to get a normal like push A rep.
295270	297590	Right. So I think what they're doing here
297590	299850	is that they're exploring the constraint.
299850	302290	And if I recall, the constraint is that...
304070	308370	So ULAB 128 is the actual encoding decoding going on here,
308370	311270	which is to say you can take 128 bits
311270	314330	and pack them into bytes is kind of how it ends up.
315070	318890	And so what that means is you don't get the high bit
319350	320890	to use as your shellcode.
320890	322770	And that really limits the instructions
322770	324190	you can use for your shellcode here.
325170	326750	Now, is it that you don't get the high bit
326750	329090	or that it sets the high bit for you?
329090	332410	So you need to pass. Can you only use...
332410	335610	You can only use instructions that have the high bit set.
335610	336950	Yes, you're correct. Sorry.
336950	339550	I'm just making sure here because like I said,
339550	341510	mental gymnastics, looking at this thing,
341510	344750	like trying to verify after casting and running offs all day.
344750	347770	It's been a lot, man. It's been a lot.
347770	350550	I think Carl was saying that our bingo card
350550	352890	is getting full for things that can go wrong.
352890	355490	Absolutely. We had hardware failure.
355490	357170	We had just at the venue,
357170	359790	there was a suspicious package that kicked everyone out.
359790	361410	That's right. They kicked everyone out for it.
361410	363570	We, this morning, had capture card failures.
363570	368170	We had network problems. We had proxy issues.
368190	369770	It was, oh, okay.
369770	372330	Now we see MMM finding the same Leb128,
373370	374150	PwnedToolsLeb128.
374210	377190	I wish. That would have made my life easier.
377190	379890	But they have a lot of things. They don't have everything.
380490	386630	But looking at that same Leb128 crate over on Macaroni,
386630	388790	they were just looking at usage docs for it.
388790	391230	I think they're going to, yep, they're doing it.
392090	394790	They're going to plug in the code to chat GPT.
395590	398310	See? Can you explain this function?
398310	399750	Great minds think alike.
399750	400970	I love it.
400970	403450	You know, but this is a real thing, right?
403450	406290	AI is here. These LLMs are extremely powerful,
406290	409130	can help with a lot of varied things.
409810	413810	You know that it might be showing you some things
413810	415250	that are incorrect, right?
415330	417730	But it's still better than nothing,
417730	419590	especially when you're pressed for time.
419590	421450	This could give you a little bit of a leg up.
421450	423150	Oh, absolutely. That forward training
423150	427670	and just throwing a question at such a large,
427670	429990	like, well, LLM, way better than MLM.
429990	432870	And I only got to see the response there for a second,
432870	435910	but it did seem to have recognized it as uleb.
435910	437690	It did. I'm wondering if that's just from the name
437690	439030	and if it's going to give information
439030	440650	that might lead him down a rabbit hole.
440650	443930	Good point. Yeah, you can't trust those AIs.
443930	445990	Just like my grandmother always said.
446830	449230	Over on MMM, we don't see any LLMs,
449770	452570	which is surprising because it just rolls off the tongue.
452670	454650	We saw him staring for a second just at the code,
454650	456870	trying to get a mental model of what's going on
457370	460890	and understanding, OK, so it transforms my code,
460890	463410	but my code also needs to match a certain set of constraints.
464310	467070	Yeah, and like I said, this encoding,
467070	468770	if you're not familiar with it, which I don't think
468770	471550	that either of these players are based on what we've seen
471550	474210	in terms of them looking at packages
474210	476590	and asking questions about what can this do,
476590	479670	what does this do, the constraints aren't clear.
479670	481990	If you read the Wikipedia page on this encoding,
481990	483170	the constraint isn't clear.
483170	485950	And so what I think we're seeing on the MMM side
485950	488810	is that sort of interactive exploration.
488810	490610	So he had a push instruction,
490610	493170	I believe it was a push of a 64-bit register,
493170	494950	which all of those instructions
495830	500050	are going to have the high bit not set.
500310	505490	And so, like I said, this forcing the high bit
505490	507250	actually puts you in a weird spot
507250	509330	with the x86 instruction set.
509810	512190	Oh yeah, no, and I mean, unless these guys
512190	513850	know off the top of their head,
513850	515590	you know, the instruction space blocks
516250	517550	and the distribution of them,
517550	519610	I think this is going to take them some work.
519630	521830	Yeah, I was asking around on our team
521830	524130	for the other folks that had looked at this problem,
524130	527150	how did you go about trying to figure out
527150	530130	what instructions you had available given that constraint?
530130	531770	Because it's kind of a weird thing to ask.
531770	532950	Oh, it's super weird.
533050	536250	And I think that Jordan's answer was,
536250	538270	well, you just go straight to the Intel manual
538270	539850	and start reading, right?
539850	540910	Which is valid.
540910	541670	Oh, very, yeah.
542030	544330	And Glenn said, oh, there's a table
544330	546170	linked from Stack Overflow somewhere
546170	548410	that actually has a pretty decent,
548410	549990	oh, here's your leading byte,
549990	551350	and then it sort of broke down
551350	553350	by the value of the leading byte,
553350	555530	what instruction categories you could get,
555530	556930	which was pretty helpful.
557070	558370	That's really nice.
558370	560530	And honestly, Stack Overflow is a great resource
560530	561830	we've seen used earlier today.
561830	563350	It's had some misleading information
563350	567050	that led people down side paths and rabbit holes for a bit.
567090	570790	But for weird knowledge like this, it's kind of invaluable.
570810	572090	Yeah, yeah, definitely.
572090	577190	And while it is definitely within the realm of CTF tricks
577190	581710	to point people to resources that aren't quite correct,
581710	583730	we're not going to be playing those games here.
583730	585250	No, definitely not.
585550	586930	Everything you need for the challenge
586930	588010	is laid out in front of you,
588010	590370	and if you just experiment with it, you can get it.
590510	592490	Yeah, and we want the competitors
592490	594810	to be able to solve this speed challenge.
594810	596130	We know that this is challenging,
596130	598390	and we are getting down to the finals here, right?
598390	603130	So we know that these players are the very best,
603130	604990	and we want it to be challenging,
604990	606230	but we also want it to be solvable.
606230	608630	And I think that the hints for this challenge,
608630	612010	we did address that and try to give some good hints.
612010	614350	Yeah, the hints are definitely explaining
614530	616050	a lot of the theory behind it.
616210	618730	And if they're off in wrong directions,
618730	620250	push them back to the right one.
620330	623510	Right, which if I recall, I think the first hint
623510	626090	sort of lays out the constraint that you have to deal with.
626090	627650	The first hint does the chat GPT,
627650	629390	can you please explain this code to me?
629730	631990	But a little nicer because it's from the author.
632010	633830	And we saw over on MMM actually,
634430	636570	experimenting with different size mobs,
636570	638030	or mob of different size registers,
638030	640830	and kind of looking at the first byte result of those.
641230	644710	So I'm curious if he's figured this out,
644710	646270	and he's just writing the constraints now,
646270	647810	what he needs to end up with.
648170	648930	Very interesting.
648930	651050	Yeah, and I think that that experimentation
651050	652970	is exactly what I would expect.
653090	657590	You can see he's sort of laying out what he needs
657590	659110	and what the constraints are.
660370	663250	So the real kicker with that constraint,
663250	665230	and I think that Glenn designed it this way,
665230	669910	is that you can't get 64-bit instructions
669910	671990	for a lot of the ones that you're going to want.
672410	672810	Yeah.
673830	679130	And so moving the shellcode around,
679130	683150	or your shellcode has to be able to read or write memory typically.
683190	686770	It's harder when you don't have the full-width registers,
686770	687950	which you would be expecting to use.
687950	688910	You have to find some alternatives.
688970	689830	Absolutely, yeah.
689830	692650	And move of the lower half register,
692650	694870	so EAX, EBX, et cetera,
696510	698370	operations on low-byte registers,
698370	702030	POPs of the low four-byte registers,
702030	703730	clears out top four bytes,
703730	704750	which is going to be really nice
704750	708810	when you end up needing, like, OX3, BNREX.
709070	711810	Oh, and now we see it on the MMSI.
711810	713390	They're looking for that opcode table,
713390	715390	and that's exactly the table that I was referencing.
715390	716510	Awesome. Oh, my.
716670	718570	This table terrifies me, honestly.
718570	721790	They are reading it very fast.
721790	723470	I love BOP code.
723590	725090	That was a challenge recently, wasn't it?
725090	725710	Was it?
725710	727490	I thought it was a DEF CON CTF.
727490	728470	Oh, I don't know.
728470	729730	I'm not sure.
729910	730770	Anyhoo.
731770	733290	Okay, but let's see.
733950	737190	So, I honestly have no idea what he's writing in this.
737190	742310	I don't know what that syscall equals OX05 CD88 question mark, like...
742310	748170	I believe that he's laying out what the bytes are for the syscall opcode.
749090	749630	Okay.
749630	752630	I think OX05 is syscall.
753230	753950	Okay.
754570	758290	Well, honestly, oh, man.
758590	760650	I don't look at bytes for disassembly anymore.
760670	763010	We have, like, on trips to CTFs,
763010	764630	done just kind of, like, back and forth trivia
764630	768410	of, like, who can name more opcodes to bytes.
769530	771350	Or, like, instructions to bytes.
771510	773250	In RPI's sake, we did this, you know,
773250	775970	when we were taking the train to and from Seesaw and stuff like that.
775970	779610	Oh, and see, this experimentation is exactly what I think
779610	781190	you're going to see on both sides,
781190	783610	is how do I do clever little things
783610	787890	where I can set the bytes just right or at least get that high bit set?
787890	789990	What can I do to have equivalent operations
789990	793270	or at least get the primitives that I need to shape a shellcode
794250	796090	without breaking the constraint?
796250	796850	Yeah, absolutely.
796850	800970	And it looks like he's finding some really funky instructions to work with here.
800970	802350	Over on Macaroni,
802350	806690	we see experimenting in the same sort a little more targeted.
806690	812870	It looks like they're trying to get generic control of written bytes.
812870	815930	Instead of targeting exactly what they need,
816650	821230	they're trying to come up with just a system for writing arbitrary bytes.
821230	822910	I got stuck on this for a long time
822910	825230	because I didn't focus on writing, you know,
825230	826810	just one instruction at a time,
826810	828730	get the state closer and closer and closer.
828730	834390	I tried to make a function to just decode.
834390	835490	That's so weird to say.
835490	839690	Decode my shellcode into the right form and then push it to the server.
839690	843330	So I'm hoping Macaroni does that here.
843330	846810	They have, oh, it looks like just a PwnTemplate thing.
847910	850190	Yeah, well, that's really the two approaches
850190	853110	I think is that I would expect to see on this challenge
853110	854550	is on one hand,
854550	857030	just start experimenting and see what makes it through.
857030	859850	And then the other side is the more static approach,
859850	862050	which is let me understand the encoding really well
862050	863210	and then I can write a function
863210	867990	that will allow me to pass whatever I want through unscathed.
867990	870370	Yeah, but understanding the encoding that deeply,
870370	872830	you know, it sounds fairly simple,
872830	876230	but looking at the code, your brain gets kind of jumbled
876230	878390	because it's just so much bit shifting,
878390	882410	oring and spacing that it's easy to lose track
882410	885030	of where you are and what byte you're working on.
885030	887150	Yeah, we see here, it looks simple,
887150	890490	but if you actually trace through the path, it's funky.
890490	893790	Yeah, it's simple enough,
893790	895450	but when you're under this kind of time pressure,
895450	896790	you really do feel like,
896790	899030	man, how much time do I have to sit and think about this
899030	900210	and really understand it?
900210	901390	Yeah, exactly.
901390	904490	And I think, yeah, we see anger coming out.
904530	906910	Oh, now that is an interesting idea.
906910	908570	That's a very interesting idea.
908570	910710	None of us tried that as far as I know.
910810	912010	No, and it's just encoding,
912010	916370	so there's nothing that should really stop anger from working.
916370	917630	It should be able to solve right through that.
917630	921510	But the question is, you still have to have some shellcode
921510	925270	that's going to run unscathed.
925270	927530	You do, but I'm wondering if this is going to be able
927530	929830	to find a way to write arbitrary bytes.
930350	933330	Because if you can just use the shellcraft-sh
933330	937210	and it'll write arbitrary bytes for you, who knows?
937210	939590	Well, you won't be able to use the shellcraft-sh, actually.
939590	944730	It'll probably return that there's no path available.
946170	946970	Right, right.
946970	951550	I think if you were trying to push things
951550	954150	that aren't going to be possible with the constraint through,
954150	957590	anger is just going to come back and say it's unsat, it's not solved.
957590	960850	Yeah, and actually, Z3 would be pretty good for this, too.
961010	964690	Well, we'll see how that works out for them.
965910	970150	Over on the MMM side, we're looking at the encoder.
970150	973650	This is definitely what the reference solution sort of did,
973650	980470	which was understand, can I have a limited set of operations
980470	983830	that allow me to write out or encode, decode?
983830	986430	I think they're going to be self-modifying shellcode.
988870	989430	Yeah, definitely.
989430	990890	I think that's the approach they're doing.
990890	995110	Because they're looking up PwnTools, Zortools.
995890	997170	Yeah, and that would totally work.
997170	1002030	If you can write a short decoder stub that stays within the constraint,
1002030	1003450	then that's a great solution.
1003450	1004770	That's super smart.
1004770	1005290	Yeah.
1006030	1012930	Or even if you get an off-by-one instruction, then you just ink RIP.
1015900	1016880	Yeah, I want to say...
1016880	1017960	Ink RIP and not.
1019300	1020960	Add RIP, too.
1024980	1026900	Oh, and so now we see that he's...
1026900	1030100	So this is a key insight that we're looking over on the MMM side.
1030100	1034380	He's realized that he doesn't have access to RSI, RAX,
1034380	1037320	but he does have access to EDX, ESI within the constraint.
1037320	1038000	That's right.
1038000	1038940	Key insight.
1040280	1042200	So this is great progress.
1042240	1046020	I'm trying to mix and match, see what the different first byte turns out to be.
1046020	1051320	Right, and he's using sub as the operation, subtract instead of move,
1052280	1055060	because maybe you want to fix up by using...
1055060	1057540	or write bytes by subtracting constants.
1057800	1059980	There's a lot of different ways to do this.
1060440	1061620	Oh, there are so many different ways.
1061620	1064460	I mean, as far as I know, x86 is turning complete.
1067320	1069000	I was really waiting there.
1069000	1071620	I'm like, oh, God, no, that one fell really flat.
1073300	1074780	Okay, so we see...
1074780	1077400	I think in that shellcode there was still a V.
1077520	1079760	Where would that be?
1079760	1082360	No, that has upper bit set.
1083480	1087760	I remember looking at the load string instructions.
1087760	1089500	That was definitely something that I explored.
1090200	1092440	No, V is 0x70 something.
1095340	1098700	It's before 0x7F, so it doesn't have upper bit set.
1098700	1099600	That's right.
1101320	1103280	That good old 7-bit ASCII.
1106270	1109430	Good old ASCII should never belong in the same sentence, honestly.
1110310	1112250	Let's switch to UTF-16 for everything.
1112250	1113750	That's a way better encoding, right?
1115610	1118550	I prefer that every byte needs two bytes,
1118550	1120010	and the second byte is a null.
1124950	1126730	Having written a Unicode decoder,
1126730	1130690	this entire thing is bringing back some PTSD.
1132770	1137370	I think encoding has to be one of the least favorite topics of most hackers.
1137370	1139510	I don't know anybody that really loves encoding.
1139530	1143230	Take this concept, transform it into an entirely new space,
1143230	1144690	and then operate on that.
1144690	1145550	It's easy, right?
1145550	1148450	Every programmer wants to needlessly complicate things.
1148790	1150970	Everyone has the best new encoding.
1151090	1151850	That's true.
1151850	1154590	There should be a standard.
1155130	1156190	Who can make a standard?
1156190	1158390	You need some sort of consortium for that.
1159270	1161430	This is how we end up with new standards.
1164210	1166990	So how is Macaroni doing?
1167330	1169190	Macaroni, looking through,
1169190	1172210	making sure they have a solid understanding of the code here.
1172250	1173470	In IDA dark theme,
1173470	1175110	this makes it really easy for us to keep track of,
1175110	1176170	because we have light theme versus dark theme.
1176170	1177270	I do appreciate that.
1177270	1179030	Light side versus dark side.
1179110	1181310	I'm not taking sides by saying that.
1181870	1184070	But looking through, leaning back in the chair,
1184070	1186310	understanding, okay.
1186630	1189650	So it's seven bits per byte.
1190170	1192270	But you encode it.
1192450	1194890	So you need to pass a normal byte,
1194890	1196990	and it only takes seven bits from that,
1196990	1198770	and sets the top bit.
1198930	1199850	That's right.
1200110	1200930	That's right.
1200930	1202070	And this is...
1202650	1206470	The encoding itself is actually for arbitrarily sized numbers.
1206470	1207070	And so even...
1208110	1209510	Just the idea of like,
1209510	1210550	this isn't a,
1210550	1211890	oh yeah, you just provide your bytes,
1211890	1213310	and it encodes, decodes.
1213310	1217230	Base 64, for example, right?
1217230	1217990	This is...
1217990	1219330	No, it's for integers.
1219330	1220170	It's for integers,
1220170	1223210	which definitely was a little confusing for me
1223210	1224050	when I was reading through it.
1224050	1224370	Oh, yeah.
1224370	1227750	No, that library does not work nicely for it.
1227890	1230370	Does not work nicely for arbitrary bytes, rather.
1230370	1233130	And the decode method just returns an int,
1233130	1234750	so you should see like,
1234750	1236130	where is it?
1236150	1239570	Like bytes to hex in these people's solve scripts.
1239570	1241470	And we saw a macaroni a second ago,
1241470	1242550	checking for the hint.
1242550	1244450	First hint was coming out in 20 seconds,
1244450	1246070	so it should be out now.
1246070	1248210	We don't see either team looking at it.
1249450	1250670	Which is interesting,
1250670	1252750	but we see mhacaroni.
1253230	1254170	Yeah.
1255290	1255810	Encoding...
1256690	1257210	7...
1257210	1259710	Oh, 7 bits from binary output.
1259810	1261770	Yeah, I think that they're trying to
1262650	1264170	graphically print out
1264170	1267470	what their bytes have.
1267470	1270450	I think this is exploring the constraint.
1270450	1271430	Oh, it absolutely is.
1271430	1272730	I'm wondering if this is going to work,
1272730	1274950	because this looks very similar to my script.
1274950	1276450	Or it's starting to, at least.
1277090	1278430	But I don't think...
1279530	1280830	Yeah, shabcd,
1280830	1282350	so those are all the 0x40 range.
1282350	1284790	Those are going to get transformed,
1284790	1286250	and you might be confused by that.
1286670	1287830	But we'll check back.
1287830	1289710	Yeah, there's that long to bytes we saw.
1292150	1294250	Actually, let's see what the script does here
1294930	1297310	before we switch back over to MMM.
1297670	1299070	To send not defined.
1299470	1300510	Yeah, that would help.
1302110	1304730	Do you think that we're going to see the classic,
1304730	1305450	all right, I'm going to look at
1305450	1307190	what I'm sending into the decoder.
1307730	1310330	uleb128 breaks up the input, like base64,
1310330	1313710	into 7-bit blocks, did it say?
1313710	1314070	Yep.
1314070	1318030	So kind of explaining the function to them in English.
1319030	1319590	Right.
1319590	1322750	I think that MMM has an understanding of that.
1322750	1323790	We'll see if that changes.
1323790	1325190	And actually, Macaroni just saw
1325190	1327430	that their 0x41, 0x42, 0x43, 0x44
1327430	1330830	got transformed to C1, C2, C3, C4.
1330830	1331290	Bingo.
1331290	1334350	So I think they're starting to really understand it.
1334350	1335270	Yep, here we go.
1335890	1338750	And now they're looking for a similar table.
1338750	1341110	Oh, wait, they're one click off.
1342010	1344710	Oh, no, look, over on the right, it has first bytes.
1344710	1345790	Oh, that's helpful.
1345790	1346570	That's so nice.
1346570	1347390	It's not an order, though.
1347390	1348890	It's an alphabetical order.
1348890	1350870	Well, it allows you to reference,
1350870	1353510	if you know what instruction you want,
1353510	1357730	you can check what the opcode ends up being.
1357730	1362070	And here we see Macaroni going to be doing very similar things
1362910	1366010	over to what MMM was just doing in their Python terminal here.
1366010	1368190	And it looks like they're doing the same 7-bit encoding,
1368190	1369790	not using any nice Python helper, though.
1369790	1371270	So they're going to have to write the helper themselves,
1371270	1372570	which is prone to errors.
1373050	1373770	Definitely.
1373770	1378250	If you can download a library and have it do the work for you,
1378830	1379990	you should, right?
1379990	1383930	It's not about writing stuff you don't have to.
1383970	1384730	Absolutely.
1384730	1387470	It's about minimum work, maximum flags.
1387870	1389350	That is the goal.
1389350	1392090	And that's what players are really used to doing here.
1392090	1395210	And it looks like he's just going to be rewriting his helper.
1395250	1398010	So rewriting his unpacker?
1398730	1399870	It's so weird to say.
1399870	1403270	Yeah, okay, this is literally what my script looks like.
1404790	1407470	Except I had, like, a mod in the...
1407470	1410450	Yeah, wait, is he going to do times len mod 2?
1410510	1414490	Because if he does times len mod 2, that is my script.
1414690	1415430	Oh, wow.
1417390	1420270	Okay, so going to be reading through the code again over on MMM.
1420730	1422530	mHackaroni, they just switched,
1422530	1426610	but mHackaroni was just going through PwnTools asm various opcodes.
1427390	1429590	Main has unknown type casted to declare type.
1429590	1430450	Is this true?
1430710	1433750	No, no, you can do this as main here.
1435330	1435970	Weird.
1436770	1438390	I don't know why it failed to disassemble them.
1438390	1438770	Yeah.
1439890	1441250	So they're going to be breaking on the call
1441250	1443130	and trying to understand what's going on there.
1443290	1445230	Yeah, because if you look at the disassembly of main,
1445230	1448130	you see that it basically ends in a call to a register,
1448130	1449270	and so everything's set up.
1449270	1452410	It's just putting the shellcode into a buffer
1452410	1453430	and jumping to that buffer.
1453430	1455050	Yeah, there are no complicated states to get there.
1455050	1456250	You're going to have the same register state.
1456250	1457150	There's no randomness.
1457150	1459170	Well, there's randomness in ASLR and stuff,
1459170	1461270	but you have fixed register entry state.
1461270	1463590	And now we see Macaroni really doing
1463590	1465910	exactly the same thing we saw MMM do,
1465910	1468210	which is let me see what the bytes are
1468210	1470810	for a bunch of instructions that I'm going to want to use.
1470810	1471330	Absolutely.
1471330	1473050	And they're going to be going through that for a bit.
1473050	1477230	Over on MMM, you see he finished writing the repacker.
1477610	1479890	Ah, re-unpacker.
1479890	1480770	The un-repacker?
1482590	1484210	And he's going to be going through,
1484210	1485970	finding the right instructions to put there.
1485970	1489610	His shellcode is not assembled instructions.
1490110	1490930	It's just bytes.
1490930	1492550	He's just writing the raw bytes,
1492550	1494030	which honestly makes sense,
1494030	1497330	because that way you don't have to go back
1497330	1500490	from assemble shellcode to integer back and forth
1500490	1502010	and try and keep a mental model of it.
1502010	1503970	It's just laid out clearly for you.
1504570	1507490	Yeah, that was something as I was working on this,
1507490	1509310	I definitely had...
1509310	1511150	I wanted to see the mnemonic.
1511150	1512670	I wanted to see the opcodes.
1513150	1513930	It was...
1514490	1518170	There's not really a good tool for that that I can think of.
1518650	1519230	I don't know.
1519230	1520310	I'm sure there's one out there,
1520310	1522930	but I haven't used one as far as I know.
1522930	1524710	I mean, I did some work in Binja,
1524710	1528850	just assembling stuff in and then doing show opcode bytes.
1528850	1529030	Yeah.
1529030	1532270	And then that was my play for a little bit.
1532270	1535330	But this is not an easy thing to do.
1535330	1538350	Yeah, I was working with Disasm.pro in the browser,
1538350	1540390	just because I'm a browser tool kind of guy,
1541090	1542690	and just typing stuff in,
1542690	1544050	seeing what top byte is,
1544050	1545050	moving stuff around,
1545050	1547450	similar to what we saw these players doing earlier.
1548970	1551830	And it looks like...
1551830	1554870	Okay, MMM just getting calls right.
1555010	1557870	Yeah, passing bytes of int.
1557870	1560610	I mean, the speed at which that they're putting these things together
1560610	1562110	is really impressive.
1562150	1565030	And I mean, there definitely is an argument here,
1565030	1568230	because the encoding is not really complicated,
1568230	1570030	that maybe writing your own
1570030	1574510	keeps you from having to deal with maybe an API issue
1574510	1577430	if you don't like what the module is presenting.
1577950	1583430	We talked about you have to figure out your big integer, so to speak,
1583430	1584530	and then hex encoding it,
1584530	1585970	and figuring out that stuff.
1586150	1589030	Yeah, and it's very much like the ease of use
1589030	1592130	of using that package, that API,
1592130	1594030	versus understanding the internals
1594030	1597010	and making sure that you have access to intermediate states.
1597370	1599670	And kind of the overhead of learning a new thing
1599670	1600870	versus writing your own thing
1600870	1602810	is really something you have to weigh out.
1602810	1604410	And going back and changing your approach
1604410	1605690	to do the other from either
1605690	1608450	is going to be a decent-sized lift,
1608450	1610030	and you're going to be making mistakes
1610030	1611710	on assumptions that don't exist anymore.
1611710	1613410	Exactly, and that's what I was going to bring up,
1613410	1615070	is that when you're using a library,
1615070	1617130	you're limited to the assumptions that they made.
1617130	1618890	Whereas if you're just looking at the assembly
1618890	1621890	and you see exactly what this is doing,
1621890	1626150	does it really matter if it's truly encoding
1626150	1627690	the way it's supposed to be?
1627870	1629550	Because the assembly is the truth.
1629550	1632030	Yeah, I mean, that's really all that matters in the end,
1632030	1634470	is what your state is when you get to that call racks.
1634470	1635030	Exactly.
1636450	1639290	And actually, call racks, you're going to have the...
1639290	1641030	you could do self-modifying there,
1641030	1645850	because you have racks equal to what your current rip is.
1646030	1648170	Right, you do have a register that points...
1648170	1649290	you have a register that points
1649290	1651090	right to the beginning of your shellcode.
1651690	1653970	If I recall, the register state's not that bad.
1653970	1656690	We see MMM going into their debugger.
1656690	1659530	I actually really love to see the debugger
1659530	1662910	integrated with your disassembly, decompiler,
1662910	1665390	RE framework, in this case IDA.
1665390	1666990	I think that's a really powerful move,
1666990	1670650	because I hate switching between windows.
1670650	1674790	And if you've got a script, a debugger, a decompiler,
1674790	1677330	you're flipping between these three things.
1677330	1679590	It's just easier when you've got everything in one view.
1679990	1682410	Yeah, and over on Macaroni,
1682410	1685170	we see them printing out every instruction
1685170	1689110	that matches the constraint that they were given.
1689610	1691290	And lots of new lines.
1692070	1694370	Yep, looks like there's an extra new line in there.
1694370	1696230	Yeah, check if the string is empty, continue.
1696670	1698410	Grep one line, or I'll filter that out for you.
1698410	1699670	Oh, yeah, just grep.
1700750	1702290	Oh, yeah, because they're printing one line in between
1702290	1704310	instead of one line after every valid one.
1704850	1705670	Oh, man.
1706090	1708310	Yeah, I mean, this is CTF code, through and through.
1708310	1710070	This is what we would expect to see.
1710070	1711590	And honestly, this is...
1711590	1713830	if you've got something that prints things out
1713830	1715710	exactly the way you see, that can be a lot more useful
1715710	1718250	than a Wikipedia page, which somebody else put together,
1718250	1721110	probably for people doing sane things instead of CTF.
1721750	1723490	CTF is sane? What are you talking about?
1723490	1726450	It's just writing shellcode and 7-bit unpacking
1726450	1728810	for an integer encoding.
1729410	1730290	Exactly.
1730290	1731630	Oh, I get your point.
1733110	1738070	You know, I started off in CTF,
1739050	1740750	reversing, all of that stuff,
1740750	1742670	and I didn't realize how weird it was
1742670	1745590	until I started dealing with real software people.
1745590	1746350	Oh, yeah.
1746350	1750350	No, I was talking with, once again, the iOS, macOS cat
1750890	1752430	who's helping us behind the scenes.
1753450	1755450	And we were staring at this problem,
1755450	1757470	and she was just like, wait, no, this doesn't make any sense.
1757470	1758410	This is so stupid.
1758410	1761150	And we were staring at this thing for like 30, 40 minutes.
1762050	1764010	And she'd never played a CTF before.
1764190	1766010	And I turned to her and I'm like, congrats,
1766010	1767410	this is what playing a CTF feels like.
1767410	1768950	And she's like, oh, no.
1769190	1771110	This doesn't make sense. This is so stupid.
1771110	1772370	Yep, that sounds like CTF.
1772390	1773030	Exactly.
1773070	1774730	You either solve it or you look at the solution
1774730	1776570	and you're like, wow, yeah.
1776650	1778450	Yeah, not to date myself too much here,
1778450	1781230	but when Python 3 came out
1781230	1784190	and they made it a little bit more difficult
1784190	1785910	to deal with bytes because you had to worry
1785910	1787330	about strings versus bytes,
1787330	1791250	I argued vehemently about why Python 2 had gotten it right.
1791250	1793910	And all of the hackers that I knew were like,
1793910	1795310	yeah, no, it's a lot easier to deal with.
1795310	1798030	But everybody else in the world was like, you're crazy.
1798330	1799850	Have you heard of internationalization?
1799850	1801330	No, absolutely the same thing.
1801330	1802870	I argued completely against it.
1803730	1806910	RPISec's internal tools, I believe, still use Python 2.
1806990	1807630	Oh, my gosh.
1807630	1808210	Some of them.
1809470	1810710	Hey, look, OK.
1810710	1811950	At this point, that's cruel.
1812570	1814710	RPISec, you know, we haven't really been playing CTFs much
1814710	1815910	in the past couple of years.
1817670	1819310	But, yeah, I argued completely against it.
1819310	1822290	And now I'm, like, strong Python 3.
1822930	1823830	Me too.
1823830	1824370	Yeah.
1824370	1825010	Me too.
1825010	1828370	Now when I see tools that are still written for Python 2,
1828370	1829310	it's like, hey, man.
1829330	1830490	Yeah, it's kind of like, come on.
1830490	1831750	I had to switch my code over.
1832370	1834050	Python 2 was EOL.
1834110	1835390	It's been EOL for a while.
1835390	1835850	It's true.
1837190	1842310	So getting back to it, we're looking at Macaroni,
1842310	1843810	still looking through the tables,
1843810	1846350	finding the opcodes that they can use,
1846350	1847730	giving the constraints.
1848310	1850170	Oh, going into XMM registers.
1850170	1851110	Wait a minute.
1851510	1852410	Oh, clever.
1852410	1854070	You know, I wondered about that.
1854250	1854730	Oh.
1854730	1856190	I didn't explore that myself.
1856190	1856690	Gosh.
1856690	1858830	But I thought maybe, you know, you could use these
1859550	1860870	extended registers.
1860870	1864270	To move things around, you know?
1864270	1865470	I'm wondering if they're going to go into, like,
1865470	1866710	AVX 512.
1866710	1868310	And I'm like, does my CPU support it?
1868310	1869210	Yeah, okay, good.
1869210	1869890	We're good.
1869890	1870550	Oh, man.
1870550	1871790	How much of a heartbreaker would that be
1871790	1873330	if you write this beautiful shellcode
1873330	1875670	and then it just doesn't support those extensions?
1875670	1876350	Yeah.
1876590	1877270	No.
1878010	1880530	New CPU, supports just about everything.
1881550	1883130	Really hope they're not going to do the...
1884010	1884810	What's the new one?
1884930	1886250	Zenbleed downfall?
1886550	1887210	Oh.
1887250	1889510	Which one was the AMD one again?
1889510	1891510	Well, I know Zenbleed was, but...
1893590	1894970	What are they looking at here?
1894970	1895930	Is this Python codecs?
1895930	1896790	Yeah, it's Python codecs.
1896790	1897410	All right.
1898430	1901390	So, switching back over to the MMM side,
1901390	1902750	you can see they've got their interactive
1903790	1904970	debugger within IDA.
1904970	1906330	They're flipping back and forth.
1906330	1908770	I really feel like this is the right view,
1908770	1911450	or at least a view that is very helpful.
1911930	1912990	Because it allows you to see,
1912990	1913810	hey, this is the memory.
1913810	1916470	He's got that hex view with the bytes of memory.
1916570	1918910	You can see the disassembly,
1918910	1920610	swap back and forth, the decompilation,
1920610	1922790	and the registers all in one window.
1922790	1924350	I think that helps you move faster.
1924490	1925710	Yeah, absolutely.
1925710	1927410	It gives you kind of the full context
1927410	1929370	in one view, which is really nice.
1929370	1931010	At the end of the day, we're only people.
1931010	1933270	We only have like max one set of eyes.
1933670	1936670	So, keeping track of all these different things,
1936670	1938770	we're going to have that context switch overhead.
1940170	1941490	Right, and as I said,
1941930	1944450	you like to have it as much as you can in one view,
1944450	1945910	but now he's got...
1947250	1949030	He's got his IDE that has a script
1949030	1950290	and two terminal windows open.
1950290	1952450	He's got flipping back and forth to the...
1952450	1952870	The big table.
1952870	1954870	The browser, yeah, with the table.
1955170	1956030	This is a lot.
1956030	1958490	You've got to cross-reference a lot of information here.
1958490	1959530	Oh, absolutely.
1959530	1961150	Be able to organize it in your head.
1961150	1963730	I really like in CTFs having like a dual monitor setup,
1963790	1964930	a little external monitor,
1964930	1967170	because you can have your reference up there,
1967170	1968070	you can have a chat up there
1968070	1970050	if you're talking back and forth to someone,
1970630	1973130	or just like a notepad to keep track of.
1973130	1975330	But live CTF, you do need a mirror screen,
1975330	1976790	so it is...
1977630	1979870	So it is harder.
1979870	1981810	And we see...
1981810	1984730	I don't want to leak Mhacaroni's file system there,
1984730	1986330	but they were searching their file system
1986330	1988110	and funny files came up.
1988110	1991430	It was like, challenges to hack and code better.
1993510	1995150	Well, you know, I've got some friends
1995150	1996830	that are really interested in starting a school,
1996830	1998170	you know, for...
1998170	2000670	School of hacking for kids that want to learn to...
2000670	2003430	Kids that want to learn to hack and be good.
2003430	2004330	Hack good.
2004330	2005390	Hack good.
2005450	2006410	Yeah.
2007270	2009130	Okay, well, I'm going to switch over to Mhacaroni,
2009130	2012330	because they're looking for...
2014270	2017170	Maple CTF CPO 37 write-up.
2017170	2019470	Oh, I think that they're looking for a reference solution
2019470	2022050	to another challenge that might mirror this one.
2022050	2024070	Car set constraint shellcode.
2024110	2024910	Another challenge.
2024910	2027130	And I think they're hoping that they can just
2027130	2029290	plug the constraints in.
2029790	2031130	CPO 37 not found.
2031130	2031890	Oh, yeah, look.
2031890	2035230	They're like, I solved this challenge before, right?
2035330	2036590	Like I solved one very similar.
2036590	2039750	So they're trying to find their own solution on GitHub
2040290	2042210	because they couldn't find it on a file system.
2042570	2045610	That's pretty good when you have that kind of flashback
2045610	2047930	and you're like, wait a minute, I've been here.
2048350	2051350	And I think that that's really a thing in the CTF community
2051350	2054330	is that if you have played a lot of CTF,
2054330	2055970	you kind of have that knowledge bank.
2055990	2058330	You've got an understanding of what are the kinds
2058330	2059850	of problems that people ask you,
2059850	2062110	and you can pull different pieces,
2062110	2064210	even if it wasn't exactly the same challenge.
2064210	2066790	Maybe you can pull like a real slick encoder
2066790	2069190	or a bit of shellcode to do a very specific thing.
2069190	2071270	Oh, yeah, or a Z3 script would be gold.
2071270	2072090	Exactly.
2072230	2072670	Yeah.
2073730	2074850	But going through...
2075590	2077910	Yeah, no, I mean, I know personally my CTF folder.
2077910	2080390	I have some of my CTF solutions uploaded to GitHub.
2080390	2082990	The other ones are too gross for me to upload.
2082990	2085650	And I think that folder is like five gigs now.
2085650	2086710	It's giant.
2088550	2091450	Oh, no.
2091490	2095830	I thought I saw, you know, a controlled exit there,
2095830	2098650	like setting racks properly.
2098770	2100870	But it looks like it was just...
2101290	2102970	Yeah, exit zero.
2103770	2106970	Oh, but it looks like they might have code then
2106970	2108910	if they like got a proper ret.
2110530	2112070	Yeah, looking at what they're doing...
2112070	2112830	Oh, no, I'm sorry.
2112830	2114030	This is their own code.
2114030	2114370	Right.
2114370	2117170	I was thinking they might be compiling something
2117170	2120410	and then ripping out the bytes for it.
2121030	2126670	Oh, they could, but they still need to either jump to a read or...
2126670	2127730	Well, yeah, wait.
2127730	2131530	No, because they'd need a move racks RDI
2131970	2134850	and then they'd need to unset other args
2134850	2136490	and then they'd need a read.
2137470	2138650	I think once you've got...
2138650	2142330	If it's only register manipulation, that's not so bad.
2142330	2145470	But I think that the tricky part here
2145470	2149010	was trying to get the code that you need,
2149010	2151950	sort of your final shellcode that you're going to execute,
2151950	2154430	getting that written to memory cleanly
2155230	2156950	was really the difficulty.
2156950	2159750	And it looks like here, over on Macaroni,
2159750	2162010	they're working with CL now.
2162010	2166130	So that's the lower byte in any register.
2166810	2169510	And I think they found out that that meets the constraint
2169510	2172310	that they can change that low byte,
2172310	2172830	which is going to be BIN.
2172990	2174050	Yeah, and that's what I...
2174050	2175390	We see them writing BINSH now,
2175390	2177130	which is going to be living in their input.
2177470	2180250	So they know they have RIP in racks.
2180470	2181550	Well, they have RIP and RIP also.
2181550	2182690	They have access to every register.
2182870	2185990	So they know relative offset of their BINSH string.
2186110	2188450	You can control lower byte writes.
2188630	2192550	And I believe also second byte writes.
2193270	2194570	Not 100% on that one.
2194570	2197730	I think you can get a 16-bit register right.
2197950	2199110	You can get 16-bit register right,
2199110	2200670	or do you have to do AL and AH?
2202590	2204550	Look, I'm not the Intel manual.
2204550	2205370	I don't know.
2205450	2206570	Believe it or not.
2207390	2209390	Yeah, I definitely had a similar approach.
2209390	2215350	I was using the sort of one-byte register with instructions.
2215730	2217830	And so there's really, at this point,
2217830	2220210	I think two different ways you could be going.
2220210	2222070	You could be looking at the encoder style.
2222070	2223590	Hey, just write an encoder stub,
2223590	2226830	and then decode my shellcode and jump to it.
2226830	2231690	Or you could do sort of a byte or a chunk at a time
2231690	2234530	where you have essentially a mini-decoder stub,
2234530	2235950	where it's more like a writer stub
2235950	2238670	that writes the byte that you want
2238670	2242110	to a targeted area in memory and then jump to that.
2242210	2242890	Yeah, absolutely.
2242890	2245470	Because where you are, it's RWX, I believe.
2245510	2246190	Oh, here we go.
2246190	2247230	And you're not limited.
2247230	2249130	Use 16 and 8-bit RWOFs to get a real write primitive
2249130	2250890	and write a second-stage payload with real shellcode.
2250890	2251950	Exactly what you were saying.
2251950	2253010	Exactly, right.
2253070	2254990	And that works in this case
2254990	2256990	because you're not really limited on size.
2256990	2260130	You're just really limited by this constraint
2260130	2262310	that's really tricky to get around.
2262390	2267490	And with this hint now, we see...
2267490	2269730	Oh, we still can't operate on RAC.
2269730	2271450	Oh, no, RACCL. Yeah.
2271450	2272010	Exactly.
2272010	2276270	So this is where that's exactly the instruction that they need.
2276270	2280630	But the hint there, the 16-bit or 8-bit read-write ops,
2280630	2282530	you can't use RAX there
2282530	2284210	because it's going to violate that constraint.
2284210	2289450	But you can use things like EAX.
2289490	2293230	The 4-bit width, 4-byte width operations
2293230	2296710	for writing to memory should work.
2296730	2300290	Can you use EAX or do you have to use AX?
2300710	2308470	I believe you can use something like MOV, dereference, EDX.
2308470	2309510	Oh, okay.
2309510	2311610	So the deref might...
2311610	2312230	You're right.
2312230	2313310	I'm going to trust you on this
2313310	2316370	because, once again, I'm not a disassembler.
2319530	2319970	But...
2319970	2321110	We still love you anyways, Josh.
2321110	2323090	Oh, thank you so much, guys.
2323150	2327030	Even though I don't have 8,000 pages and so many mistakes.
2327030	2329090	Some of my best friends are manuals.
2330030	2331410	I have a friend named manual.
2334690	2336230	MOV, byte point, okay.
2336230	2337830	So therefore my string is broken.
2338950	2341690	So they need to add brackets around the J.
2341690	2344350	So we'll see them figure that out eventually.
2344350	2345750	There's a lot of experimentation.
2345750	2348230	It's so much easier being a commentator, honestly.
2348690	2351270	I mean, I definitely banged my head on this challenge for a bit.
2351270	2352910	Oh my gosh, same.
2352990	2356710	So the hints are released at 20 minutes in and 35 minutes in.
2356710	2360910	So that means we are max, like, 15 minutes away from sudden death.
2360910	2361590	That's right.
2361590	2364230	Yeah, we are getting near the end.
2364230	2366070	We knew that these challenges are hard.
2366070	2371470	Sudden death was sort of always on our minds as it might come down to that.
2371470	2373250	I'm hoping that that's not going to be the case.
2373630	2375890	I have faith in our competitors here.
2375890	2377870	I think that they're going to figure this one out.
2378130	2378910	I think they are.
2378910	2384050	I think they're both making really good progress towards the final goal of setting up that second stage payload.
2384050	2385110	Well, final goal.
2385590	2389010	Towards the intermediate goal of making that second stage payload.
2389170	2389690	Right.
2389690	2394630	You know, I think that MMM, they kind of got to the idea pretty quick.
2394930	2400430	They have been spending a bit of time now working through how to get things lined up.
2400430	2403150	I think that they're on the right track.
2403530	2406250	Yeah, well, I see a lot of Zord D-word pointers.
2406430	2411990	You know, RSP plus 0x7B89, like, these random offsets.
2412050	2417770	So, I think they're getting close, but they might get hung up on some small details of, like,
2417770	2421690	I have a null byte in the middle of my shellcode somewhere that I just missed.
2421950	2428670	Yeah, it's always something that you can just have the littlest thing mess you up.
2428670	2433850	You don't catch it, or you've got, like, 99% of the solution, right?
2433850	2435930	It totally happens in CTF.
2435930	2438790	Absolutely, in this challenge, those mistakes are cascading.
2438790	2441330	They will mess up everything after them.
2441350	2444650	You know, potentially around them, like on either side, too.
2445650	2451390	So, catching one is going to be hard, and you might just think to yourself, like, I'm messing all this up.
2451390	2458130	What I really liked doing in this challenge was setting up a known good beginning write that was just garbage.
2458130	2461510	You know, it was a bunch of nops. It was just a bunch of A's, whatever.
2461510	2464410	Just to make sure that my write primitive still works.
2464410	2466770	Like, I can still write that first stage shellcode.
2467790	2470430	Yeah, I think that there's a lot of...
2471190	2473890	This is one of those challenges where you want to have those sanity checks.
2473890	2477470	I definitely was printing out my disassembly.
2477470	2479550	I was checking the hex dump every time I ran it.
2479550	2483370	So, if something did change, I would at least be able to see, oh, the pattern changed there.
2483370	2485550	Something went wrong. I've got to go back and fix that.
2485550	2489670	Yeah, like I'm doing stir of bytes instead of dot decode or dot encode.
2489670	2491210	God, now this has me backwards.
2493610	2502550	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...
2503090	2506090	It's a simple concept with really hard execution.
2506150	2506530	Right.
2506530	2516570	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.
2516570	2519310	And you're like, oh, that's close enough. I can just do this.
2519310	2524050	And then you get to actually implementing a solution for it, and you're like, oh, my God, I know nothing about computers.
2524230	2525270	These were a mistake.
2526250	2532050	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.
2532050	2534410	And that's how I felt when I was working on this.
2534410	2536870	Yeah, no, absolutely same.
2536870	2545890	I really had the layout down, but actually writing, like, that first stage payload was not a good time.
2545890	2548230	And it took me way longer than it probably should have.
2548950	2554650	So it looks like MMM debugging their writes not working out quite right.
2555010	2563030	And, okay, so here over on Macaroni, we see them using debug assembly, which is a great feature of Puntles.
2563030	2566250	And just trying to figure out, they have a move racks.
2566270	2570810	Oh, they're trying to figure out what's the, they're trying to make a stack frame via enter.
2570990	2572570	Oh, that's clever.
2572570	2584610	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.
2584610	2587030	That seems a little overkill in my opinion.
2587030	2593610	Well, you know, I never count the competitors out for coming up with clever solutions that we didn't expect.
2593610	2596330	Exactly, yeah. And it could be easier for them.
2596410	2598830	Like, they might be, like, SIGROP masters or something.
2598830	2599190	Sure.
2599190	2602170	And they're just like, I don't know how to write shellcode math.
2602490	2604770	Yeah, they could be like, no, I invented this technique.
2604770	2606150	Yeah, really, really.
2606350	2609850	Well, I mean, we have Jinmo on MMM right now, and we were talking about it.
2609850	2612650	He had a solution yesterday that was, I think, eight minutes.
2612970	2616170	And we're looking at each other, and we're just kind of like, did this happen?
2616170	2619490	And we look at the username on the screen that says Jinmo, and we're like, oh, yeah.
2619770	2621110	Okay, that explains it.
2621270	2623570	Yeah, we've got some truly impressive competitors here.
2623570	2624250	Absolutely.
2624430	2628970	Anybody who has won against this many other competitors at this level.
2629090	2629690	Yeah.
2629690	2630610	Top tier.
2630670	2631510	Exactly.
2631510	2634470	No, these are all fantastic hackers.
2634470	2639530	We need to point that out, that these challenges, they have little to no time to get acquainted with them.
2639530	2645910	Their mind is still on, you know, the challenge they've been staring at for the past 12 hours in DEF CON CTF.
2645910	2647430	You know, the non-live version.
2649050	2651670	And just they have so much going on in their mind.
2651670	2655030	They have someone sitting directly across from them that they're hacking against.
2655350	2657310	And even that adds its own stress.
2657310	2658190	They're on stream.
2658190	2659670	That adds more stress.
2660090	2662110	It's a foreign concept, you know.
2662190	2664070	They don't have tools set up for this.
2664070	2668270	They don't know that, like, oh, yeah, this is normally like a Pwn CTF, like DEF CON finals usually is.
2668890	2670670	It's new territory for them.
2670670	2672270	And I think that can be really daunting.
2672270	2675150	And the first step in this isn't getting acquainted with the program.
2675150	2682950	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.
2683110	2689070	Yeah, DEF CON CTF really could include challenges in any weird area.
2689070	2696090	I mean, I think we had a competitor ask us, hey, can you specify what architecture this is on?
2696090	2698350	And so far we've only seen x86.
2699270	2702110	But with the finals, anything goes.
2702110	2705370	Well, we had your Python shellcode challenge, too.
2705650	2711270	That's true, that's true, which, you know, technically you didn't need to care about the native implementation.
2711310	2712750	We had people walk up to us.
2712750	2715150	I don't know if you know this, but we had people walk up to us.
2715230	2719570	And the category we gave them was Python, I think Python shellcode.
2719910	2722610	And they walk up to us and they're like, hey, can you be more specific?
2722610	2723430	What exactly does that mean?
2723430	2724790	And we're like, what do you mean more specific?
2724790	2728030	And it's like, well, like, is it Python written to shellcode?
2728030	2730170	Is it like shellcode that has to be valid Python?
2730170	2732850	And we're like, dude, you have an hour for these challenges.
2733450	2736550	It's not going to be like Python bytecode that's also valid shellcode.
2738070	2739570	Oh, was it?
2739570	2741950	No, it would be interesting to try something like that.
2741950	2744030	I'm like, did we do that?
2744590	2745570	No, no.
2745570	2749410	So in that challenge, you didn't need to go low level.
2749410	2751810	You could just ask Python to compile the bytecode for you.
2751810	2753230	Yeah, OK, OK.
2753290	2757270	No, I didn't think we'd have them, you know, do a polyglot challenge like that.
2758470	2761370	See, and coming up with stuff is hard.
2761490	2766650	So having a challenge that involves the topics that you're interested in,
2766650	2772210	that you think will be fun for competitors, but also, you know, reasonable for the time frame.
2772290	2773690	Yeah, it's not always easy.
2773690	2778730	Well, we were talking, just organizing this, that I think writing the challenges is easy.
2778730	2780470	Coming up with the ideas is hard.
2780670	2785030	And then talking with Glenn and Carl, I think, they said, oh, the ideas are easy.
2785030	2786010	Writing the challenges are hard.
2786010	2787270	And I'm like, wait a minute.
2787270	2790890	It's very much like, you've got chocolate on my peanut butter, you've got peanut butter on my chocolate.
2791230	2794550	It's the perfect team that works out.
2794650	2797730	And that's why it's great to have people that think differently on your team.
2797730	2798190	Oh, yeah.
2798190	2805670	And if we switch back to the MMM side, it looks like what they're doing is having a handwritten decoder there
2807030	2810590	that's just decoding a D word at a time via XOR.
2810590	2813430	Oh, they're just, wait, but they're just XORing.
2813430	2817650	So they're just only using shell code that doesn't have top bit set.
2817710	2822470	Which is definitely easier because when I tried to solve this, that's what I thought the constraint was at first.
2822470	2824270	And so I wrote this nice shell code.
2824530	2825610	No top bit set.
2825610	2826210	But it's working.
2826210	2827350	They have a syscall.
2827690	2828930	They have syscall.
2828930	2830570	They don't have bin sh.
2830690	2832770	So they probably just determined...
2832770	2833730	Error no 14.
2834330	2836050	I love how they search error no 14.
2836050	2838330	It says, oh, yeah, HTTP error 404.
2841210	2841730	Wow.
2841730	2843730	So that's a really clever idea.
2843730	2849050	And it looks like there might have been some corruption on their shell code.
2849050	2852350	But other than that, they're looking like they're on the right track.
2852350	2853930	I think they don't.
2853930	2856450	So they've got a big NOP sled.
2856610	2860750	They've got their payload that they're going to XOR back.
2860870	2862950	And then...
2862950	2865050	Which that's totally valid.
2865050	2866130	Great idea.
2866270	2866870	Yep.
2867070	2868190	Got EOF reading and interactive.
2868190	2870330	So NOP's going to have the top bit set.
2870330	2873330	So your vanilla x86 NOP.
2875670	2878510	Oh, yeah, yeah.
2878730	2882830	So now he's just troubleshooting what went wrong with that, right?
2883250	2884530	Is the shell code intact?
2884530	2888990	Was the string reference the address of bin sh?
2888990	2891750	Pop rdi, push rdx, pop rsi, syscall.
2891750	2893710	Does he have bin sh on the stack?
2894250	2895610	I think he forgot about bin sh.
2895610	2897270	Oh, no, he's using shellcraft down there.
2897270	2900910	Hidden under his two global area terminals.
2901770	2903390	Okay, so it's just NOP.
2903630	2911730	Do you recall if the shellcraft shellcode, if that just uses a move to push the string into a register and then out?
2911730	2913070	I believe it does.
2913630	2917390	And I think it also sets all the register states, so he should be good there.
2917390	2922290	I was going to say that's one of the things that this is a little nonstandard,
2922290	2925390	but every challenge you have to understand what your register states are.
2925390	2928110	There may be some implicit assumptions in your shellcode.
2928110	2929350	Yes, absolutely.
2929350	2933690	But I think it's really nice that the path to your shellcode being executed is so simple
2934330	2939070	that you don't really need to worry about any randomness outside of ASLR.
2939070	2942530	Stack offset is already in a register.
2942730	2948130	You have RAP in two different registers, so you have different possibilities for instructions there.
2949230	2951550	Wow, I think that he's getting very close here.
2951550	2952970	I think MMM is really close.
2953050	2957590	Macaroni? Macaroni? Macaroni? Not sure.
2957590	2961350	Still looking at instruction encodings, trying to figure out which one they can use.
2961350	2965050	It looks like they're iterating through all the possible registers
2965590	2971790	and figuring out what can encode correctly or what can encode and match the constraints.
2972130	2981110	Yes, and like we mentioned, all of those R prefixes on those registers indicating the 64-bit width,
2981110	2985130	pretty sure that those aren't going to be able to be used with this constraint.
2985130	2987070	Oh, and it looks... oh my God.
2987290	2992170	Wait, they just got immediately... MMM just immediately solved.
2993130	2994610	Did they solve?
2994900	2999510	They solved. 40 seconds before sudden death we heard.
3000840	3002630	Let's double check here.
3002970	3006230	Yeah, Team 2 made... yeah, MMM won match 19.
3006230	3008390	Wow, incredible. Incredible.
3008390	3009470	Oh my goodness.
3009470	3014190	Just an outstanding job throwing together this, getting it at the last moment.
3014190	3015570	This is a tough challenge.
3015570	3021510	We can see that Macaroni was also having a real hard time.
3021510	3026010	This is, again, sound simple, hard challenge, excellent work.
3026010	3028150	Very close for a long time there.
3028150	3033310	And then MMM really had the idea of setting up their second stage payload using XOR,
3033310	3040510	which top bit unset is going to be a lot easier in 64-bit x86.
3040510	3044530	Yeah, I think they just did XOR negative 1 because negative 1 is going to have all the bits set.
3044530	3046830	And then away you go.
3046830	3048790	And then you just flip-flop everything.
3049550	3052150	Yeah, they had 40 seconds left until sudden death.
3052150	3052550	Wow.
3052610	3054630	That's crazy. So that could have been really close.
3054630	3056890	That could have been a big upset in sudden death too.
3056910	3061130	Well, a great challenge. Outstanding job to our competitors.
3061530	3062230	Absolutely.
3062230	3065090	Difficult, came down to the wire. I'm glad we got to see that solved.
3065090	3070710	And so MMM will be going into the finals of the lower bracket.
3070850	3075070	So they'll have a chance to fight all the way back to the finals and maybe even win it. We'll see.
3075070	3081130	Maybe see them in grand finals against one of Hypeboi and Strawhat coming up next.
3081130	3085950	We're going to go ahead and get those teams swapped over and we'll see you back for the next match very shortly.
3085950	3086670	Alright.
