Hello. Can you all hear me okay? All right. So this talk is going to be about information hiding and binaries. My name is Rakan. Some people choose to remember me as Rakan. It's going to be a pretty exciting talk. Lots of cool things I've been working on, on steganography. Basically, there's a big thing I want to warn you all about. There's a big difference between steganography and stenography. So many people come up to me and go, hey, you know this stenography thing you're working on? It's really cool. Can you tell me all about it? Well, just for illustration, that's stenography. All right. So we're just going to talk about information hiding in general to begin with. And then little by little, I'll delve into theoretical details and then the practical implementation of things and what can all of this be used for. There are five general types of information hiding. A lot of you know steganography. And I've seen it before. And there are lots of applications that do that. But steganography is just one of them. There's covert channels communications, anonymous communications. And a big one is copyright marking, which is mostly seen as watermarking. Now, all of these five different classifications of information hiding are really, we're only really looking at three different criterias. One of them is data rates. The other one is stealth. And the third one is resilience to attacks. And these five different kinds of information hiding have differing requirements for each one of those. Steganography is when you're trying to hide a message, but you don't necessarily care about the data rates. But what you do care about is the fact that it's stealthy, that nobody can know, a third-party eavesdropper cannot know that you're, that there's any communication going on at all. And that's one of the things that we're trying to do. But at the same time, it doesn't necessarily have to be resilient. If it is, great. Otherwise, it's not a big deal. Covert channels, it's kind of a breed apart where you're basically using channels that were not designed nor intended to provide any information at all, such as maybe the timing of TCP packets or TCP IP sequence numbers or what error message is displayed and things like that. Anonymity is when you're trying to hide, not necessarily the message itself, but the endpoints of the communication. So I could literally post something on a Usenet group for everybody to see. But if nobody knows that I posted it and who the destination is, then that's also a form of information hiding. Now, copyright marking, that's a big one. I'm going to be spending a lot of time talking about watermarks and how they're defeated. Just because most of the information hiding research is done for watermarking purposes, you have robust marks and fragile marks. The only difference is that it's a different application. Robust marks are meant to be as resilient as possible to attacks, whereas fragile marks, as soon as you touch the medium whatsoever, the mark, the hidden information in it breaks. So this is useful in the case where you're, say, in a court and you have a digital image and you're trying to use that as an evidence for something. If there is a fragile mark hidden in it, then if there's any alteration whatsoever in the image, the mark would have been broken, so you can prove that this image has not been tampered with. Now robust mark, you all know watermarking, where you try to hide something so that later on somebody can say, this medium belongs to me because, look at the watermark that's hidden in it, and it's not tampered with. It's in there. And you can set up the objects, and you can talk to them, and say, this is what they like. And you can prove that there's a particular mark hidden in this image it. Fingerprinting is similar, but it's, instead of embedding something like copyright recording industry, you'd embed copyright Joe Schmo, sorry, this file was sent to Joe Schmo and when I send it to Joe Schmo, if I ever find it on Kazaa or Napster or whatever, then I would know, okay, Joe Schmo leaked this file and good luck to Joe Schmo. So historically, basically, there's been three general ways of doing information hiding. Security service security is a big one. Mainly, way back in Caesar's days, they used to use these kinds of techniques where, because nobody would know how you would engage the code information, then nobody but the recipient would find out what your message was, but it's also used nowadays in the sense that sometimes it's almost impossible to have a hundred, it's impossible to have a hundred percent foolproof system where nobody can detect or break your system and get your message out. So today, instead, what people do is they use... do is that they try to make the system as difficult as possible to break, even though they know that eventually it will be broken. And they use obscurity techniques. So they'll just try to make, like, a reverse engineer's life very difficult. And an example is if you release a video game and you don't want people to reverse engineer the serial number generation method, you just make it so difficult to do that it will take a reverse engineer six months to break. And within six months, you know, you would have sold all the copies of the game that you would normally have sold anyway. So it wouldn't matter anymore if the code was broken six months later. Camouflage is another class of techniques where you're hiding in plain sight, but you do things to fool the human. human perceptual system, so you would either put very, very tiny dots in places where the human eye wouldn't see it, or little holes right next to a character, and because the character is black and the paper is white, your eye doesn't see it, or you could even use invisible ink and stuff like that. Another thing is you could have the data hidden in a very particular location of the medium, and you would hope that your attacker wouldn't know where to look to find that data. This is easy to break, though, because all an attacker needs to do is modify your medium as much as possible while keeping the original meaning of the medium, and they could destroy your data that way. So what people have been doing more recently is spread the hidden information all over the medium. And what that means is that they would... One way is to... One way is to have the message repeated several places all over your medium, and if one place is broken, then it's okay because you have several other copies and you can reconstruct the original that way. Now I touched upon this before, these three general criteria that are used to evaluate any information-hiding system, data rate, how much data you can store, stealth, how obvious is it that you've hidden anything, and resilience, where he tries to modify your medium and extract, and basically break the message that you have in it, how easy is it for him to do so. There are three classes of attacks. One of them is subtractive, which means that you take a medium, which I represent here as that rectangle, and I use W as watermark because usually a lot of these attacks are against watermarks. And basically the idea is to try to take the W... W out of the rectangle. So we'll have our friend here, Joe Hacker, who comes along with his friendly chainsaw, attacks our medium, and extracts the watermark out. Now in general, this is a pretty hard attack to do because it would mean that your information-hiding system is so broken that the attacker could know exactly where the watermark is located and exactly what... What to do to take it out without destroying the medium in such a way that it's not useful anymore. So if you have a huge copyright movie industry smack in the middle of the screen when you're watching a movie, an attacker could crop that whole section of the screen out and he would have effectively gotten rid of the watermark. But the problem is that the resulting medium is just useless now. And so it's not a successful attack. A distortive attack is another form of... Is another kind of attack where the attacker doesn't necessarily know where in the medium the watermark has resided, but he'll do a lot of different things that basically messes around with the medium just enough so that it's still useful when he's done messing around with it. But the watermark is modified in such a way that it's not recognizable anymore. By whoever put the watermark in. So an example is... Well, illustrations, guy jumps up and down on the thing and then you get a W prime, which is our new watermark. An example would be if you have a JPEG with a watermark in it and you scaled it a little bit, sheared it a little bit, maybe twist some points in the image just enough so that the human eye can see it. You may not notice the difference between the original JPEG and the new one, but a machine looking for a set sequence of colors or however they implemented their system wouldn't recognize it anymore. Now an additive attack is where you don't do any of these things. Instead, you try to make as if you are putting your own watermark into the medium. And the end result is that you have a medium which... There are two watermarks in it. If you're lucky, you can actually override the first watermark. If not, then you have these two watermarks that are side by side. And if you end up in court, you can be like, hey, how can you prove that my watermark wasn't there before yours and this medium actually belongs to me? So information hiding has been done in so many different mediums, sound, image, all of this. Text, you've probably seen a lot of text steganography, there's this spam, I think it's called spam mimic. Some of you have probably heard of it. You enter your message and it generates a spam, like Nigerian 419. And in it, there's your message hidden. And if somebody just uses the same technique, they can retrieve it. But to everybody else, this just looks like a 419 scam. Okay. Now, this was information hiding in general. And now I will talk more about binary information hiding and why is it different and what makes it an interesting problem to solve. So it's a low redundancy medium. What that means is that there's very few different ways to express the same message. Now, I haven't spoken about redundancy yet, but the idea is that in order to hide any information in the medium without it being detected, you have to have the resulting medium look very similar to the original, so that a human cannot look at it and say, hey, what's wrong with this new medium? Why does it look so bizarre? And the way you do that is that if there are several different ways to express the same thing, at least to the human perception, then you can fool people. So if your medium... If your medium is redundant, then you can hide information in it. An example is the English language. There are so many different ways to say the same thing that if you choose to say things one way rather than the other, you could be encoding information. Any of you know the Monty Python dead parrot sketch? Yeah. Anyways, the guy walks into the pet store, he's like, hey, my parrot's dead, and they start talking about it. And they get into this big argument. And the guy goes, really fed up, trying to explain to the salesman that the parrot really is dead. And he says the parrot is dead in about, I don't know, 15 different ways. This parrot is dead. This parrot is no more. This parrot has ceased to be. This parrot has run off its mortal coil and joined the choir invisible, and my favorite, this is an ex-parrot. So basically, if you chose one of these dead parrots... If you chose one of these dead parrots to convey your message, this parrot is dead, you could convene ahead of time that, okay, if I say the parrot is dead, what I mean is meet me at noon over there. If I say this parrot is no more, meet me at 1 over there, and so on. So that's what I mean by redundancy. The more redundancy you have in your medium, the more different ways you can express your message, and the more, the easier it is for you to hide information to it. Now, binaries have notoriously low redundancy in them because they were designed for me. From the onset, to be efficient, your instruction set in your CPU instruction set has to be as small as possible so that your CPU is as not complicated as possible, and it costs money and time and all of that. So how do you do it when you have a medium that's specifically been designed to be non-redundant as possible? I'll go over this, and there are two classes of techniques you can use to hide information in binaries. One of them is called static mark, the other dynamic, I'll go over them right now. Static data mark is when basically you have pieces of data in your code that you can use to later identify your mark, meaning you have an array with data such as copyright, I don't know, recording industry, and so on, and then later on you run strings on your binary and you find that. That string. You're like, aha, you see? My data mark was hidden in it. There are many ways to do it. One way is like this. Another way is you can actually have codes that have, I don't know, anyway, a bunch of different ways. You don't have to use strings either. You can use anything you want, but the idea, meaning that it's a piece of data that's just sitting there in your binary waiting to be found in a very specific location. A code mark is similar. It's similar, except that you're not playing with data anymore, but code, so instead what you'd have is you'd have pieces of code ordered in a certain way in your executable. The original would be the thing on the left, and then you just change it a little bit, and then if you see the thing on the right anywhere, then you know, okay, this really is my piece of code. This is another more sophisticated example of static code marks, which is you have a bunch of go-to statements that do nothing but go to themselves. Depending on the ordering, does A go to B or C or D, and does B go to whichever one, you can have a pretty long list of go-to statements that uniquely identify your code. It has to be my code. Nowhere else in the world would I have such a sequence of code. Go-to statements, as it says, easy to break and easy to implement. The thing is, it's static. It's just sitting there waiting to be found. So if it's sitting there waiting to be found, then all it takes for an attacker is to know where it is and then mess with it. So this used to be used a long time ago and everything, but now it's not valid anymore. Instead, what's more difficult is... It's what we call dynamic marks. So a program is running. You give it a set of inputs. So you could be clicking on it. You could be typing something and say if it's a browser, you can type something and it's in the URL or whatever. And depending how your program reacts to this input, at some point you can stop it and then that's the state in which it's in would be the mark itself. I'll give you examples. Right now, data structure, mark, execution, Easter eggs. You all know Easter eggs. You type about Mozilla and you get this stuff. So the idea being that if you write a program that looks for this input about Mozilla and then displays this text when you do type that input, then you know... And say you're looking at some other web browser somewhere else like five years down the line and you type about Mozilla and you get the exact same thing. Like, wait, this is a little bit suspicious. Why is it reacting the same way? This is the Easter egg information hiding, yeah. Dynamic data structure, same general idea where you take a bunch of input except that you do a whole bunch of operations on that input. And those operations can be part of your normal execution flow. So if you're looking at... At a web browser, it could be... One input could be the URL and then you XOR it with some random variable in memory. Like here you have four variables. You just do some computations with it. You intermingle it with a lot of other normal code and just keep going on that way until your last piece of input has been fed in. And at that point, some of those variables will have a certain content in them. And if that content is what you expect it to... So here, the ASCII, the great Mahir, then you know that, okay, this is my program and this is my watermark. This is another form of dynamic watermarking where it's a data structure. This data structure is a linked list and you basically have two pointers in them. One pointer that points to one of the other elements in the list and the second pointer just simply points to the next element. Okay. In the list. And depending on how you order your pointers, you can encode certain data. So in this case, we have four, sorry, we have five linked list elements. And with that, I mean, it's just a formula that you use. The first element all the way on the left is five to the power of four just because there are five elements and then four for the zero-based counting. And then the first pointer on the left, if it pointed to null, then it would be zero times five to the four. If it points to itself, then it's one times five to the four. If it points to the next item, then it's two times five to the four and so on. And you can encode a number that way. Now the advantage of doing this is that if you choose two large prime numbers, P and Q, multiply them together, you get this other huge number. Now, if you encode this huge number, N, into your data structure, later on, if you're trying to prove that indeed this is your code, what you can do is say, look, I've extracted N from this data structure and I know how to factor N. Now, factorizing a lot too, the product of two large prime numbers is extremely difficult. So if you can do that, it proves that, yes, you were the original. You were the originator of the code. So in this case, seven times 191 equals 1337. Now, dynamic execution trace is you get a set of inputs and you just look at the way your program executes. You don't necessarily look at what data gets produced or any output or anything. Instead what you look at is, for example, the addresses. Instead the program goes through while it's executing. Or maybe even this falls in the sequence of thereof. You can use that to uniquely identify your program. Now, there are a whole bunch of attacks on all of these things. They're just more difficult to implement. One of them is what we call semantics for preserving transformation, which just means that you have a piece of code on the left, which is just assigning three variables, and you change it to something that's functionally equivalent. So, for example, I can actually put in a two-dimensional expression, which is equivalent, but it's just unrecognizable. If you were to try to recognize the code on the right automatically, you'd be like, no, it doesn't look anything like the first piece of code, but in fact, functionally, it's the same thing. To the linked list that I told you about before, you can add a whole bunch of different pointers, confusing the recognizing program. Just in general, add levels of indirection. All right. it's supposed to work in a certain way, you know, maybe add more function calls, more system calls, just change just the general way it works while keeping the functional equivalency. Now, this is all great and everything, but the problem is that I just said things like, yeah, so you add a pointer here, or you add function calls, and you do stuff like that. But the thing is that, how do you do that if you do not have access to the source code? And this is the main difference between bytecode and things like assembly code, where bytecode can be disassembled one-to-one, meaning you can pretty much get the original, quote-unquote, source code when you disassemble Java bytecode, but you cannot do that with assembly code. And the reason is there is no difference between data and code, so you could never know if something was a number or if something was an instruction that you're supposed to execute. So there are disassemblers, of course, but they're not perfect. You can simply not disassemble something and then reassemble it and expect it to work. No way, it won't work. Disassembly is never perfect. In fact, perfect disassembly is what we call an intractable problem, meaning it's just impossible. So as a result, we cannot use the advanced techniques that I talked about for attacking dynamic watermarks. And it's really difficult to even have dynamic watermarks in code to begin with, because unless you have the original source code, there's nothing you can do. You cannot just add that graph, that linked list I told you about, you can't just add it in the middle of the code and get it to cooperate nicely with everything else that's around it. So as a result, very little work has been done. Most of the work that's been done has been on source code and not machine code. So what's something that hides information, information in a loose sense, into binaries? Viruses. Viruses come in and they hide their own code, and they try to make it very difficult for an antivirus to detect. So this is something interesting to look into if we want to hide information into it. So the way it usually works, you have your program, there's an entry point, which is where the program starts, and the program just runs from there. What a virus would do is it puts a payload at the end of the program and then hijacks the entry point. And when it's done executing its own code, it goes back to the original entry point and just keeps on executing there as if nothing had happened. This is the basic first virus, whatever. Now that's very easy to detect because what antiviruses do is they just look for this kind of behavior and detect it. So instead, oh, sorry, the payload basically would be fixed originally. So what an antivirus would do is just basically go through the payload, grab for that code sequence, and it would know, okay, if I find this piece of code, then it's obviously a virus, and flag it, and that's it. So what people started doing was use encryption, where they would have this, a few statements that would decrypt the code that they would actually then run. Now, and every time a virus infects a new host, they would change the key that would be used to encrypt and decrypt. So you would have every single, at every single new host, you'd have a different code block at the end of your program. So the virus body would be changing. But this fixed routine would remain the same. You know, it needs to decrypt. So what antivirus people started doing was simply triggering on that decryption routine. If they ever see that decryption routine in your code, then they're like, okay, there's a virus in there. So what people started doing was, we call it polymorphism, or polymorphic virus, which is simply you keep that idea of encrypting your virus body, but change the way, change the decoding of your decryption routine. And yeah, so there are different ways you can write the same piece of code. So every time you infect a new host, you just write a new version of your decryption routine. Now that made antivirus, antivirus makers' lives a little difficult for a little while. But then they realized that all they needed to do was to wait for the virus to decrypt its code. And because at some point it has to decrypt it and then run it. So if ever it finds, the antivirus finds this decrypted code in memory, then they flag the virus. So that's what's been happening. Now, as a response to that, what people have been doing is called metamorphic viruses. And in this case, there simply is no decryptor. Some people use encryption with it, but the basic idea is it doesn't necessarily even have to have one. And instead, it simply uses different ways of writing codes. And every time it spreads itself to new hosts, it will just rewrite its own code in a different way. And so when it's loaded in memory, it looks different every single time, even though it's the same code. That's much more difficult to detect. So a trick that metamorphic viruses use, I'm going to talk about metamorphic viruses because it's on the basis of that information hiding that I've chosen to implement information hiding. Register swapping is simply... How many of you know a little bit about assembly? Okay, all right. I thought, all right. Good. So basically, you have assembly statements and you use different registers. But there's no rhyme or reason necessarily as to which registers you use in your code. You could use EAX or EBX or ECX, anything you want, as long as you're not clobbering any registers that you've used previously, you're good to go. So in this code example, on the left, you'd be using ESI, EAX, and ECX, and EBX. No? Yeah. And basically, you would just swap the registers around. And the result is that your resulting code still behaves the same way. You're still doing the same thing, except that it looks different now. The portions in red, basically almost half of the code looks different. So if an antivirus were to simply grep for... for a code sequence, it would never find this, even though this is functionally equivalent. Now, there are very, very many tricks. That was just a simple one. Instruction substitution means that you take several instructions that have this... the same meaning, and you swap them. And depending which one you use, it just looks different, but it acts the same way. You can have data that's... that you use in your code, but then it's not really doing anything. So instead, what you do is you just change it, you change the data to a different value, and your code looks different because it just has different data in it now, but you're not actually using it, or if you are, you compensate for the change elsewhere, things like that. You can add nops in the middle of your code, garbage, random things that do nothing, and so on. Basically, you're just trying to change your code as much as... changing the looks of your code as much as possible, but, in fact, the functionality remains the same. But, in fact, the functionality remains the same. So, Hydren uses instruction substitution that I'll detail now to encode data, and I'll go for a demo. Hopefully it'll work. Alright. So... Hang on. Alright, so, the way Hydren works is that, basically, you just... you supply it a binary, so I can do, like, bin ls, and then you supply it a message file. Message. And then you just give it an output file, so it could be ls.stegged. Password? Foo. Alright, so embedded, you know, it embedded 192 bytes it could have embedded up to 362. Now, let's just execute ls.stegged. Looks the same. You know, you can do whatever you want. For all practical purposes, it's still ls. Now, let me see what message I hid in there. So I do hide and decode. ls.stegged. Password? Foo. Bang. Now... Xavier is my handle, by the way. You can see the original bin ls and ls.stegged exactly the same size. But the new one now just has some extra information in it. Alright. Let's try that demo. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . simply compares two registers. If you're only looking at the same register, if you test EAX with itself, which is often done to test for if it's zero or not, you can equally do, you can OR it with itself, and there are two different ways of doing OR. I'll explain this a little bit later. Or you can AND it with itself. There are also two different ways to AND it, but just to keep it simple, I've kept this to four. With four instructions, you can embed, with four instructions, you can embed two bits of data. In this case, I've chosen test is zero, OR is zero one, and so on. Anyways, this is just an example. I have a listing on the left, and the data I want to encode is zero, one, zero, zero. I hit an add. I want to embed a zero. I already have an add, which is zero, so I just leave it as is. Or, same thing, I can embed two bits and I just flip it around and so on. It's pretty simple. There are a bunch of stuff that I do in HIDEN to make it a bit more secure, because the idea is that you would want to have your information... I mean, it's steganography. We're doing information hiding, but I would ideally like to do steganography, which means that it has to be stealthy. Now, I don't want somebody to simply look at the text, at the resulting binary, and be like, oh, this looks really suspicious, and what's going on. ASCII text... If you embed straight ASCII text, it's very suspicious, because every most significant bit in ASCII is zero or one. I forgot which one. What would happen is that you would end up having this repeating sequence. Every eight bits, you have one, one, one. That just looks really weird. Instead, what we do is we encrypt it, encrypt everything. The resulting... The stuff that you embed is actually... Looks like garbage. Now, there's another thing I do to prevent people from seeing what's going on, is what I call random walk. Now, if you simply went through the listing, as I said before, and embedded sequentially, you know, at every other instruction that you saw, and your message doesn't fill the whole size of the binary, then you'd end up with a whole clump of data at the top of the binary, and nothing afterwards. So that would look suspicious from the point of view of an attacker. So instead, you have a random walk, which is you seed a random number generator with, say, your password, and then you just call the random number generator every time, and it just gives you back a number, another number. And you use that number to jump around the binary and embed your stuff. So this is the binary with all the, like... Code locations. Now, the blue blobs are where you can actually embed things. So you pick one, and then you just jump a random number, and then just keep jumping a random number, and just keep going until you fill everything up. When the person... When somebody receives your message, what they would do is they would feed the same input to the random number generator, which is the password. And by doing that, they could retrieve the same exact sequence of random numbers that have been output for you. Now, sometimes some of the instructions that I use are not equivalent in edge cases. So addition and subtraction, you'd assume, are the same, you know, most of the time. But sometimes they're not. An example is if you add negative one to, say, EAX, the result is negative one. But the... The... The flags are set, the overflow flag is zero, and the carry flag is zero. But if you do... If you subtract one instead to EAX, then your carry flag is set differently. So what I do is I scan ahead. Like, if I see an addition or a subtraction, and I want to change it, I scan ahead to see what other instructions there are in front of it. And if one of the instructions ahead of it is an instruction that changes the carry flag anyway, it clobbers it. And in between the addition and that clobbering instruction, there are no instructions that check for this carry flag. Then we're good, we can use... We can do whatever we want with a carry flag, it never gets checked. Other instructions have similar behaviors and, you know... Yeah, what do we do if we have seven instructions? I showed you the example where we have two instructions, four instructions, but if we have eight instructions, we can embed them in the other instructions. three bits of information. But if we have only seven, what are we going to do? We could just waste three of them and then only use four of them for embedding. But that would be a waste. So instead what I do is I use one of the instructions as a wild card, Joker. And if there is no instruction that can be embedded with it, sorry, I try to embed, say, with seven instructions, I try to embed three bits as much as I can. But if I cannot, then I use one of the instructions as a Joker value, meaning this instruction encodes no data, skip, move forward. The result of that, we can embed log two of n minus one bits of information for when n is not a power of two. So the example with seven instructions is that you can embed log two of six bits of information, which is 2.58 bits. Whereas normally, we would only have done with two bits. So it's an improvement. Now, instructions are not created equal, meaning that it is possible to detect addition and subtraction in all these instruction substitutions that I do, simply because the compilers produce code in a certain way, and at the end of the day, you can see that difference when you're using hidden. An example is negative subtractions. Compilers rarely do. Sub EAX negative five. For some reason, they just never do that. Instead, they would do add EAX five. And what hidden does is that it creates very many of those negative subtractions. So if you were to just look for an inordinate number of negative subtractions, you would know, all right, something is very weird in this code. It's also low bandwidth, meaning outguess, which embeds into JPEGs, and that's one bit of information for everything. 17 bits of image, whereas hidden.