So my session is called Sneaky PDF. Thanks for your time. So a little bit about myself. My name is Mahmoud Ibrahim, or Yomu, from Myshirt, part of Cybersecurity Malaysia. I'm interested in malicious PDF as well as Android malware reversing. So the agenda for today, I'm going to cover a little bit about intro and then a little bit about obfuscation technique that we found out in the wild that have been used, and of course, a little bit about challenge and issues, and the last one is about conclusion. All right, introduction. So this is not about PDF reader application zero-day, so don't get confused with that. And of course, it's also not about Adobe X Reader sandbox bypass, okay? So this is plainly, we're talking about PDF obfuscation, which is pretty much the same issue. So basically, when you talk about obfuscation, so you have a PDF plus obfuscation, what pretty much you expect to become? Transformer, maybe? Not really, right? Of course, you expect to become a PDF as well, right? So the topic for today is about you have a normal PDF or you have a PDF that we exploit, and then you want to use it for a lot of things. So why do you want to obfuscate it? The main reason of why you want to obfuscate it, well, obviously, there are many reasons for that. Malicious PDF mainly comes with two components. The first one is probably the exploit, and the second one is the payload itself, or shellcode rather. And then, well, the main reason, like I mentioned, is it needs to be off the radar. How? Obviously, you need to look like a normal PDF. You cannot be, you cannot expect to look like a malform, because if you're talking about a normal PDF, you trigger that then you somehow raise a red flag for any security product for detection. Of course, what do you want to obfuscate? It's dependent on what kind of level that you want to go. Normally, people just obfuscate on the exploit, or people want to obfuscate on the shellcode. But the two most, these main components will need to be obfuscated, right? Well, why are you obfuscating this one? Obviously, you want to stay. You want to stop reducing for being detected. And one of the other things is try to make analysis harder. Because eventually, if you were here for the previous presentation about APT, there is always, you know, a wish to believe somehow in the end of the day, your tool is going to be detected, right? But you can make analysis become more harder by implementing some obfuscation. So, statistic of obfuscated malices, PDF. PDF, I don't think statistically somehow look at this way. It's always going up because that is pretty much the trend. So yeah. And then the PDF in general. So I hope the PDF is serious enough nowadays. So this is pretty much the PDF. I tried to cover a little bit about the structures or the concept of PDF. Okay. The first one is you see on the green color box, you're going to have PDF version. And on the PDF version, normally you have something like percent something, percent something. And then you have PDF and then version numbers. One of the components that can be used to, for example, you know, to create a PDF, you need to have full couple of PDF analyzer tool is by play around with the version numbers. So not version numbers by the header or PDF. Like, for example, if you're looking like percent and PDF-1 and what kind of version is it. It needs to be remembered, though, because for the PDF specification, it said within one, zero, two, four bytes, for the first one, zero, two, four bytes, it's a legitimate for you to declare the PDF version. For example, you have, you have some weird numbers, like you can have percent, percent, percent, or you have ABC, ABC, or whatever you want, and then you put percent PDF-1.1, it still can be considered as a PDF, still can be considered as a legitimate PDF version. And then the second body for this one, if you can see over here, is pretty much the main component of PDF. Which is normally have object, normally be representing as an OBJ, and it needs to be end with an OBJ. And later on, I will show some, some rather obfuscation that you can implement when it comes to the object declaration, like this one. And then, of course, it's also part of the major component inside here, is the JavaScript. And you have on the yellow box, you have the cross-reference, which is somehow define the offset of each object. Okay? And then the last one, you have trailer. Trailer is pretty much the main component that have one major component called slash root. Slash root especially give you some clue, or some entry point where your PDF will start, when you open the PDF. Okay? And the last one is also interesting, you have the NOFI, which is representing of, um, NOFI for the PDF. Uh, it declare a percent percent, uh, uh, um, NOFI. But, um, it's also can be, uh, you can also have multiple NOFI. Uh, I will show you a demo later on, on this, uh, specific, uh, uh, topic. So obfuscation. Well, commonly observed in the obfuscation method, uh, pretty much, uh, like I mentioned earlier, you have, uh, JavaScript. And you have a PDF syntax. And, of course, you have, uh, PDF, uh, features. And the last one is probably you have, uh, uh, media reach on PDF. Okay, the first one, uh, abusing of the JavaScript to make your, uh, PDF, uh, undetectable, or, or make your, uh, uh, make your PDF become more difficult to analyze, is, uh... the sky's the limit. Whatever can be executed by JavaScript is pretty much can be rendered as well within the PDF, uh, engine. And majority of, uh, PDF reader application have, uh, JavaScript engine. Uh, you name it, like Adobe have it, uh, Nitro have it, um, you also have, um, Fawcett, and even you have Sumatra PDF as well. Okay, basically it's been, uh, mainly been used for, uh, runtime export setup. Like, uh, you're not gonna, um, uh, you know, put, like, plain text, you know, plain text for your exploit. We need a PDF, so you pretty much, uh, construct during runtime for your exploit to trigger. And then, of course, you're talking about shellcode affisication setup. Uh, normally you generate shellcode on the fly, uh, to make, uh, it, well, to make your, your, your, your PDF, uh, uh, obfuscated, I think. And, of course, uh, majority of the PDF that we saw implementation of the JavaScript is mainly for heap spray. But, uh, recently, if you notice, there is, like, a couple of, uh, deep spray stuff is also, uh, been implemented as well. And, of course, the main reason is, uh, to make analysis, well, one of the main reasons is to try to make analysis harder. Well, how does it look like? Pretty much, if you notice over here, you have Y8, it's a very typical JavaScript operation. You have Y8, Y, uh, B, and then you have Y, C, blah, blah, blah. And then you have, uh, you combine all this, uh, this stuff and you execute it. And then, uh, another typical, uh, JavaScript, uh, function that's been used is argument.cully. And another thing that's normally been used is, uh, ASCII convention. Like, you have, uh, 0x41 is, uh, basically representing 4, uh, A. And, for example, uh, in within the PDF, off you have a dictionary called a slash filter and slash filter is going to retrieve some key value which is a flag decode and instead of representing as a flag decode you can also spelling or using an ASCII convention. For example, you take a look at this sample over here. So it pretty much starts with 50 A-R-E and so on and so forth, okay. And, of course, if we see a usual suspect for encoder like B624 or R-13 and so on and so forth. And normally for JavaScript the certification they tried to make one-liner code because JavaScript always end up the code execution efficient by the semicolon, so the new line really doesn't bother, so normally they try to screw up the code, the formatting of the code by implementing just one line of code. And then sometimes you also have some spaghetti code. If you take a look at the sample here, you pretty much notice this is just a declaration of function, and the last one is probably tried and catch loop, right? But, um, this is pretty much the try loop, but isn't, oh, okay, sorry. Over here. So you should notice, so I can make it bigger. Oops. I don't think you guys can see it, right? Can you guys see it? But somehow over there, over here is kind of the loop that you can see, loop for try and catch, but really this is not the, the education part, because it started earlier, early, early on before that. Like, if you notice here, there is an if-else function, okay? So this is pretty much a very generic, you know, JavaScript affixation. It's not really affixation. It's kind of like spaghetti. You combine multiple things. You combine multiple code and function within, you know, and then sometimes they also come with a half-pyramid sometimes. If you notice here, it's kind of like a running bunch of stuff. So sometimes you can make a pyramid. Probably the guy is boring, so try to make it look like a pyramid. And then dealing with the JavaScript affixation can be annoying. Normally you just pretty much always end up. It's always like, because there are many ways people can fool you with the JavaScript. Like I said previously, JavaScript affixation is involved with creativity. So if the bad guy is much more creative than the analyst, so you always end up like this way, you know, fuck or something, okay? But I believe with the help of tools, you will be probably more relaxed a little bit. So you kind of release, you know, because there is a tool for you to help you to automate or make your analysis more easier. For example, if you're talking about, you know, to run the JavaScript, you need to have some sort of emulator for that. Because you try to trace one, you know, by your bare hand, well, I wish you good luck to manage to go through all the code. And for emulator, you have a SpiderMonkey, Rhino, or even you can try Google V8. And of course, like I mentioned earlier about the code spaghetti stuff, you can use a code beautifier, like a JS beautifier, which is pretty much have been ported to JavaScript. Or to almost IDE or code editor. And you can also implement some sort of JavaScript dynamic instrumentation tool as well to see the application, to see the runtime of a JavaScript, okay? But then, having said so, it's pretty much, if you take a look at the previous sample of the JavaScript, you pretty much can read all this stuff, right? But maybe in the future, it may come to, within this function, this is valid JavaScript implementation, okay? And then, it may also come with the smiley characters for you guys. So this is kind of an application that you can see within the JavaScript implementation in PDF. And there's a second normal application that we saw is about abusing the PDF syntax. For example, if you notice the slash root, you can see the root over here, which as I mentioned earlier on, within the startup of the PDF, normally, it's going to start with the slash root. At the beginning of it, you need to go to root. And this one is specified, the object slash, the starting point of this PDF, always going to refer to the object 21. It will be referred by the object 21. So any education file will start on the object 21. It's no longer about object 1, 0, OBJ. Because the normal thing that we saw, the mistake that we've done, is when you start working with analysis on the PDF, you start by looking at the percent PDF version, and you go with one by one of the PDF component. But really, you need to start from the slash root. And another thing is about referring to another object. For example, you notice the var here, okay? The variable var is pointing to the function called, not a function, it's pointing to object 21. It's pointing to the object 21. It's pointing to the object 21. I'm going to go ahead and call this dot info dot title, which is the kind of OO representation, which is this normally referred to the object itself. I'm sorry, referred to the PDF itself. And dot info is always referred to another component, like for example, this one, slash info. And slash info is a point, it's referring to the object 5, so this is the object 5. And then this is your title. So your variable of root will be this variable. stream. That's pretty much the obfuscation that we saw on the PDF. Okay, I'll talk about the syntax of the percent PDF and NL5, right? And normally, how you start parsing your PDF file? If you're building some PDF tools to analyze a PDF, which one you start with? You're looking at a percent PDF version, or you're looking for NL5? According to the Adobe reference, you somehow should start from the NL5 of the PDF. But the problem is, if you choose to read from NL5, which one is going to be your the first NL5? Because like I mentioned earlier, you can have multiple NL5s within your single file of PDF. For example, this one. If you start from NL5, right? If you're parsing your PDF file using NL5 as a starting point, which NL5 that you want to refer? You want to refer to this one, or you want to refer to this one? Well, this is pretty much legitimate declaration. If you open, it's not a malformed PDF. Your reader, majority of readers, well, I have touched with Nitro, Adobe, touched with Foxit, and even Evinced. They open nicely. There's not even a problem with this. So if you build a parser, which one do you want to choose? And then, for example, if you choose the last one, if you choose the last one, and then how about this? If you choose the last one on the NL5, and take a look at the object 12, if you choose the last one, this one, this one, so in this NL5, you have multiple object declarations for the object 12. For example, you have one, you have two, here. So which one is which data now is representing by the NL5? Sorry, we've been representing by the object 12. Because, for example, the first object 12 now here is half a data that say test first NL5. The second one is test NL5 second NL5. I will show you a demo about this later on. And then another one. Here. Okay. But the truth is, NL5 is not even needed. If there is no NL5, your PDF application reader can somehow manage to render it properly. So the last one of the declaration, for example on this one, if you notice, from this one, the object 12, the last object 12 is always going to be the one that will be picked up by your PDF application. So like I said, this one declaration for object 12, so this, the last object 12, will always be executed. Okay. So this is the one. So the last one will always be used by a PDF reader. So for example, the demo. So the first one, let me open with this. If you open this file, oh crap. It's freaking slow. For example, this one, this is your first NL5. But you can put a bunch of other things as well below of it. Like this is object 12. You end with another NL5. And this is interesting. You have here NL, you have object 12. And inside object 12, you have another NL5. And then this is pretty much another, the data that belongs to object 12. You notice here the second NL5. And you have another, the third one, NL5. So if you open this file, it's always slow when it comes to demo. It's always slow when it comes to demo. So you just open NL5 for the second one. Right? Because the last one is always the one that will be choose by the PDF reader. So this one, I'll open with this one again. This one, it don't even have the NL5. But if you open it with any PDF reader, everything is just fine. For example, this one, below this, that is no longer NL5, but you have object 12 here. And you also have object 12 here. And then if you just open this, you can still get NL5. So very tricky one to find where you can stop. Building the parser is very tricky where you want to find a starting point and try to parse for every single object within the PDF. For example, in future, I believe for the PDF, have something like this. For example, the reference to the object that create loop. For example, you have the object 1 that have the dictionary for auto, which is pointing to object 6 over here. And object 6 auto have also pointing to the object 1. If you open it with any PDF application, it may stop. But if you're building your own parser, when are you going to stop your loop? Right? So that will be interesting to see when we should stop. Okay. Then another thing is about abusing the PDF syntax is relate to the acrobat are specifically designed for the PDF engine, especially for Adobe. A couple of JavaScript functions like get anode, sing anode scan, get page number. For example, get a word. Now for example, get page nth word. This one basically tries to get a word on page specific and get page nth word to 1. It's basically get the third word of page 1, for example. And then you can select based on page as well. So this is pretty much normally being implemented with the on the PDF. For example, this is one of the functions you can see. This one, this get page number and this select page number something. Okay? So it's very, very, it's very difficult. It's not, I would say it's very difficult, but it's very difficult to emulate all of the acrobat JS engine to your own parser. Because this kind of, this kind of JavaScript code is not supported by default for like for public acrobat PDF engine. Sorry, JavaScript engine like SpiderMonkey, V8, it's not been designed for this. Okay? Another thing is, like I mentioned earlier, you can abuse incomplete syntax. For example, like object stream. For example, this is object as 1. We start with a 1, 0, obj. So you're pretty much expecting it need to be n with obj. But then if you don't have an obj, that's no problem. You have a PDF application, we just load it fine. But if you build your own parser, you need to know where to stop. For example, this is stream. You're expecting to have n stream. But if you don't have, it's also fine. And even funnier, you have stream. You have another stream. And you have n stream. You have n stream here. So which stream, which data that belong to this stream for example? This one? Or this one? Or this one? Or this one? Right? It's very tricky to analyze all of it. Okay, so another thing is, like I mentioned, the problem with this is difficult to emulate or to automate within a parser. Something like I mentioned earlier, emulating acroj as code, finding stopping loop, and finding ending tag for like obj and stream. And of course, you need to understand how the PDF3D application parser actually works. But then, are we building another PDF3D application? I think not, right? We are building the parser to analyze the malicious PDF. I put it here, we're implementing, we organized a challenge for 100Net project last year. So a couple of tricks have been implemented over there. If you're interested to see the tricks, just try to, you know, get along with the challenge. And it seems very difficult to automate this analysis, so manual tools are recommended. Manual tools is something like, you don't really, you know, parse the whole thing. You just somehow grab any object and then you just display the object. So you can manually trace the component that belongs to the object. For example, you can follow the PDF flow. You can manually inspect each object or each stream, so you know where it should end. And dealing with the AcroJet, there's still pain in the ass, I think. A couple of tools that you can play around with are PDFStreamDumper, PDFZerminer, PDFDeceptor, and FileInsect. Another thing that you can abuse within the PDF obfuscation is try to abuse the filter. The main category for here is I put PDF features. Obviously, one of the normal features in PDF is filter. Well, the main reason for filter is basically try to compress the size of PDF, so you normally use some encoding to compress it. So if you're using less known filter, for example, CCR, ITF, FaxDecode, and DCTDDecode, there's pretty much a high chance for your analysis PDF not being detected. But somehow, in general, filter is normally you have FlaxDecode, ASCIIHaxDecode, and a couple bunch of ASCII, like ASCII85, JBig2Decode. And this is also interesting as well, because if you see at the filter dictionary, it can accept a couple of parameters. So if you want to make your filter have some strict parameters, so that if you're using like if you're trying to compress without passing this parameter, your decompression will be filled. You can implement it within the parameter called decodePAM. For example, this one, this code implements CCR, ITF, FaxDecode. It's normally for image, but really it doesn't really matter. It's not necessarily image. You can put whatever you want, as long as it's within the format of the CCR, ITF, FaxDecode. And then you can also abuse the filter by implementing some multiple layer of filter. For example, you have combining of ASCII85 decode and with the LZWD decode. So you just combine between it. Well, there is no limit for you to play around with it. So you can add a multiple filter. And this one, for example, this one implements FlaxDecode and going to do ASCIIHacksDecode later on. And you can also do some abbreviation, especially on this one, like 85 belongs to ASCII85 decode, LZW belongs to this one, LZWD decode. So this kind of abbreviation somehow, if you don't put it within your parser, it will be difficult for you to decompress all these filters. And another interesting part of this, try to abuse encrypt. Encrypt is something that when you have PDF, secretive PDF, you normally try to put a password protected on this PDF, right? And if you put that on your PDF, so pretty much your stream and your string are going to be encrypted. So in Adobe, they're implementing RC4 and AES algorithm. So for example, on this one, this is not, when I mentioned about encrypt, this is not really about protecting the document itself. It's rather protecting the stream. So for example, slash root have dictionary encrypt. So it will point to the object 76 over here. So if you took the object 76 here, it has declaration, it's going to be encrypt with the AES encryption. And then... Okay. So with this one, if you ask like a password or something, like normally when you open PDF, we trigger like password for that. Well, we have a sample like, if depending on the slash root where it starts, you have while you're busy keeping the password, it already can drop some exploit that triggered the exploitation already. So... And then of course it's somehow, it depends on the event, like auth event. Like for example, you have .open, so it will trigger when you open the PDF. Okay? So but then if your slash root have a point in that point to different object that have exploit on it, so it will trigger that first. And then we ask the action from these event. Well, it's pretty much difficult to analyze it, because simply the fact that you can down the stream, because you need to break the encryption out of it, right? So there is no plain text. So for example, a demo. A quick one. All right, for example, I try to open this with a file inside first, to show that this file is, that have encryption. Like I mentioned, please go to your slash root first. A flash root normally have within the trailer. So here you have like definition for encrypt, which is points to the object 29. But your slash root here have the object pointed to object 10 first. Okay? And then this encrypt have pointing to object 29, I think. 29. So if you go to the object 29, so this is pretty much the implementation of RC algorithm for the encryption. Okay? So we have some like stream over here. For example, take a look here. This stream have implementing some sort of flag decode filter. So pretty much you try to decode this one using exactly encoding it should work. For example, you select this one. So you just select and then you right click and then you can, so you can go to decode and try to inflate. Of course you cannot do inflate, right? Because it's already been encrypted. And then if you run this using a PDF application, the exploit might trigger. But then, yeah, you couldn't find what kind of exploit I used for this one. All right? It will take a while for exploit to work because I'm running some sort of heap spray on top of it. So it will take a while. I think we go to this screen after a couple of slides. All right? The fourth one that we normally see within the PDF application is try to use media reach on the PDF. Because the fact that they have many media types that they support, so pretty much you can embed a couple of media, for example, AIF, .mp3, and even now that SWF. So if you attach any exploit within the PDF file against this media player, well, you normally win. Because people are not really suspicious to click on PDF rather than clicking on their .mp3 and .mov that come over your email or something. Okay? And normally, for the PDF, it's used against the Flash today. So you have normal PDF, good-looking PDF. It's not malformed. But you have bugs on Adobe and on the Flash get owned as well. How does it look like within your PDF structures? For example, you start with a slash root again. You check slash root is pointing to object 31. And then object 31 have the page pointed to page object 1. So you go to the object 1 here, and then you have page. And page somehow have a reference on the object 12. You go to the object 12, and object 12 is somehow have a Flash flash file on top of it. Okay? So you see, SWF is basically CWF is basically compressed file. And then this is another one called FWS is uncompressed file. PDF is just pretty much the main transporter for this one. You need to extract the Flash file to check what is the exploit, what kind of shell code inside it. Okay? So tools normally you can use, like PDF stream helper, and plus the PDF examiner for this one. And then of course you can do a Flash analysis later on to trace what's really happened when you opened the PDF. As we know, the PDF have engine for the Flash, right? So for the Flash analysis, pretty much very ideal for us to decompiling Flash by code, which is normally tried to from the AS3 or AS2 to AS2 or AS3 code. Idea, but so far I saw it's only two software that do a proper decompiling on this one, but it's a commercial, so you can somehow integrate this kind of tool within your parser. So think Flash decompiler have decompiler for this one, and if you look for the PDF stream damper, they have another proprietary tool as well called AS3 software on this one. So this is pretty much what the decompiling code looks like on the AS3. It's pretty much AS3 code here. And if you cannot do decompiling, you can always do some bytecode analysis here. So for example, this one is pretty much try to construct the knob slack for the shellcode. You can see over here that's some stuff, push integer, and this is couple of loop over here to assign the array. And this is another pushing some ROP gadget on top of the shellcode. And then pretty much here, you can also put some shellcode and try to translate it and try to do encrypt it, so when it comes within the PDF, you just have a properly encrypted, not say encrypted, properly obfuscated Flash file within your normal PDF. Let's see for this one. I think this is pretty much when you open the PDF, the demo just shows that when you open the PDF, it just gives you a calculator. And then it cracks, but then again, we don't even know what is the exploit used for this one. Alright, so this is pretty much you know, this is not the main focus of this presentation. I just show here basically how you can do analysis on the Flash exploit that embedded within the PDF. Okay? And then so this is a challenge and an issue. I would like to share with you guys and hope there is a proper answer for a couple of these challenges. I would say building a complete PDF process is a task. It's a very tough task. Having lexical analysis is one thing, but not so standard or processing object is another. Okay? And embedded components also need attention, like font. How many exploits that are leveraged on font that have been used? Recently, you know on iOS, Jill break me tweet is also starting from the font as well, right? And of course, media, Flash, audio and stuff is also main problem as well now to address within a PDF processor or PDF analyzer. And of course try to fully compatible JavaScript to emulate this is very painful, especially that has specific on Acro.js function. And inspection of the whole part of potential execution within a PDF reader application contact is hard. For example, if you try to analyze outside of contact of PDF reader contact, it would be difficult to find out the floor of it. For example, you have app version viewer version 9, it will have a different execution. So you need to mimic all this environment within your analyzer. And well, even though they have a challenge and issue, I think a lot of effort have been done to translate within the tools, like you have PDFMiner, you have Origami that can be used within the library on Ruby. And of course, you have famous DDS7 stuff and then PDF stream damper, PDF sector, which is a commercial, I think, that one. And PowerVue. Yeah, even and then there's also a couple of our online PDF analyzers as well. The one that we built is called Gallus. And then I think the Web Power at Fame, JS unpack, and PDF examiner. And the last one is also built by our friend, our previous presenter about PDF analyzer called APTU-Diesel. So still, all these applications that have been built, it's not a fully 100% compatible with how the PDF reader application works. So it's very tricky. And then, conclusion that I can draw from my presentation for today is many application method to hide a malice PDF, like you can do over JavaScript, you can do a PDF syntax, you can abuse some features. And for the features, it also leads to many problems on this one. Like you have slash encoder, which gives you some sort of independent to do some encoding. And you also have something like slash launch to launch whatever command that you want. Well, it's nice, it's convenient, but it also can lead to a different problem as well. And you also have like slash encrypt, which I just showed you in the demo. And again, encryption is a major stumbling block. Good to protect your secret data. And then it's also so dust for the zero-day encryption as well. You can protect a zero-day within this encrypt function. A more complex technique on exploitation, we make analysis more difficult, I think. For example, command PDF from iOS to lead to the kernel exploitation. Of course, kernel is a bug as well on this, right? And of course, I don't know, big malice PDF embedded file scanner or detector engine within the reader application itself is a good idea. Because I believe it would be good because you have contacts within the PDF reader. But for some reason, I think it's also a bad idea if you add another engine on top of it, you add a complexity of code base, which is also meant to do bugs within the engine itself. It would be embarrassed to have the code to do a scanner for malicious stuff. It's also vulnerable for the bugs. Alright? So pretty much that's the conclusion. And if you're interested in this PDF weirdness, you can read all these PDF references from Adobe. This one. And of course, you can also read, well, they have a different reference on both of these. This one is specifically for JavaScript scripting engine. So you can read on this as well. And of course, a couple of researchers have been working on this, like Sebastian Foss has been working on this. And also Julia has also been working on this as well. And then thanks for all these people that have been working on this, I feel. And then I think that is all from my presentation for today.