Let's go back nine years ago to the summer of 2016. It was about to be just a regular summer, you know, going to the pool, attending DEF CON, but little did we know Niantic, a mobile game company, was about to release a new game called Pokemon Go, condemning thousands of nerds to be collectively sunburned. But jokes aside, this was a dream come true for me and for many. You know, being outside, chasing Pokemon, battling for gym access, it was really, really a dream come true. Except it wasn't so much for me. I lived in a rural town back then and there weren't any Pokemon around me. And while everyone in the city was having fun, I had to chase down Pokemon very far away from my home. And all I had, in fact, was this lousy scanner. I don't know if you remember it. But you could only see the nine closest Pokemon to your location and a footprint one to two or three showing you how close they are to your location. And honestly, this sucked and all the Pokemon were ratatats anyway. These are real pictures of me and my friend. So naturally I decided to build a Pokemon scanner that would tell me where all the Pokemon are and those that I haven't caught yet so I can flex on my friends. So little did I know this idea would take me to an adventure of uncovering the Pokemon Go protocol and understanding how it works and also having to overcome very difficult defense mechanisms against fake scanners. Hi, everyone. My name is Tal Skverer. I know my last name is hard. I'm a security researcher by day and a security researcher by night as well. During the day I get paid to lead the research team at ASIC security, a cyber security start up doing identity security and by night I do independent hacking, CDFs and all sorts of crazy projects you can read about in my blog. Actually it's not the first time on DEF CON. You noticed I haven't done any shots. In DEF CON 31 I talked about a zero day in GCP and I'm very, very, very excited to be here today. Thank you all for coming to hear me. This talk will be accompanied by a two part blog post that will be live on my blog right after this talk. It might be even live right now. So you are free to go and read it afterwards. I go into details further than I am in this talk due to lack of time. I also have quality stickers, limited time edition that I will be giving away after the talk so feel free to come by, ask me questions, take your sticker and you can also reach out to me on social media. And like every good Pokemon trainer we need to collect badges. So we'll collect six badges during this talk when we overcome a very difficult gym battle and you can use this to know where we are on the talk approximately. One last thing. So this research was done independently nine years ago. Most of the techniques that I'm going to show you today no longer work on the actual app. So this talk is mostly to show you how the mobile hacking game community looks like. And I have references. So all the images that I'm going to show you today are based on publicly available data. I will be sharing the references slide in the last slide. With that out of the way, let's begin. So I hear you want to create a Pokemon scanner. Hello. So I hear you want to create a Pokemon scanner. And we know that the Pokemon Go app operates something like that. So it has to get the information that it displays in the lousy scanner. So it has to request data to get all the Pokemon and get back all the nearby Pokemon to its location. And this is a request that I want to forge to say that I'm in a different location and get all the Pokemon around that location. But who is to say that the app doesn't get only the information that is displayed on the lousy scanner. So only a list of nine Pokemon and the footprints of how far they are from you. Well, there are two hints. One, if you play Pokemon Go, you know that once you are close enough to the actual Pokemon, it immediately appears on your screen at a very specific location which kind of tells you that the app knows the exact specific location. The second hint is that servers are lazy. So no one wants to do this heavy computation that has to do with determining how far a Pokemon is to you. And Niantic would be happy to delegate this computation to your device. You have a very powerful Android device or Apple device in your pocket that can do this calculation for you. So I'm not sure that I convinced you but I did convince myself back then and I'm happy that I did. And I wanted to see how to be able to do this request. I wanted to see how the protocol looks like. And to see the protocol, I have to look at the traffic that goes between the Pokemon Go app and the Pokemon Go server. And this is a tech called sniffing attack. We can pretty guess, pretty much guess that the app and the server communicates over HTTP which means that we need to employ an HTTP proxy to look and record the information that goes back and forth. In Android, that's pretty simple. You spin up an HTTP proxy on one of your machines, you go to your Wi-Fi settings, you put the IP address of your machine in this proxy settings and immediately you start seeing traffic. I used filler classic back then. I still use it today. Call me an oldie but I really like this program. And this is how the real communication looks like in filler. As we can see, the app starts by requesting a generic end point and then switches to a specific end point probably for load balancing issues. And now we are able to see the communication between the app and the server and for this we get our first badge. The badge of sniffing. Okay. We have the communication. Let's dig deep into the actual protocol. So as you can see here, we can see the request content type that is reported by the app is actually form URL encoded. As you can see, it is lying. Because if you ever saw form URL encoded, it's textual protocol. And here the protocol is clearly binary. So what's going on? Let's look a bit deeper into the actual binary of the request. On the left, maybe it's on the left for you, you can see the bytes being sent on the wire and on the right you can see the ASCII presentation of them when it is possible. And it probably means nothing to you but luckily at the time I happened to look at this exact scenario multiple times so I immediately noticed some very telling clues here. The first one is that the first byte of the request is 08 and the second is that there are some glimpses of readable text which means that it's not encrypted but rather serialized and I immediately realized that this is protobuf. Protobuf is short for protocol buffers. This is a very well-known framework developed by Google and maintained by Google that takes very complex objects and knows how to serialize them so two separate systems like an Android app and a server can communicate with each other even though the objects can be relatively difficult. So let's take a second and switch the screen to this very, very nice pink hue to talk about protobuf. So as a developer you define a protobuf message which is the object you are going to send and the definition looks something like that so this is just an example definition from the protobuf documentation. We define a search request message. It has four fields. The first field is a query of type string. The second field is a page number of type integer and then there are actually two optional fields that don't have to appear in every object. And as you can see, the fourth field actually, the search options, is a repeated field which means it can appear more than once, kind of like a list. As you can see, its type is a search option so you can embed messages within other messages. And we don't have a declaration of a search option here and that's on purpose. And to use it, you use a tool, as I said, developed by Google named Proto C. You take this definition, you kind of compile it into your favorite language. For this example I compiled it into Python and then you can simply import the resulting file as you can see here. On the left, this short code imports this library, creates a new search request object, fills it with information, serializes it and sends it on the wire. Good. So we know now about Protobuf but we have a problem. We see the serialized data on the wire but we don't have the original definitions. So what we can do about that? Luckily Proto C supports a flag named decode raw, it's the best flag ever, which basically tells Proto C do your best to deserialize this message without having access to the actual definitions. If we would take the message that I created here that was sent on the wire and decode it, use the decode raw flag on it, we would get something like that. So as you can see, it's not looking like the original, we don't have the field names, maybe some of the types are wrong, but we can still learn a lot about the underlying definition just from seeing the deserialized message without the declaration. And we can even tell some things about the message that we didn't see the declaration of, right? You can see it has two fields, both of them are strings. So let's apply this technique to the actual message that we just saw for Pokemon Go. So here it is. It's very loud, you probably can't see anything but that's fine. So at first this might look a bit difficult to understand and today you have tools like PBTK that basically goes and looks at the binary of an Android app and extract all the definitions, all the compiled definitions from it. Back then understanding protocol definitions was nothing short of an art. And I use several techniques to understand how messages look like and how the protocol works. I go deeper into them in my blog post but here I just cover the three main tips and tricks that I use. The first one is you can tell a lot about fields using their values. So if you have very clear values like the strings at the bottom there, that you can immediately, if you know this, you know that this is an open ID token, then maybe field 10 is an authentication field. The second trick is actually knowing that some of the different types, like hex code and integers that you can see there and floats share the same code. So sometimes protocol C when it tries to decode them, it doesn't know what the original type is, so it just tries its best. And if you would go and convert those hex encoded integers into floats, you would just see that they are coordinates. So this is my location. And the third technique is actually by interacting differently with the app, like making a different action or moving to a new location, I can see the messages are changing slightly. And using these changes I can infer a lot of information about the underlying declaration. I will save you all of that. You are welcome to go to the blog to read more. But after understanding some of the fields of the request, I ended up with this declaration, which is a bit shorter so you can see it better. So how a request looks like from the Pokemon Go app. So it's actually, I call it a request container because it contains requests. The request container has some metadata fields like the request ID, my location, my authentication info and it has a repeated field that I named requests that includes all the different requests that the app wants the server to answer on. Each request has a request type and optionally request bytes if it needs to. So here it sends three different requests, 106, 126 and 4. And the server response looks relatively the same. So it has a response container with the same request ID and a repeated response field. Each response corresponding to one request so it's always matching one to one according to the same order. Okay, so now that we know how the general format looks like, we have to try and find the actual request that gets the list of Pokemon, right? That's what we wanted to do for the scanner. But there are tons of different types of requests. And I tried to do a few things like searching for Pokemon names, searching for locations around me, but I didn't really manage to find the actual request type that I wanted. And what actually solved it for me is playing Pokemon. So if you played Pokemon, you know that all of them are indexed by an incrementing number. And by looking at the lousy scanner and seeing that it scanned a PG and a Rattata, I searched for the number 16 and 19 and I found a hit. So it turns out request number 106, which was later changed to name get map object, that's the title, is a request that takes as input an identifier of a cell and as a response looks something like that. It responds with a map cell object that basically includes all the different objects that are on this specific map cell in the area, including Forts, which is the internal name for gyms, poker stops, et cetera. It also includes spawn points and Pokemon and more importantly it has the exact location of the specific Pokemon in this map cell. As you can see there is a catchable Pokemon at a very specific location and this is the Pokemon number 23. So who is that Pokemon? I hope you know it. So upon successfully understanding the protocol of how the Pokemon Go app requests and gets all the Pokemon in a specific location, we earn our second badge, the badge of protocol. So what do we know so far? We know that the communication, the protocol uses protobuf and the main message that is being sent is a request container. It contains some metadata on the request including a list of requests, one of which is request number 106 that fetches the map details for a specific cell. It gets a cell ID and responds with the exact location of Pokemon which is the best case scenario for building a scanner. But we still have three open questions. So the first one is how do you construct a request container? So it has complicated fields like authentication fields. How do you create them successfully? Second, there are still plenty of fields and request types that I just didn't know. So I called them unknown like unknown six. So do I need to create them in order to make a successful request? I don't know what they are used for. And lastly, what the hell is a cell ID? I'm used to coordinates. I don't know anything about cells. So it turns out the answer to the first two questions was actually pretty simple. The server just doesn't care. It was very, very relaxed regarding what the data that it expects in a request container. You basically only had to send a request identifier, your authentication info which is very straightforward and a single request 106 with your cell ID. It didn't care about other fields that I understood. It didn't care about all the fields that I didn't understand. It didn't care about other request types. So best case scenario for me. About that cell ID, so keen eyed of you may have noticed in the previous slide, I call this an S2 cell ID. It turns out Pokemon Go uses a framework named S2 cells. It splits a sphere, in this case the earth, into cells. You decide on a level which basically controls the size of a specific cell. Pokemon Go works with at least get map object works with level 15. And then you have a very, very simple calculation that has a lot of calculators online that take a specific coordinate on earth and converts it to a 64 bit cell identifier that you put, excuse me, in your get map request as the cell that you want to find Pokemon on. So with all the questions answered, I went and created a Pokemon scanner. This is my code from back there. A very nice code. I'm sure you can see for yourself. It gets authentication info from Google. It constructs a request container with authentication info, request identifier. So it starts on with a specific location basically all around me. I scan like a radius of a few miles. And for each location it adds a new get map object request, converts the actual coordinate to an S2 cell , gets the request, passes the response, puts all the different Pokemon that it finds on the map, and we have a request container. And dumb me, I didn't really record any of the actual maps that I built with Pokemon from back there. I only actually had this one picture of a log that I had. And you can tell that it's not fake and real because I had to blur out my actual location. So that's my only proof to you. But this is an example log from the scanner that searches for different Pokemon. I think it found a Pidgey. And it was great. I flexed on all my friends. I found all the cool Pokemon. I used it for a couple of weeks. And upon successfully creating a Pokemon scanner, we get our third badge, the badge of Pokemon. So one quiet Wednesday I got back home and I started my Pokemon scanner to play a nice evening of Pokemon Go. Only to discover that it didn't work. So my scanner got like a generic error that I really didn't understand. So naturally I opened up Fiddler, my HTTP proxy, to see how the information, how the protocol looks like. I knew that a few days earlier a new update was pushed to the app. Maybe something, some stuff in the protocol has changed and I needed to update my scanner. And Fiddler didn't record anything. And in fact, while it was open, the Pokemon Go app refused to turn on and refused to do anything. So okay, we have a challenge . We have a fighter on hand. So naturally I went online to search if anyone else has encountered this problem. And I realized that I wasn't the only smart guy in the room that decided to build their own Pokemon scanner. There were actually many different communities online doing this stuff. One in particular was PogoDev, a community dedicated to creating unofficial API for Pokemon Go. They had noticed this issue as well and started tackling it. And in fact I found that their administrator had actually put up a Reddit post saying, well, we know our API is down. Something has changed in the app. We've created a Discord server to coordinate efforts around this. So naturally I went on the Discord server. I joined the internal hacking channel and we started working towards solving this. Little did I know this step would be the first out of a three day hackathon where I barely slept in which we tried to overcome all the defenses that were put by Niantic against unofficial API calls. I will make sure to, and we used various techniques to overcome these issues. I will make sure to stop when I introduce a new technique. I will name it. I will explain how it works. And then we can see how we used it to overcome the defenses. On top of the title you can see the timeline. So this started around 1 a.m. in the first day. So you can follow along how long it took us to do every step. So the first hurdle was the fact that no one was able to sniff the traffic and see the protocol and how it looks like. And we thought, and actually one researcher found this interesting class was added to the Pokemon Go app named Niantic trust manager. And so it implemented a check server trusted function which seems like it implements a defense called certificate pinning. And to understand how we overcome it, we first need to understand why it works against HTTP proxies and basically blocks their behavior. We need to talk a little bit about HTTP proxy. So here you can see a very, very high level overview of how HTTP proxy works. Basically, normally when you work with HTTPS, the client communicates with the server in an encrypted form. That's what the S stands for. Secure. Based on a certificate that is provided to the server to the client. And besides confidentiality, HTTPS also promises you integrity. Which means that you know that you are talking to the real domain and not a fake domain that says, hey, I'm a Pokemon Go server. But that's exactly what HTTP proxy needs to do. It needs to convince the client to speak to it and it will parse and decrypt all the communication, log it and then pass it on to the server. So it works because you own the client. The HTTP proxy generates a certificate that you install as a certificate authority on your client which basically allows the HTTP proxy to create and sign any certificate that it wants for any domain that it wants and convince the client that it is talking with the real server. This is how the certificate of filler looks like on my Windows machine. It works the same way for Android. I was too lazy to pull it up from my machine. Okay. So now we understand how this works. So how do certificate pinning works? By doing certificate pinning, basically the developer takes the public key of the actual server that it intends to talk to and simply hard codes it into the application. And what the application does, it wants a new session of HTTPS starts. It verifies that the public key of the server matches the public key that is embedded in the code. Obviously, since the HTTP proxy generates a new certificate, the public key would be different from the real deal and that way the client can detect that it is actually interacting with the HTTP proxy and not the actual server and basically block the communication. So how do we overcome it? We have to use a new technique that I call dynamic reverse engineering. So we have to learn it. So what dynamic reverse engineering means is intervening in the running code of an application and basically changing stuff on the way. You can think about it similarly to developing code and debugging it and changing values while it is debugging, only automatically. And there are a few frameworks that allows you to do it for Android in particular. One of which is exposed, which basically allows you to hook any Java class function that you want and run code before it starts and after it returns. So we wrote this short exposed model. It is actually very short. I just removed the original change because it is very long. We hook on the checked server function of the trust manager, which by the way we found because it extends a very well-known class for certificate pinning named X509 trust manager. That's a good way to find certificate pinning if you ever want to do so. We took the original chain from the actual server. This is public. It is very easy to get. And what we do is we did a before hook. Before a function is called, so every time it is called, we basically replace with the first argument which is the certificate to validate with a real certificate. So that way the app always thinks it interacts with the actual server even though it is not. So we fool it that way. So this allowed us to see the traffic again. And what we saw kind of surprised us. We saw that nothing changed. So all the protocol looked exactly the same as it was before. So what was the problem? We realized that what might have changed is one of the fields that was previously unneeded and optional started to become required and the server started verifying it. And we needed to find it and there were various different fields that we didn't know, various types of requests that we didn't know. So to figure out the specific field, we had to use a second technique that I call active probing. With active probing, and I actually used it a little bit for my scanner, you take a valid request and you start changing values with it and sending it to the server until the server starts responding with an error. So what we did is we basically started removing fields that we knew were optional one by one until the server returned an error. And that way we actually found a specific field, the sixth field of the request container became required which was optional before. And so we did know a bit about the format of the sixth field. We called it unknown six. We knew that it contained a message within and within a message there is a byte array and the byte array actually contains the information within unknown six. And we turned our sole focus of this research was turned into unknown six, which naturally, it was natural to take the name of it as the name of our group. So we called ourselves team unknown six and we focused on cracking this. So starting off, we wanted to know more about unknown six and how it looks like. And to do this, we'll use our third technique which is kind of like the counterpart to the active probing. I call this passive analysis. Passive analysis was also used for the Pokemon scanner. You generate a lot of different requests by interacting differently with the app or doing different actions or simply generating a lot of different requests from a lot of different devices. Looking at all these requests, you can infer a lot of details about how the protocol works. So what we did, we generated a bunch of unknown six examples. This is one specific example. As you can see, most of the information is within the one field over there. I'll just call this unknown six for short. And we noticed something peculiar from all of these samples. The size of this unknown six. So it turned out that the size of this was always a multiple of 256, one of my favorite numbers, plus 32. So the size of this is just one block of 256 and 32, so 288 tokens. So it's a bit peculiar. Another very nice finding that one of the researchers did is that they set the time, the clock on their machine to the exact same second every time. And he noticed that all of the samples of unknown six that he generated began with the same 32 bytes. So we managed to figure out that the first 32 bytes of unknown six only depend on time where the rest depends on other things. Actually by doing active probing and taking a valid unknown six and changing the request, just the cell ID in a get map object request, we would also have the server return an error. Which means that this unknown six is strongly tied to the request we make. In fact, the existence of numbers like 256 and the involvement of time, we kind of guessed that this is some encrypted signature over the request that we make, that now the server started to validate. It was always sent to the server, it just didn't validate it before, probably because they suffered from a lot of technical difficulties in the first weeks of Pokemon Go due to the large number of people that were playing. So the next step that we wanted to do is to find where this unknown six is generated in the code so we can understand what happens and how the encryption works and how the signature looks like. And we knew that everything that has to do with protobuf is actually in the native part of the application. So let me stop for a second. I speak a lot about the Java part of the application and the native part of the application, so let me explain. An Android application is basically split into two parts. There is the Java part, it's the more high level part that has to do with interacting with the Android framework and interacting with the user. And then there is the native part, usually coded in C or C++ that is actually compiled and inserted in the library that the Java part can call using NDK. This is an interface between them. Actually the certificate pinning called, it was a Java class that was calling a native part. And usually native code is used for more computational heavy operations and it's no wonder that mobile games mostly rely on native code because they have a lot of graphical related computations. Specifically Pokemon Go I think relies on unity. Okay, so what do you do with the Java part and the native part? To understand it further you have to use our fourth and final technique which I call static reverse engineering, kind of like the analog to the other way around of dynamic reverse engineering. You use specialized programs to inspect the actual code that is being executed by either the Java part or the native part and you use specialized programs to do so. These programs basically do the other way around. They start from an assembly, they disassemble it back to the assembly language and then they also try to decompile it to get as close as they can to the original source code that generated the app. With Java we have Jadix. It's an amazing tool. It does an excellent job. Here you can see the Pokemon Go app open in Jadix and actually the image from before of the certificate pinning class was actually from Jadix as well. It does an excellent job reflecting back the byte code of Java into the actual code as close as possible to the original. And it's relatively easy because Java is only compiled into an intermediate language. When it comes to native code this is a bit harder and you have to use different tools. This is an example from Ida. Today we have Gidra which is also a great tool. They basically show you the actual assembly. On the left there you can see the graph view of a function in Ida and on the right you can see Ida trying its best to decompile the assembly code back into C code. And these programs what they actually allow you to do is to change the names of functions, of variables, change the types that are being used, define structures, really to help you to understand difficult patches of code and get to the point where the code that you are looking at is very close to the original code that was being developed. So we knew, as I said, we knew that everything related to protobuf including creation of unknown 6 is in the native part. Specifically in a library named Lib Niantic manager. So we opened it in Ida and we had to pinpoint the actual function that generates unknown 6. And there were a few methods to do it. I think I laid down three different methods in my blog. Here I will only share one method due to a lack of time. This was the method that I used. If you recall, using static analysis, we found that the starting bytes of the unknown 6 message are only dependent on time. So naturally the code that generates unknown 6 has to rely on time somehow. And once you have a binary library that relies on a system function like time, it needs to import it usually if it's not compiled statically. So I went to Ida, to the import table, and I did find the time function being imported. And I looked at all the cross references meaning all the locations in the assembly in the library that calls time. I found two. The bottom one wasn't related at all. It was very easy to see. The top one, the function at offset 87444, I can't even see it. I remember it. So once you look at the code there, you see that the output of the time function gets fed into SRand, which sets the seed of all the randomness that is going to come. Then this function generates 32 random bytes. And finally, you can see a lot of places in the code where the number 256 as a constant appears, which really makes us believe that we found the actual code that generates unknown 6. And for this, we get our fourth badge. Badge of unknown 6. Okay. So at this point, we looked at a specific function that we pinpointed. We called it sig encrypt function because we believe it encrypts a signature. It was only natural. And we decided to verify beyond doubt that it's exactly the function that we wanted to generate unknown 6. So we used active probing again, excuse me, dynamic reverse engineering again to detect that. This time, instead of exposed, we used Frida. Frida is a very, very powerful tool that allows you to basically hook using JavaScript any function that you want. It works on Windows, Linux, Android. It's very strong for Android. Here you can see a short Frida script that basically finds the ‑‑ so it hooks on the native library. It finds the actual address of the function that we wanted, offset 87444. It hooks both the enter of the function, so every time it runs, and the return. And simply dumps the input and the output. And by matching the output that this hook recorded to the value that was actually being sent by the app afterwards in our HTTP proxy, we noticed that it is exact same value, meaning that we did find the actual function. Another better finding that we managed to do with this hook function is actually look at the input to the encryption function, which is our signature, and we found that it is actually port above again. So I heard you like port above. And it's a very, very long object. And there are some interesting strings there, like one plus that was my device back then. And it looked like field that was supposed to be in the signature, so we had that. But before moving on, we focused on the sig encrypt function in trying to understand how does it manipulate this input to get to the encrypted output that we know. And it turned out to be quite simple. So I will be able to show you this today. Here you can see the decompiled version of the sig encrypt function. And let's start with an input of length 700. I split it into 256 chunks. The less chunks is a shorter one, just for easier understanding. So as we knew, it starts by calling time, feeding it into SRUN and then generating 32 bytes for the seed, which it prepends to the beginning. So that's the 32 bytes that we saw in the final version. Then it pads the input to the next closest block of 256. And actually the last byte is the remainder, so the server knows how many bytes it needs to strip to get to the actual input. And this is not the interesting part. This is the interesting part. We have encryption. So we have encryption at offset 9E9D8. This is the encryption function. And first the function starts by expanding the seed into a block of 256 using an expansion mechanism. And then encryption works. So this expanded seed is actually using the initialization vector to the encryption function together with the first block to output the first encrypted block. It gets overridden to the first block, which is used as the IV with the second block to get the encrypted second block and same way for the third block until we have our encrypted value that is being used in unknown 6. And this is nothing proprietary. This is a very well-known cryptographic scheme named CBC mode that has to do with encrypting blocks based on initialization vector. So now that we know how the sync and encrypt function works, we split into two groups. One group focused on encryption 9E whatever to understand how encryption works and basically replicate it so we can encrypt our own values because we want to encrypt our own signatures. The second group I was a part of actually focused on the signature to understand how it is constructed so we can create our fake signatures to sign. And actually, I think it was five hours later, the first group already succeeded. They were very, very good. And replicating and getting the encryption to work. So how did they do it? They were very smart and they walked through the entire call chain of the encryption whatever numbers that came afterwards. Which means all the functions that could be theoretically called by following the chain of calls from this function, they automatically used IDA to decompile them into very ugly C codes but it was a C code that compiles and executes exactly the same as the original assembly and they put them all in a single C file which turned out to be of size 14,000 lines which actually with a few fixes compiled successfully and allowed us to encrypt any input that we want to which was a very good job by them. And for successfully replicating the encryption function, we get our fifth badge, the badge of encryption. So meanwhile, the second group that I was a part of actually focused on understanding how the signature works. So there are a few subfields within the signature message that were very easy to understand according to the values in the field. And you saw them earlier. So one contained GPS information, basically a dump of all the GPS information that you can infer that the device can get which called location fix and the second one called device info contained a lot of different properties and string about our device. And actually the third message that we found, we understood what it means quite funnily. So people starting to generate a lot of samples of the signature, we started using emulators and we noticed that this field was always empty in emulators and always filled with regular devices. So we understood that it contained sense of information. Obviously emulators don't have any sense of information, real devices does. It contains a lot of information regarding acceleration, altitude, gravity, etc. And actually at this point, so this is how the signature declaration looked like at the time, what we understood so far. And inclusion of fields like this field, like the sensor info field, actually something before that. So people that were using active probing to understand things about the signature protobuf, started getting their account banned. And this together with the existence of fields like sensor information, fueled the fears in the community that Niantic was using the information within the signature to detect unofficial API usage. And if you consider things like sensor info, this is kind of akin to tracking your mouse movement for captures. This is a data that is very hard to forge and we really didn't know how we were going to create this for our fake signatures. But this thought also made us wonder, does the server actually verify this? So to verify things like sensor information based on previous sensor information is a very , very difficult computational job. And we knew that the servers were under high load at the time. So we thought, well, maybe not all fields in the signature are necessary. So we employed active probing again using dynamic reverse engineering, using Frida. We started removing fields from the signature before it was encrypted and seeing when the server starts responding with an error. And we found out that most of the signature was not needed. So all the fields that you can see that are marked with not required, were not required. And actually only six fields were required. All of these highlighted here. Two of which were just regular time stamps, which were very simple. So we were left with just four fields to go. Field 10, field 20, field 22 and field 24. At this point, I recall, the discord was going crazy. So here we are at the end of the second day of the hackathon and we were very tired at the time. And actually we had to go to discord and ask them to increase the limit on our server size because so many people had joined and back then it wasn't so common for servers to grow beyond 10,000 members in such a short time. And another thing that happened, so we had this channel named RE research, which all the hackers were a part of. And eventually, because people kept asking, it was open to the public. But only for view, not for chatting. So only we were able to chat. And I remember that we had a voice chat with hundreds of people within it waiting and analyzing every message that we sent in the RE research. It was a very humbling experience, I can say. But it was very, very crazy. So going back to the fields that we wanted to figure out, we actually found that two fields, field 10 and field 20, were generated based on the same function, which takes as input a 32-bit number, a byte array, a string, and outputs a 32-bit integer as well, which kind of looks like a hashing function. And we found that field 20 was a very simple hash of this number. We don't know what it means to this day. If you know, please approach me. I would be happy to know. And the string of your location chained together . And the output of the function was inserted in the field 20. Field 10 was a bit more complicated, but not so much. So first you hash your authentication info straight from the request container and then you feed the output of this hash as the integer to the second hash of your location. So we have two hashes, both on the location of the user, one of which is also on the dedication info. So at this point we tried to understand what's the hash. And one technique to do it is to look at the constants being used in the hash and comparing them to known hashes. Using this we very easily found that it's a very famous hash named XX hash. And this was a 32-bit version of it. We also found a 64-bit version of it. And it was actually used for field 24. So field 24 was a repeated field, at least as you can see from this. And actually every request that was sent took the request bytes of the request and hashed them together with the same integer that I don't know. And it was the hashing, the hash was added to field 24. So field 24 contained as many hashes as you had requests. So for this example you had three hashes in field 24. And then we had the last field, the final field, the toughest nuts to crack. We actually went in the wrong direction for a while because we saw that it changes frequently when your dedication info changes. But it turned out to be completely false. One researcher found that the function that generates this field didn't get any input. So this field could be basically any thing. And once we tried to do it, we at 7 p.m. the third day, 67 hours after the hackathon started, we finally managed to make our first successful API request. And for this we get our final badge, the badge of API. Thank you. I'll just take one minute. One minute to talk about, so I was very interested to, so this is my code from back there that implements the actual authentication. You can laugh at it while I talk for the last minute. I was kind of interested to know what happened afterwards. So it turned out that, so we all treated this effort as something that is necessary to create a community, thriving community, developing tools for Pokemon Go. We really believe that having access to this kind of tool makes it possible for people that couldn't play the game normally to have access to it. And I was interested to know where the Pokemon Go hacking scene went from this. So I kind of didn't get involved into more stuff afterwards. So Pocodev continued maintaining their API for about a year and a half after this, after which they stopped. Today I search online. There's also a couple of bots that are offered for cash. Together with some unlocked versions of the app, I wouldn't install those, which is a far cry from what could have been if Niantic would publish an official API. I'll just like to thank both the team, Anon8, they were amazing guys. I had fun to work with them. I would also like EFF for supporting me and counseling me on giving this talk today. If not for them, I was not here. I will also thank you for coming. And there's a reference slide. Feel free to come, grab some stickers. Thank you for listening.