00:00:00.267,00:00:04.304 >>Alright, now they’re gonna talk about the uh little bit of new uh nuke shell coding and a 00:00:04.304,00:00:09.309 little humor along the way. Go ahead fellas. >>Hi, hello DefCon. How are you today? 00:00:15.716,00:00:20.821 [crowd answered] Brilliant. Very glad to be here today. Gonna talk about the ABC of next 00:00:20.821,00:00:26.126 generation shell coding. A lot of interesting things. So let me just say a few words of 00:00:26.126,00:00:32.633 disclaimer before I begin. Don’t look at what’s written there. We are going to have a deep dive 00:00:32.633,00:00:39.439 into the dark arts of shell coding. We’ll use brute force mathematics, wizardry, bit of 00:00:39.439,00:00:44.444 dancing. We’ll make your head spin at some point. And the idea will be to build up obscure 00:00:48.148,00:00:54.054 incantations to make computers do things they shouldn’t do. We’ll conjure monsters, give you 00:00:54.054,00:00:59.960 nightmares and hopefully you’ll stay until the end so that you know why we do all these things. 00:00:59.960,00:01:04.898 So just a few words about who we are. Uh the three of us. You’ve got Hadrien. Goerges-Axel. And 00:01:07.868,00:01:12.873 myself. Uh we we work at University, we work as researchers in security and the 00:01:16.443,00:01:22.883 point of the talk today more precisely is creative methods and I insist on creative to 00:01:22.883,00:01:29.156 write shell codes or exploitation code and our constraints on new architectures 00:01:29.156,00:01:35.996 and we will illustrate that on an architecture that is not even easy to find actually right now. 00:01:35.996,00:01:41.001 Because it’s uh not a deployed very much. So just a reminder, who who amongst you has ever 00:01:44.004,00:01:50.177 written a shell code. Just raise your hands for me. Uh that’s half. Yeah Ok. So you know how 00:01:50.177,00:01:56.883 it works, so you think at least. Um, for the other half, this is what shell code is. It is 00:01:56.883,00:02:01.822 essentially code that you wrote or found in a targets memory and that you want to jump to. And 00:02:04.491,00:02:09.496 usually it’s it pops a shell. So that’s what you call it a shell code. And then once you have a 00:02:09.496,00:02:14.835 shell you do whatever you like. To to actually jump to the shell code, uh you have to trigger 00:02:14.835,00:02:20.741 vulnerability, a a buffer overflow or use up the free diconfusion whatever. Um, but 00:02:20.741,00:02:25.746 the typical scenario is that you’ll target a random program, the program accepts user input 00:02:29.182,00:02:35.922 and so you write user input, you carefully craft user input so as to inject your code in memory 00:02:35.922,00:02:42.462 and jump to it. So you have a nice picture on the screen there that targets memory uh and gets 00:02:42.462,00:02:47.267 the payload inserted and then you jump to it using the vulnerability. So that’s very 00:02:47.267,00:02:53.473 nice. The issue with that is that it’s not that easy for those of you who actually wrote 00:02:53.473,00:02:58.478 shellcodes, you know it’s not trivial. Um, there are constraints because it has to 00:02:58.478,00:03:03.550 pass as user input so you can’t have uh terminating zeros in in your strings. There might be 00:03:03.550,00:03:08.922 stack protections, you may have limited memory. You may not know where the shellcode is in 00:03:08.922,00:03:13.960 memory. That’s tr- that’s annoying really. Turns out you can work around these 00:03:13.960,00:03:19.066 constraints. You you- can, you can always succeed. Nevertheless, uh, using clever 00:03:19.066,00:03:21.068 techniques we are not going to talk about the techniques to bypass existing mi- mitigations 00:03:21.068,00:03:23.070 because while they’re well known and that’s not the point of the talk today. What I’m going to 00:03:23.070,00:03:28.075 talk about. Is the fact that the shellcode such as this thing does not look like user input. I 00:03:38.118,00:03:43.323 mean, perhaps you guys input such things, but the normal human beings which are not here 00:03:43.323,00:03:48.328 today, would not. And there are several things that give it away. Uh things such as, um, the 00:03:50.564,00:03:57.070 presence of NOP. Characters NOP instructions in the code. The non-printable characters in it. 00:03:57.070,00:04:03.076 The presence of suspicious sub-strings such as bin sh. And the fact that you have bits that 00:04:03.076,00:04:10.050 I mean look like, well known malware for instance. Type sign, so this is suspicious. And this 00:04:10.050,00:04:16.223 is the detectable. Which means anti-virus or blue teams or I mean, your unknowing neighbors 00:04:16.223,00:04:22.863 will find out that what you’re writing is actually a shellcode and perhaps make it uh a problem 00:04:22.863,00:04:27.868 for you. So we try to stay under the radar and one way to do that, an illustration of that to 00:04:30.337,00:04:36.309 pass as human inputs, especially for strings is that you want your shellcode to be written 00:04:36.309,00:04:42.482 using for instance just ASCII characters, ASCII printable characters. Or perhaps just 00:04:42.482,00:04:47.721 alphanumeric characters for user name for instance. Perhaps English words. You just want to 00:04:47.721,00:04:53.927 write poetry. You feel inspired. It turns out to be a shellcode. Why not even Shakespear quotes? 00:04:53.927,00:04:58.932 So why would you do that? Wha- wha- for one, if it really looks like it’s just English text, it 00:05:03.770,00:05:09.109 does not trigger alarm that much and you have plausible deniability. You could just say 00:05:09.109,00:05:14.114 this is poetry, this is the lyrics of my next song. Right? It’s it is it is not an NSA 00:05:17.684,00:05:22.689 implant. Well, of it course it is, but. It is also less likely to be escaped or broken. Because 00:05:25.091,00:05:30.397 it is already text, it doesn’t have any special character. So your exploit might work better. 00:05:30.397,00:05:35.569 And if everything else fails, you can always try the pickup line at the bar. Ok? So do try 00:05:35.569,00:05:41.274 that. The only question remaining is is that feasible? Can I write my code. My 00:05:41.274,00:05:46.279 programs? My eternal blue using only English words. Yes. Take the x86 instruction set for 00:05:52.485,00:05:57.891 instance. And just look what the letters look like when you disassemble. You’ve got for 00:05:57.891,00:06:02.829 capital letters A to O, you got uh increment and decrement operations. For the others, 00:06:05.332,00:06:10.870 you’ve got push and pop. So stack operations. You’ve got jumps, you’ve got xor, so you 00:06:10.870,00:06:15.875 can actually do a lot of things. Alright. It turns out uh, rix and others have shown the x86 00:06:18.845,00:06:25.752 ISA is extremely nice and smooth when you try to write alphanumeric code. You you’ve 00:06:25.752,00:06:32.225 got everything you need and you can even make it work on 64 bits architecture. Almost trivially. 00:06:32.225,00:06:37.230 So here is a full shellcode that works on x86 64 written entirely using letters and and numbers. 00:06:40.100,00:06:46.072 Therefore you can print that on a t-shirt, right? Just that’s what you should do. Now you can 00:06:46.072,00:06:51.077 actually go further than that. >>Well, you can even go further and uh, for example, here we 00:06:53.113,00:06:59.219 will see how to do for so- some English sh- shellcoding, so it has been published, uh, almost 00:06:59.219,00:07:06.126 exactly 10 years ago by Mason and uh others. Uh, the idea is uh to do exactly the same as 00:07:06.126,00:07:12.899 previously, but not this time you will generate an English compatible subset of x86. So 00:07:12.899,00:07:17.470 this is exactly alphanumeric as before, but you have even more than alphanumeric characters. So 00:07:17.470,00:07:22.976 you can have spaces, you can have punctuation, uh, you can have uh colons, semi-colons, you 00:07:22.976,00:07:28.415 can have dashes, uh you can have some special characters. Uh for example, it gives you even more 00:07:28.415,00:07:34.587 instructions li li- than that. For example, if you look at point. You can have more uh, 00:07:34.587,00:07:39.993 appearance available as before. And if you look for example at space, you have one more upcode, 00:07:39.993,00:07:46.399 uh which gives you the end instruction. So we have more than that. So the fundamental 00:07:46.399,00:07:52.005 idea behind that is that you do a normal shellcode, so you write a small decoder with those 00:07:52.005,00:07:58.712 instructions. Then you cut it into sma- small snippets of code that would fit into English 00:07:58.712,00:08:05.051 words, then you have some gaps. You- uh and those gaps you can jump from each snippet to 00:08:05.051,00:08:09.789 another using j- the jump instructions you can see there. And just the idea is to fill 00:08:09.789,00:08:16.062 those gaps with something that makes your shellcode look like English uh, English text. Of 00:08:16.062,00:08:20.433 course this is done using markov chains. Uh, so Markov chains fundamentally are just uh the 00:08:20.433,00:08:26.039 auto completion uh feature on your iphones. So you write a word and then it gives you some 00:08:26.039,00:08:31.211 other words. So it can give you some pretty nice text uh if you write some uh a some uh some 00:08:31.211,00:08:36.216 SMSs with uh that. And uh and you just have a text that looks like English co- uh that looks 00:08:39.419,00:08:44.124 like you just have a shellcode that looks like English text. You send it to the to the to the 00:08:44.124,00:08:48.661 vulnerable application and you enjoy and you have your word chat. So let’s have a little 00:08:48.661,00:08:53.666 demo for that. So this is what I did on my computer. So here. We would go for a standard uh set 00:08:58.238,00:09:04.944 user ID exploitation so the idea is you have uh that ID behind it is that you have a program that 00:09:04.944,00:09:10.850 would be executed as a root program. But it can be executed by the standard user, for 00:09:10.850,00:09:15.688 example, if you want to change your password, then it has to be a root action that has to be 00:09:15.688,00:09:22.295 done by uh the standard user. So you have a program executing on root. So here we give it the set 00:09:22.295,00:09:27.300 user ID permission. And when we switch to the user so we can have our program here that says 00:09:29.569,00:09:34.541 that you have the small S in the permissions that says you, it gets executed as root. And the 00:09:34.541,00:09:40.980 idea is to send a shellcode to it. So that it does something else that what it was supposed 00:09:40.980,00:09:46.419 to do. So here we have our English text here. We just write it. We send it and we have the 00:09:46.419,00:09:51.424 uh root uh shell that pops out so we can check that indeed we are root here. [applause] More 00:09:59.099,00:10:04.103 generally uh, when we speak about x86 uh it's almost fully solved so the idea is that you 00:10:07.207,00:10:14.013 have a for example, msf phenom so you just say I want uh some shell code on x86 with this 00:10:14.013,00:10:17.817 restrictions on the instruction set, so I want only alphanumeric, I want alpha plus 00:10:17.817,00:10:22.088 uh some characters, I want something that looks like a URL, I want something that looks like 00:10:22.088,00:10:26.826 uh a path and this kind of thing. And its automatically generated you uh whatever is 00:10:26.826,00:10:31.664 required so that uh it everything goes well. In principle, we could even write 00:10:31.664,00:10:36.236 uh some fully functional shellcodes from only Shakespear quotes. Uh but uh what would we 00:10:36.236,00:10:41.241 sp uh speaking about uh in the next uh part of the talk? Would not be on x86 uh because now we 00:10:43.276,00:10:49.782 have more and more devices that are running on something else than x86. Uh and I’ll give uh, 00:10:49.782,00:10:54.554 I’ll give uh. Here. >>Yeah so, so challenge for you, by the way the the Shakespeare shell code. 00:10:54.554,00:10:59.559 We did not do it. Do it for us. Now we going to take risks. And as was just mentioned, what 00:11:04.130,00:11:09.836 powers most devices today is slowly drifting away from x86, including phones, including 00:11:09.836,00:11:14.173 voting machines, including several interesting things that we’d like to run shell codes on. 00:11:14.173,00:11:19.178 And and to do that, we need to look at the way for instance RISC instruction such as ARM, 00:11:22.382,00:11:28.621 um, work. It turns out that you can not choose the techniques which are described on the ARM. 00:11:28.621,00:11:34.627 Reasons are you do not have anymore single character instructions. We do not have as 00:11:34.627,00:11:38.831 many addressing modes, in particular we like, we like the memory to memory addressing 00:11:38.831,00:11:44.671 modes. And we have constraints on operants that make it very tricky and actually so far 00:11:44.671,00:11:49.676 impossible to write shell codes for RISK 5. Uh, does not work uh o- on o the ARM architectures as 00:11:53.980,00:11:59.686 as well. Um, so I’m going to talk about three approaches very quickly about the two fo- th the 00:11:59.686,00:12:04.757 two uh compilation and emulation technique and a bit more unpacking technique. So three 00:12:04.757,00:12:11.598 ways around this limitations that allow us to work nevertheless. The compilation 00:12:11.598,00:12:17.370 approach, the first approach, consist in compiling assembly code directly to the constraint 00:12:17.370,00:12:24.043 instruction set. Directly to alphanumeric for instance. Uh, operations. The the good thing 00:12:24.043,00:12:28.548 about it is that it may be possible to compile to one instruction sets uh easily. 00:12:28.548,00:12:31.751 That’s the Movfuscator for instance written by Christopher Domas uh does that. The the the 00:12:31.751,00:12:37.190 main disadvantage of such an approach is that uh it does not work when the constraints are on 00:12:37.190,00:12:42.195 the operants and not on the upcodes and also who wants to write a compiler? I mean if if 00:12:47.133,00:12:52.572 Chris Domas is in the in the room do it? Please. By all means do what you want. That’s just a 00:12:52.572,00:12:57.577 life’s time work. Second approach, the emulation way. To do that you write an interpreter 00:12:59.646,00:13:05.818 for some language, you write your payload in that interpreted language and uh you just run 00:13:05.818,00:13:10.823 that. The thing is you have to write the interpreter um once. And once that’s done, well, you 00:13:12.892,00:13:16.529 can reuse it for different payloads. Works quite well, it’s feasible. It’s been done by 00:13:16.529,00:13:21.534 Younan a- and Philippaerts. Uh for ARM 7, they did a Brainf**k interpreter. And while that 00:13:24.837,00:13:31.811 works. The issue with that is what? Well it’s interpreted which means its toothless, you 00:13:31.811,00:13:35.948 cannot really call syscalls, you cannot really do fancy stuff that you’d like to do with a 00:13:35.948,00:13:40.953 shellcode, right? So leaves us with a third approach which we introduced some years ago. And 00:13:43.656,00:13:50.463 the idea is a several step process. Let me just take some time to explain that one. The 00:13:50.463,00:13:56.069 first step is that your payload will be encoded in a constraint-compliant way. For 00:13:56.069,00:14:02.008 instance if you want uh alphanumeric shellcode, you would first encode it in some uh 00:14:02.008,00:14:07.013 alphanumeric way. You hide it as you can see on the top right. Picture. Then you look at the 00:14:10.016,00:14:16.622 ISA you’re targeting and you identify high level constraint-compliant constructs. 00:14:16.622,00:14:21.461 So a set of instructions you you, that that fits with your constraints and allows you to do 00:14:21.461,00:14:27.700 some basic operations. Building blocks. Zeroing a register. Increasing a register. And using 00:14:27.700,00:14:34.273 these building blocks. You build and the unpacker. Something that decodes in memory, in self 00:14:34.273,00:14:41.047 modifying code, that payload. Write the minimal unpacker because we don’t want to spend 00:14:41.047,00:14:45.184 too much time on that and we just don’t care about the unpacker that much. We want to 00:14:45.184,00:14:51.424 run the payload. So the unpacker encodes and executes the payload. This is straight there. 00:14:51.424,00:14:56.429 Sorry, uh. >>So on e- on there v8, this is the demo of this approach. Very quickly speaking, 00:15:02.802,00:15:08.908 um, we run sorry, so you’ve got the application there. Uh this application takes a string as 00:15:08.908,00:15:15.181 input. For instance a username. We place there the shellcode, which is written with this 00:15:15.181,00:15:20.186 unpacker strategy. Um, so here is the shellcode you can see it’s mostly letters. We ran 00:15:25.558,00:15:30.563 that. We just paste it. And once that’s run, it unpacks in memory, executes it and here is 00:15:35.935,00:15:40.940 the shadow oh- of the target. [applause] Ok, so now that you saw how you ca- we can we can 00:15:53.486,00:15:59.859 bypass the limitations of usual ARM processes, uh as if we’re not, everyone’s turning around 00:15:59.859,00:16:06.365 from a- x86, we’re gonna turn our attention to RISC 5. For various reasons. >>Thank you. 00:16:06.365,00:16:11.771 So, RISC 5, maybe you’ve never heard about it. It is a new architecture. Uh basically it is 00:16:11.771,00:16:16.776 a a once again a RISC architecture. Very much like MIPS if you heard about it. It 00:16:20.580,00:16:26.419 aims at being open source and also open hardware. And it is still very work in progress. By 00:16:26.419,00:16:31.257 this I mean that, this specification is not completely done yet. There is very few 00:16:31.257,00:16:37.196 silicon available. But hopefully uh in a few few years, we’ll see RISC 5 everywhere. So many 00:16:37.196,00:16:41.601 companies interested in it. So that remain to be seen, but hopefully it is the architecture 00:16:41.601,00:16:48.441 of the future. We do have one issue with RISC 5 when it comes to out of the way shellcoding. 00:16:48.441,00:16:53.446 It is that it makes our job much much harder. So let’s look at what is available for us in 00:16:56.349,00:17:03.256 alphanumeric RISC 5. So first, we can load a few constants with typically will load inst- load 00:17:03.256,00:17:09.262 image to load upper image then we have small increments, if you combine both of them it means 00:17:09.262,00:17:15.668 you can load quite lot of values and registers. So then we have some branch shells, both 00:17:15.668,00:17:21.340 conditional and unconditional. But only for what branches. We do not attack backward branch 00:17:21.340,00:17:26.345 shells, so that’s an issue. So then we have a single arithmetic instruction, which is a high 00:17:28.714,00:17:33.719 shift, why not. And then we have a system register write, uh is an issue with this instructions 00:17:36.956,00:17:41.460 is that it is only available at higher privileged levels. Typically it would work if you 00:17:41.460,00:17:46.465 uh are attacking a Linux or your operating your operating system, but not just a simple argument. 00:17:49.001,00:17:54.607 So what we just forget about them since we want something quite generic. And finally we do 00:17:54.607,00:17:59.612 have miscellaneous floating point operations. So as you have seen, we have no loops because 00:18:04.584,00:18:09.588 [inaudible] no store and no syscall and no Cisco. Eh- we’re, we are start. And I can even 00:18:11.724,00:18:16.729 tell you it is not even totally complete. So let’s look at what a typical RISC 5 instruction is. 00:18:19.198,00:18:25.671 If you look at the 7 load bits of a binary representation of an instruction, you have the opcode 00:18:25.671,00:18:30.676 and 7 bits is exactly what ASCII character is. So we will just allow ourself one more single 00:18:34.480,00:18:40.586 printable character.As a spoiler I can tell you that there are three useful printable 00:18:40.586,00:18:47.059 characters that can uh go make us go out of a no loop no store and no syscall issue. We have 00:18:47.059,00:18:52.064 hash, slash and tick. Typically hash will give us uh regular stalls, with regular stalls we 00:18:55.101,00:19:00.039 can write our unpacker. So let’s look at how it works uh for uh writing alphanumeric plus hash 00:19:04.744,00:19:09.749 uh shellcode on the RISC 5s. So here is architecture, we have three stages. Over left is the 00:19:12.752,00:19:18.491 stage 1. First we have some initialization, then we do use a forward jump which is a jump and 00:19:18.491,00:19:23.529 link uh we have a jump and link which means you can actually get the p enc of the shellcode which 00:19:23.529,00:19:28.401 is quite useful. If you do not know exactly where your shellcode is in memory. Since we 00:19:28.401,00:19:35.074 have the forward jump, we have some wasted space. So we use the wasted space to uh pass the 00:19:35.074,00:19:41.447 encoded payload. Then we write our unpacker which is the hard thing to do. But we won’t unpack 00:19:41.447,00:19:47.586 directly the payload. We’ll first unpack a stage 2. The reason we do this is because uh 00:19:47.586,00:19:54.493 it is difficult to write the generic unpacker, but writing an un- unpacker for specific code 00:19:54.493,00:20:00.666 is much easier. So we have our stage 2. Stage 2 is much more straightforward, it is just a 00:20:00.666,00:20:06.439 simple decoded loop which because now we have loops. We could, we just unpack something. 00:20:06.439,00:20:13.079 So uh stage 2 will unpack the final encoded payloaded and then we run. We have something which 00:20:13.079,00:20:19.952 works. So uh let me just show you a little demo on the only silicon available widener which 00:20:19.952,00:20:24.957 is the HiFive Unleashed board Ok. So we see basically what the shellcode looks like. Uh you can 00:20:31.731,00:20:37.636 see that basically all the hashes that correspond to our install instructions. We start 00:20:37.636,00:20:42.641 with a shell we have a available um network application. We’ll just send it uh send our 00:20:44.977,00:20:49.982 shellcode on the circuit. As you can see we’ve sent it. We now have our shell, we can check 00:20:52.551,00:20:58.290 that we are in the door. And if we check the cpu type it is indeed a RSIC 5 cpu we are on. 00:20:58.290,00:21:03.229 That’s on fo- [applause] >>Well, let’s go a little bit dirtier. Uh so we have seen what uh hash 00:21:12.872,00:21:17.676 can do, so it gives you a standard source. Uh so now we will switch to the other 00:21:17.676,00:21:22.114 character which is to another character which is slash. Uh which can be really useful when 00:21:22.114,00:21:27.119 you’re writing for example ur- URLs or path uh in uh in the Linux uh operating systems. Uh 00:21:29.255,00:21:34.260 uh of course, switching to hash uh to slash instead of sla- of hash, uh does not give us 00:21:36.428,00:21:40.299 standard stores anymore. So we have to find a new wri- memory writing primitive. Uh to 00:21:40.299,00:21:45.304 compensate for it. Of course slash is not taken uh out of nowhere. Uh because this uh 00:21:47.706,00:21:53.312 character gives us atomic operations. Uh so we have two uh many useful atomic operations. 00:21:53.312,00:21:58.817 So the first one, for example, AQ3 slash gives us atomic R and the other is atomic N. 00:21:58.817,00:22:03.756 Fundamentally an atomic R operation reads 64 bits from the memory. Stores it in a register. 00:22:07.092,00:22:13.766 And then stores back to the memory the same uh, value or with another register. So the 00:22:13.766,00:22:18.771 end is exactly the same with the o- end operation instead of R. Of course uh so given that I can 00:22:22.208,00:22:27.646 read and write 64 bits into the memory, so this is a memory writing primitive, so the idea 00:22:27.646,00:22:32.651 is just to uh, to write my stage 2 with those instructions. However in RISC 5 uh there is a 00:22:36.889,00:22:41.527 little constraint for atomic operations which was not there for stores. Uh and its says that 00:22:41.527,00:22:46.999 the address held in the register must be naturally aligned to the size of the upper end. And if 00:22:46.999,00:22:51.737 the address is not naturally aligned a misaligned exter- exception will be generated. So 00:22:51.737,00:22:56.909 that’s fine. It’s si- it’s 8 bytes, I have to align it on 8 bytes so the idea is I have a 00:22:56.909,00:23:02.815 pointer to which I write to. I write my 8 bytes then I increase th- this pointer by 8 and I 00:23:02.815,00:23:08.387 continue writing it. So we have to use some add image 8 instruction that will allow us 00:23:08.387,00:23:13.392 to increase the pointer. So we look at the available instructions. We look for the 00:23:13.392,00:23:18.397 add image 8, then we take the shortest one. And of course the shortest add is of 16. So we are 00:23:21.267,00:23:26.272 f****d now, so we will have to find a way to go out of it. Uh the solution is to use a 16 byte 00:23:29.675,00:23:36.048 chunks because we are obliged to move our pointer for 16 bytes. Out of which only the 8 are 00:23:36.048,00:23:41.787 controllable. So the idea is we will use 6 on the out of them so it’s even better. Uh and we will 00:23:41.787,00:23:45.924 put an instruction at the beginning uh that will be our real instruction of the stage 2, 00:23:45.924,00:23:50.963 then a nop-like operation, then we’ll put a jump instruction that will jump to the next 00:23:50.963,00:23:56.168 block. Uh, here we decided to put 2 bytes and 2 bytes instead of 4 bytes of instruction, 00:23:56.168,00:24:01.106 because it was to easier to build uh the shellcode and just because we are lazy so. So using 00:24:03.242,00:24:08.814 some black magic uh, so I will explain all of this all of it uh step by step. So here is uh the 00:24:08.814,00:24:13.619 example of uh some code that allows you uh to to write exactly one block to load into 00:24:13.619,00:24:18.624 the mirror one block. And uh we will use some gdb over uh dimmer uh to look how what it does 00:24:23.128,00:24:29.134 exactly. So other black magic here, uh we load, uh in initialization section uh magic 00:24:29.134,00:24:34.139 value in the the tp uh register. Which is A031 0 0 0 4. And let’s go step by step to it. So at 00:24:36.608,00:24:41.613 first we would zero s4. Then we would do the atomic end to the uh chunk. Which in practice 00:24:44.616,00:24:50.856 would zero all the ch- uh the first 8 bytes of the chunk which is exactly what we want. Then we 00:24:50.856,00:24:55.828 would do the or with the register that has the magic value so it loads A031 into the 00:24:55.828,00:25:01.967 memory. Which is exactly we want because this is a jump 12 which we jump to the next block. Then 00:25:01.967,00:25:06.972 you load a magic value into a zero. You shift it by 12, you subtract 10 out of it and then 00:25:10.309,00:25:15.314 do again an atomic or to the memory which would lo- load into the the chunk. 97 A zero and 00:25:17.416,00:25:24.189 zero zero zero 5. 97 A zero is exactly at A4 A4 sp which is one of the instructions of the stage 00:25:24.189,00:25:29.194 2 and zero zero zero 5 is the nop operation which is exactly what we want. So the idea behind 00:25:32.531,00:25:37.536 is just you do exactly the same for every instruction of your stage 2. So you had a load of 00:25:39.538,00:25:44.543 you imitate instruction, you shift it by an amount and then you put some add uh image 8 00:25:44.543,00:25:50.983 instructions so a small or bigger uh on 32 bits uh and uh you just brute force on all 00:25:50.983,00:25:55.988 those instruction sequences. So at the end it will allow you to load 1 value into the the the 00:25:58.524,00:26:03.061 chunk. So if you have several inst- instruction sequences that do the same thing, you can do 00:26:03.061,00:26:08.867 shortest one. And if your stage 2 does not fit into the instruction sequences you found. 00:26:08.867,00:26:13.605 So you just modify it, you tweak it a little bit and this will give. So here is exactly the 00:26:13.605,00:26:19.244 stage 2, so sorry I had no place, uh uh for putting uh vertically so, just please turn 00:26:19.244,00:26:25.584 your head 90 degrees. [laughter] Uh so here if we look at it you have exactly uh the 00:26:25.584,00:26:31.957 instructions. Uh ok. So let me put it back uh in the right order. So you have the the body 00:26:31.957,00:26:37.296 of the group. So everybody knows what’s in the body of the roots so let me take it out. Here it 00:26:37.296,00:26:43.402 becomes normal I think. Ok. So let’s get back so you have the jump instructions. You have your 00:26:43.402,00:26:49.208 nop instructions. So you have uh left shirt at the end, which is, which shifts uh a register that 00:26:49.208,00:26:53.779 we do not care about. So it’s a nop like instruction. And you have the real stuff here, which 00:26:53.779,00:26:59.251 is exactly a stage 2. And we had some you have the 2 bytes instructions and there was 1 00:26:59.251,00:27:03.222 instruction that was 4 bytes long which is the fence instruction. Which allows you to 00:27:03.222,00:27:08.994 clear the cache uh if you uh set modifying code. This is absolutely sm shell. Uh and for 00:27:08.994,00:27:13.565 this we just end root to the the instruction sequence and it’s only one instruction so that’s 00:27:13.565,00:27:18.570 fine. So let’s get back to the demo. So here. So. We still have our shellcode here so you can 00:27:25.177,00:27:31.617 see the slash uh characters that tell you that it’s an atomic operation. And we will send it 00:27:31.617,00:27:37.489 to the same application that has another filter now so instead of filtering out all uh, the hash 00:27:37.489,00:27:42.494 characters so it will only keep the slash characters. So we send it. We get our shell. So we do 00:27:44.530,00:27:49.535 ID. This is root. And if we check again the CPU so it’s again RISC 5. [applause] >>Ok, 00:27:53.238,00:27:58.243 so let us look at this nice quote from xkcd; Either your handing out raw floating point 00:28:03.348,00:28:08.320 variables. Sorry. Or you’ve built a database to track individuals atoms. In either 00:28:08.320,00:28:13.125 case please stop. Well, I’m very pleased to tell you that we are not going to build a database to 00:28:13.125,00:28:18.597 track individual atoms. Which means we’re going to have fun with floating points. For last 00:28:18.597,00:28:25.003 character tick, gives us gives us floating point stores and that’s really difficult to work 00:28:25.003,00:28:30.008 with. So as a rem- as a reminder we only want to change your unpacker so other parts of our 00:28:32.477,00:28:38.216 architecture would change. But instead of using regular store or atomic store, we need to 00:28:38.216,00:28:43.221 write our first unpacker with floating point stores. So uh floating 101 for people who need 00:28:46.625,00:28:53.432 it. Uh floating point will put notation in memory uh has refills, Mantissa, Exponent and 00:28:53.432,00:29:00.172 Sign and mathematical representation of this uh binary repr- representation is very 00:29:00.172,00:29:06.945 roughly mantissa times 2 to the power of the exponent. Plus the sign bit. This variable but it’s 00:29:06.945,00:29:13.819 much enough for this presentation. So our idea to write the unpacker is to first 00:29:13.819,00:29:19.257 load certain floating point value from some mem- memory. Since it is from the memory it 00:29:19.257,00:29:25.764 means it is must be alphanumeric then do some computation and hopefully at the end we have a 00:29:25.764,00:29:30.769 chunk of our of our stage 2 en- uh other register we can which we can just store it to memory. 00:29:32.871,00:29:37.876 We do this for each chunk and we have our unpacker. Obviously the issue here is which value do I 00:29:40.646,00:29:45.651 pick and which computation do I do. Well, uh let’s look at what is available on alphanumeric 00:29:48.553,00:29:50.555 RISC 5 and return of floating point operations. So first we have loads and stills. But 00:29:50.555,00:29:52.557 that’s a good thing. And then we have we need to find our operation to work on those 00:29:52.557,00:29:54.559 loaded values. So first we have code to the bulk of operations, but since we won’t have the bulk 00:29:54.559,00:29:56.561 of code it’s like not super useful. Then we have sign manipulation such as for example 00:29:56.561,00:29:58.563 taking the absolute value of a 14 point register, but it will only change a single bit in the 00:29:58.563,00:30:00.565 register, so its not super useful. And finally we do- we do have fused multiply-adds 00:30:00.565,00:30:02.567 instructions which has multiple variants. So uhfuse multiple add is an operation which has four 00:30:02.567,00:30:07.439 inputs and one output and basically it combines a multiply and a add in single instruction. 00:30:07.439,00:30:13.979 So uh it's a times b plus c. And some variants have some minus sign in the middle. So for 00:30:13.979,00:30:18.984 example if we had an instruction. Fmsubb uh ft6, fs4, ft4, fa0 it means that the 00:30:47.512,00:30:52.517 floating point register d6 will be set to the result of h2 times t4 minus a0. So uh here’s how we 00:31:06.531,00:31:12.838 want to start a chunk of stage 2. Let’s say we want to store the 16 bit value ABCD in exact 00:31:12.838,00:31:19.311 decimal. And the height we can see our uh few multiply instruction and we need to set A 00:31:19.311,00:31:24.316 B and C which must all be alphanumeric such that uh, those contains ABCD into N. So first, 00:31:29.054,00:31:34.059 we’ll just take a whole for thing for A. Ok. Why not. Then same thing, we will take a whole 00:31:37.229,00:31:44.102 thing for B. And at this time at this point, we only have a single input left so we can 00:31:44.102,00:31:50.275 mathematically solve for it and in this time if we want R to have ABCD in the logic, it means 00:31:50.275,00:31:55.280 that C is something quite difficult. Besides a non alphanumeric character so 00:31:57.749,00:32:03.088 doesn’t talk. So what we do is that we try again, we take another B again solve 00:32:03.088,00:32:08.593 mathematically on it. This time with other key, C, is alphanumeric. As you can see it 00:32:08.593,00:32:13.598 is bbboqccz6 and this time we have a good result in R. So you you might want to ask how how 00:32:16.234,00:32:22.808 long do I have to try to find good base? Well, not that much. Only 10,000 times. And since 00:32:22.808,00:32:27.813 we’re doing it on the computer, 10,000 twice is like nothing. So it’s like really efficient. And 00:32:31.383,00:32:36.788 I don’t have a proof of its value here, but I can tell you just trust me that it works if I 00:32:36.788,00:32:43.094 change ABCD to anything. It works for all 16 bit values. And even better than that when we 00:32:43.094,00:32:47.833 fo- found our thing we saw that we could actually control much more than 16 bits. As you can 00:32:47.833,00:32:54.573 see, uh in the heights uh, on the left on the just before ABCD we have lots of 0s which means 00:32:54.573,00:32:59.411 we can actually control all those bits. Otherwise we would re-order. So we can actually 00:32:59.411,00:33:04.349 have all 48 bits. Which means that we’ve fe- few- si- uh 364 bits value we get 48 bits of 00:33:08.587,00:33:13.592 output. We- We have quite a good unpacker here so we do it for every part of our stage 2 and 00:33:16.027,00:33:21.032 then again we have an unpacker and otherwise works fine. So again a little demo. So you have 00:33:29.074,00:33:35.747 all this in it, but this time it is with tick. So uh on top you can see the encoded payload, on 00:33:35.747,00:33:41.820 the bottom you can see the unpacker with our text code pointing to floating point 00:33:41.820,00:33:46.825 store. Once again we are sending it to our vulnerable application which this time accepts 00:33:49.828,00:33:56.635 alphanumeric plus tick. We get our one shell as you can see with our root and once again you 00:33:56.635,00:34:01.573 can guess it, this is the same CPU. It is still a RISC 5 CPU. [applause] >>Ok. I hope you did 00:34:10.682,00:34:15.687 not expect that. Um, so with we went through different new techniques to write code. We 00:34:17.923,00:34:22.961 focus on alphanumeric which as you can probably imagine these are tricks that some of them 00:34:22.961,00:34:29.968 weren’t known before. We tried to bring you to navigate to yoga of writing constrained 00:34:29.968,00:34:34.973 shellcode. To avoid filters, to fool IDSs and humans as well. To target specific applications. Um 00:34:38.877,00:34:45.016 as we mentioned the x86 environment is already quite mature, so this is a solved 00:34:45.016,00:34:51.923 problem there almost. But new architectures in particularly RISC 5 is something that’s 00:34:51.923,00:34:58.296 that’s gaining momentum and we need to keep up. It would be an acceptable that it goes public 00:34:58.296,00:35:04.135 before we have attacks for it. Right? So we showed that it is possible to write alphanumeric 00:35:04.135,00:35:09.140 shellcodes uh even on very constrained instruction sets. And what we described to you, 00:35:11.309,00:35:17.482 the unpacker was a hard part really. The decoder was the hard part and now what we remains is 00:35:17.482,00:35:22.487 just to put your payload any payload arbitrary payload, this is a world first by the way. So 00:35:25.924,00:35:30.629 more than tricks and techniques, uh we have introduced new approaches that can be 00:35:30.629,00:35:35.333 transported to other architectures and for those of you who are really curious how 00:35:35.333,00:35:40.338 to use that, um for once, do come to uh our talk next week. Uh the do read the paper that we 00:35:45.310,00:35:49.881 are go- uh that has been published uh yesterday. All the code is open source, you can 00:35:49.881,00:35:56.454 actually find everything there if you’re curious. And you have no excuse whatsoever, so get 00:35:56.454,00:36:01.393 hashing and slashing and ticking for fun. And for profit. Uh read the code, send us uh friendly 00:36:04.629,00:36:09.634 email. Thank you very much. Your friendly neighborhood hackers. [applause]