Before they're due, here are the speakers on APT. Hi. It's something called wrong because of the shot, right? Okay. I'm Sergio Dos Santos. I come from Spain, head of security and lab in 11 Path, which is the Telefonica cyber security unit. And I'm Sheila, and I work as security researcher as well in 11 Path. I'm 23 years old, and I came from Argentina. Thank you. Well, let's start. In the world of threat intelligence, determining the attacker's geographical location is one of the most valuable data for attribution techniques. However, in some cases, tracking a malware developer can turn into a pretty difficult thing, and the researcher starts getting mad and even feels a little bit frustrated. That's why we are always paying attention to new techniques that might help to track malware developers and reach the potential of a malware campaign. In this presentation, we'll focus on Android. First, we're going to talk about the application that has un频 online. So we'll focus mainly on using junto Add tuo had tornado download. But before anybody is excited about the action, let's talk about two new techniques that we found to track Android my very developers. My head in the my getting the dar a few off them. Their first thing is has to do with a bug inside the Android SDK surely in the back thread. These bugs the types of disclosure of the computer where developed have compiled may were. And the second technique is related to an at calculation of creation times between an active elite type studio API. So what you've seen throughout the certificate of the APK and some files inside it. So at our talk we'll get deep into these two new techniques and finally we'll talk about how we can do an accurate from the time zone that we got to a specific country. So let us start talking about the Android back. When we download the Android SDK it comes with a tool named APT. We can find this tool inside the SDK folder and the build tools API version. If we run APT we can observe in the first line that this is the Android asset vacation tool. So we can use this program from command line to add some files. However, when we use APT for add some files to an APK, that file see the information about other scene related to APK ketchup because management. Due to the standard, every Allibles had its own 시간이 Derivativa classified. I would However, while we use API keep or add in more files get something got so ashamed in these themes could be of the not such a good idea. However when we use A.P.T. for adding some files to an APK, we note that the Instead, the right date and time information, we usually saw something like 01.01.80, an hour, and 00. That three in the hour field caught our attention because if we change the time zone of the computer to, for example, gmt plus eight, that three turn into an eight. And if we change the time zone to gmt plus four, the hour was four. So, what the hell is happening here? Is this a kind of gmt offset? Well, after we noticed that, we started to analyze the source code of AAPT. It is published on Google Git, and inside the path of AAPT, there are several files that compose the source code of this program. So, we put our attention in those files related to zipping process. Inside the zip file dot C++. There is a method named addCommon that is invoked for every file that will be added to an APK. As we can observe, this method receives a parameter, the file name, the size, and some other things related to the file being stored into an APK. So analyzing the code of this method, we observe that there is a call to another method named setModeWhen. Using our parameter, the modeWhen variable. As we look for this variable, we find that it's a timeT type, and it's initialized to zero. It should be used inside the setModeWhen method, so let's check this code. setModeWhen is located into the zip entry dot C++ file of the source code of AAPT. There we have the method and its parameter. Remember that when is equal to zero. And inside this method, there is another variable of timeT type, it's named even, and the value of even is the value of one. So even is equal to zero too. But the question here is, is the even variable used for anything at all? Well, immediately after the lines that we saw before, even is used as parameter for local time function. It is a variable. AAPT.ENG is a TN structure, where local time will say it's result. And after that, the result is used for assign the last modified field for every file that will be added to an APK. So at this moment, we have a problem identified. In AAPT, local time function is receiving as parameter the even value that is zero. When the expected argument for local time function is already in the setModeWallet, timestamp. So let's analyze it in runtime. Here we are attached to APT. We have run the debugger with parameters for adding a file. We put a break point on the start routine that we were analyzing in the source code. And at this moment, we can observe the event variable with value zero being passed to local time function as an admin. The result of this is the one that we were seeing for the time zone disclosure of the computer. But what will happen if we pass to local time function the expected argument? That means a real timestamp. Well, now we have altered the value of event, putting a timestamp of Unix epoch. And surprise. The date and time of last modified was the correct one. So let's show you a video demo with all this in action. Okay. The computer is in CMT plus three. We have run the debugger with two parameters for adding two files. We put a break point. We reach the break point for the first file. But this time, we won't fix anything. Just we will leave in the event value to zero. And then we will have a normal execution. But for the second file, we will fix this bug. We'll put a real timestamp, Unix epoch. Of course, in Excel as well. We are changing the value of event from zero to the real timestamp. We continue the process and it will finish. So we can use now AAPT for extracting details of any APK. So now we can see this APK with the first file with this bug making the time zone disclosure and the second file with this bug fixed. Yes. Showing the right date and time information. Well. At this moment, we are convinced that there is a bug inside AAPT. But why does this end in a time zone disclosure of the computer? Well, local time function makes a calculation to put the correct hour in the hours field. It takes the Unix epoch coming from the parameter that is UTC zero and makes a sum or substation with the time zone. For example, if the time zone of the computer is G and T plus 3, it makes the Unix epoch plus 3 hours. And if the time zone is G and T minus 3, it makes the substation. The Unix epoch minus 3 hours. With that, local time function gets the correct hour in the local computer. But in AAPT, where we found this bug, local time is making a sum or substation over zero. So G and T plus 3 is just zero plus 3. That's why we will see in the hour fields the 3 number. In the case of G and T minus 3 is the substation zero minus 3. But this substation affects the date too. Now we'll see December 31 of 79 and a 21 in the hour. That 21 is the result of the substation 24 minus 3. So those G and T offsets of G and T minus whatever might look a little bit confused. So for that we made an offset table that we will show you later. And there's a little detail. When we use AAPT, instead of seeing December 31 of 79, we see an 80 in the year field. That is because of a correction factor in the method that we were analyzing in the software. In the source code, there we have an if which says that if the year is less than 80, the year is 80. So it's a little detailed, but let us know that we are analyzing it correctly. So here we have the offset table. In the case of G and T plus something, it's very easy because it's the same number. So for example, G and T plus 5 will put a 5 in the hour field. In the case of G and T minus something, we have to do the substation. 24 minus the local time of the computer. For example, 24 minus 3 for G and T minus 3. That is 21, and 21 will be the offset in the hour field. What we have done here is mapping the G and T that we guessed it is with the file date in the APK itself. So you can check the file and then get back to the G and T. And the local time zone of the one that compiled it. After all, a good question is, should local time return this? Well, in several documentations, we can see that local time should return a null in this case. Instead, this information disclosure. Because zero is not a valid argument. So, however, we can see in the idea screenshot. The return of this function, to be sure that it's local time the one that is not handling the errors correctly. There in red, we can see the G and T offset 3. In this case, it was G and T plus 3. We have to know that this bug is present on Windows, Linux, and OS X. So Android developers using APT will be leaking their time zone regardless of the platform on the ART building. OK, once we know a technique based on a bug in AAPT, let's talk about another technique that has nothing to do with a bug, but with the way attackers or creators of applications usually work. As we have said, APKs are basically seed files. And every seed file has a date inside, a date and hour. They take it from the last modified field in the local system of the user. And it gets permanently inside the seed file. On the other hand, an application APK has to be signed by a certificate. Most of the times, the certificates are created with no CA. They are self-seeded. So there's no CA. And you create it. Just a few minutes before, a few seconds before even pilot. Or in other words, you create these possible certificates for signing this APK you're creating. Certificates are in X.509 format. That means that for the creation time field in their own certificate, they take the time from the file system as well. So if you compile it in this date, the certificate will take the date from the file system. But they do it in UTC time. Without no time zone at all. So let's think about it. If there's a signature file in the side of the APK files, that is the last ones to get in the seed file or the APK. It's the last one. And it takes the last modified field. From the local system. Or from the file system. And we have this certificate. That if we think or we assume that this certificate is being created basically in the same moment, a few seconds before the compilation, you get the time in UTC. The same time but in UTC. And in the files, they have time zone included. So in these examples, you can see that if you think that the certificate has been created 15 seconds, the certificate has been created 50 seconds before the compilation, because dates are the same, hours are the same, and minutes are basically a few seconds. Here you can do the math between both dates and times. And you will have a possible GMT or local time zone. For example, here is GMT-7. Let's have another example. Imagine that this certificate has been created 4 seconds before the compilation. So the last file in the APK gets the date on the left. And the certificate has the date on the right. You have UTC on one side. And the local time with the time zone of the person on the left side. So that means that this person is maybe in GMT-1. So in an actual, assuming minutes and seconds are closing time when you create the certificate and you compile the application. And the certificate... When the application is created together, we have information enough to reduce the GMT or time zone of the person compiling it. Because we can do the math between the UTC in the certificate and the time in the file that is last created when you compile it. For example, here it would be 8 hours or whatever. So it works. We have created a little Python tool that checks... On one hand, it checks the certificate creation date in UTC time. And on the other hand, it checks the signature file date. If we assume they were created at the same moment, the developed time zone would be UTC plus 3. Because signature file was created one second after the certificate. So the result seems quite accurate. We thought this is a fun example because in the email you can check that it's .er, which is Eritrea. And this is UTC plus 3. But this is basically a coincidence. And as you can check in the certificate, it seems to come from Bracha, which is UTC plus 3 as well. So now we have these two techniques to check. But... By a book. By a bag in AAPT. And this certificate technique to know the GMT or time zone of the person compiling the applications. Let's do some statistics. We have a million... A 10 million application set or database that we have to get for both techniques. The time zone leakage by AAPT... But we have 2,000 more or less APKs with this. And the time zone leakage by day time zone certificates, we have almost half a million of them in our database. As you can check, as you can imagine, many of them will share results. So for example, with UTC plus 7, we have like 3,000 applications that has both problems. And they leak the same UTC plus 7. So this confirms more or less these techniques. And complement each other. Once we have all this information, what we did is taking 1,000 samples with each leak. 1,000 of UTC plus 0. 1,000 of UTC plus 1. With the AAPT time zone disclosure back. Some of them we didn't have enough. For example, UTC minus 7. We only had 6 of them because this is America Samoa in the middle of the Pacific. And we think there are not too many applications created there. So we check that against different antiviruses. 1, 2, plus 3 antiviruses. And check how many malware was there. This is what we got. We got that GMT plus 4, which is Russia. Russia is usually plus 3, but a part of Russia is plus 4. GMT plus 8, which is China. And GMT minus 7, which is USA West Coast. GMT plus 11 and GMT minus 8 are not good enough because we didn't have enough samples. We did the same again with the file certificate day times disclosure technique. We took 1,000 samples with every time zone, different time zones. We took 1,000 of them. We checked against different engines with antiviruses. And this is what we got. We got that GMT plus 5, GMT plus 8, and GMT minus 6 were the ones with more malware in there. Why this little difference with the other technique here? Well, we think that this is because of the DST time, Daylight Saving Time. This technique relates on the local time of the computer, so it may change. But if you think about it, GMT plus 8, which is China, and do not use DST changes remains the same. So we can conclude that we should have done this better. We should have taken into account the period of the year when you just changed the DST. But basically what we can conclude is that Russia, which is GMT plus 4, GMT plus 3, and 5, GMT plus 8, which is China, and West and Middle USA or West Coast are the ones creating more malware. And with this technique, they are creating these possible certificates as well. You have to take this into account. They are creating these possible certificates. So this makes sense because maybe we think, it's just a theory, that the cloud is too many computers in the USA, in the West Coast, and they create certificates in there that are possible. And that's why we have so many malware in there. We did it here the other way around. What we took is all the malware we had with these leakages and checked for the UTC or GMT time. And this is what we got. Again, with one technique, the file certificate date time technique, we got that UTC minus 6 and UTC plus 8 were the ones with more malware. And with the other technique, the AAPK bug time zone disclosure, we have basically the same, UTC plus 8 and UTC plus 4. And what is this useful for? What we did as well is check our database. We have 10 million of them. And we have got several sets of 1,000 applications. And we have a rate of 6% of malware in there. And we took a set of 1,000 AAPK samples with these leakages or disclosures and compared each other. And we conclude that the chances, for example, with comparing our standard rate, 1,000 applications, which is 6% of malware, and a random set of applications with UTC plus 8, makes it six times more likely to be malware than our standard rate. You know how that is. Let's see some examples with real life. For example, this death ring I loaded in some telephones had this file certificate dating problem that was leaking the time zone. And it was Korea, UTC minus 9. And so did UD malware, which had this AAPK time zone disclosure bug. And it was Korea as well. This is a malware we found a few years ago. It was a very interesting malware that once the mobile was infected, it took some user and password from the database of the attacker, preloaded the user and password, came to the telephone that was infected, registered it with this telephone and email and everything in Google Play, got the token back to the attacker, and with this token, they were associated with the telephone. He was able to give five stars and download fake applications. Fake users registered it to real telephones, voting and downloading fake applications, just to get up high in the Google Play Store. This is called Shoei Ban. Well, we found it focusing on this bug, GMT-48, which is China, and some other things like connecting to a PHP command and control, having this get account permissions, and hiding behind wallpapers applications. Focusing on that, we were able to find and define this malware. And we alerted Google Play and they removed it, and it was quite nice to research. That's all malware. This malware comes from China. Now, we have, for example, HIDAT, that we took a few samples from them, which this malware had both techniques. You could check that with both techniques, that it came from GMT plus three, which is Russia again. And aside, here you can guess in a way that certificates are always created about two or three minutes before the compilation, which lead us to think that they were like automated. These possible certificates created in an automated way and coming from Russia. Okay. With the technique that we were analyzing, probably we'll get to the time zone of the Android malware developer. Now we see quickly how we can do an accurate from the time zone that we got to one specific country. Inside an APK, there are some files pretty common. One of them are the RTF documents. Usually they are used for agreements, agreements inside Android applications. Related to this kind of file types, we had an inspiration some months ago when WannaCry occurs, because this ransomware shows message in multiple language using several RTF documents. This is a funny thing, a trick, with Word Office and RTF files. When you create an RTF file with Word Office, you get inside the RTF metadata. It's called slash deflang. This is your default language in your Word or text editor. So every one of us has a default language in our Word. So it leaks through RTF files. And maybe if you have your, it's quite possible that your Word file has the final languages, is your native languages. So it leaks your, maybe your native language to RTF files that you create with Word. Yeah. We made our research for getting information about WannaCry. And among other things, we checked those RTF documents for metadata. And as a result, we found that Korean is the default language configuring the text editor of WannaCry's developer. Well, here we have an example of an Android malware which among its file, there is an RTF document. We have to know that either Android Studio nor other IDs remove the metadata from the media files added by the developer to an APK. So we can check this kind of media file and get some interesting information. In this case, we found that Arabic is the default language in the author's text editor. There is another trick to accurate the country. If we can get the strings typed manually by the developer, it may be helpful for knowing the native language of her. We can use APT for extracting a string of an APK, but there's a problem because even if the APK is extremely simple, there will be lots of strings added automatically by the ID just for translation purposes. So in the screenshot, we can see thousands of strings. All of them were added by the ID automatically in a very, very simple APK. So we can do a little bit of magic using APT for extracting all the resources filtering by strings using Grid together with Regex. A pretty nice command. Analyzing the output of this command, we found a way to differentiate both strings added automatically by the ID from those written by the developer. Basically, we are checking the origin of the strings, removing those coming from resources where strings of translation are. After all, the only thing we have to do is to check what could be the native language of the developer, just seeing the strings typed manually by him. And we created a tool as well, which is not online yet. This is not the best, simplest in the world, sorry, but you can drag and drop an application and it will try to reduce the possible DMT and check for another techniques to get the country and the languages. The country basically sometimes comes from these techniques we have explained, or maybe with the certificate itself, or maybe analyzing the strings.xml, that we have shown, or even sometimes maybe from the TLD domains, the dot whatever that the application has inside. So you can reduce with these different techniques, which is the DMT time zone or the language, the native languages of the person. This tool takes all these techniques together and once you drag and drop whatever APK, you will check different techniques to get in there, even the RTF that we have just talked about. So I hope this tool will be online soon. The other one is already online. This one, for example, says that it comes from Russia and has some domains with TLDs, and the certificate is the standard one for the Boeing, so it's not useful. So what are the conclusions here? Is that we presented different ways for not just leaking time zone, but as well possibly taking automatic malware creation because of this possible certificates that are created a few seconds or minutes before the compilation is done. Possible better machine learning features in detecting APK malware. Remember that we said some statistics that could be useful once you create a machine learning algorithm. It's useful to have neat features to have a better understanding. So I think this is a pretty good one for machine learning and detecting malware. The ones that are created with these possible certificates or comes from one time zone or another. And a tool for a quick view of all this information around APK metadata. Feature work, as we said, should take into account the DST, so it's more accurate, these techniques, and maybe have a little more sample, more than a thousand samples of each disclosure technique or whatever. Thank you. And this is pretty much all. Thank you. If you have any questions. No questions. Not too difficult, please. . Not with WordPad, and this stuff doesn't work. Just work with Word, with text, because it has the file language defined in there. WordPad, for example, if you create an RTF file with WordPad, you don't have a language. Take into account that this is, this language is the one you have defining your text editor to, to the syntax correction. So I don't know any other Office package, but with Word, with Office where it happens. Okay. No other question? Thank you. Hope to see you in some other . Thank you.