1 00:00:00,000 --> 00:00:04,800 Let's go back nine years ago to the summer of 2016. 2 00:00:05,160 --> 00:00:21,820 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. 3 00:00:22,860 --> 00:00:27,560 But jokes aside, this was a dream come true for me and for many. 4 00:00:27,560 --> 00:00:36,100 You know, being outside, chasing Pokemon, battling for gym access, it was really, really a dream come true. 5 00:00:36,240 --> 00:00:38,700 Except it wasn't so much for me. 6 00:00:38,700 --> 00:00:43,900 I lived in a rural town back then and there weren't any Pokemon around me. 7 00:00:44,360 --> 00:00:51,480 And while everyone in the city was having fun, I had to chase down Pokemon very far away from my home. 8 00:00:51,520 --> 00:00:55,380 And all I had, in fact, was this lousy scanner. 9 00:00:55,380 --> 00:00:56,960 I don't know if you remember it. 10 00:00:57,780 --> 00:01:07,640 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. 11 00:01:08,180 --> 00:01:12,400 And honestly, this sucked and all the Pokemon were ratatats anyway. 12 00:01:12,960 --> 00:01:15,200 These are real pictures of me and my friend. 13 00:01:15,840 --> 00:01:24,840 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. 14 00:01:25,780 --> 00:01:43,480 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. 15 00:01:44,460 --> 00:01:45,480 Hi, everyone. 16 00:01:45,480 --> 00:01:46,580 My name is Tal Skverer. 17 00:01:46,580 --> 00:01:48,240 I know my last name is hard. 18 00:01:48,240 --> 00:01:53,220 I'm a security researcher by day and a security researcher by night as well. 19 00:01:53,220 --> 00:02:07,640 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. 20 00:02:08,700 --> 00:02:10,540 Actually it's not the first time on DEF CON. 21 00:02:10,540 --> 00:02:12,900 You noticed I haven't done any shots. 22 00:02:13,340 --> 00:02:18,560 In DEF CON 31 I talked about a zero day in GCP and I'm very, very, very excited to be here today. 23 00:02:18,560 --> 00:02:20,640 Thank you all for coming to hear me. 24 00:02:22,440 --> 00:02:27,740 This talk will be accompanied by a two part blog post that will be live on my blog right after this talk. 25 00:02:27,740 --> 00:02:29,500 It might be even live right now. 26 00:02:29,620 --> 00:02:33,340 So you are free to go and read it afterwards. 27 00:02:33,340 --> 00:02:38,500 I go into details further than I am in this talk due to lack of time. 28 00:02:39,380 --> 00:02:51,260 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. 29 00:02:51,320 --> 00:02:54,580 And like every good Pokemon trainer we need to collect badges. 30 00:02:54,580 --> 00:03:04,960 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. 31 00:03:05,220 --> 00:03:07,000 One last thing. 32 00:03:07,560 --> 00:03:11,120 So this research was done independently nine years ago. 33 00:03:11,120 --> 00:03:16,800 Most of the techniques that I'm going to show you today no longer work on the actual app. 34 00:03:17,480 --> 00:03:23,620 So this talk is mostly to show you how the mobile hacking game community looks like. 35 00:03:23,620 --> 00:03:24,840 And I have references. 36 00:03:24,840 --> 00:03:31,040 So all the images that I'm going to show you today are based on publicly available data. 37 00:03:31,040 --> 00:03:34,520 I will be sharing the references slide in the last slide. 38 00:03:34,640 --> 00:03:37,200 With that out of the way, let's begin. 39 00:03:37,880 --> 00:03:41,200 So I hear you want to create a Pokemon scanner. 40 00:03:41,260 --> 00:03:41,660 Hello. 41 00:03:41,660 --> 00:03:43,820 So I hear you want to create a Pokemon scanner. 42 00:03:44,300 --> 00:03:47,980 And we know that the Pokemon Go app operates something like that. 43 00:03:47,980 --> 00:03:52,760 So it has to get the information that it displays in the lousy scanner. 44 00:03:52,940 --> 00:04:00,500 So it has to request data to get all the Pokemon and get back all the nearby Pokemon to its location. 45 00:04:00,500 --> 00:04:08,820 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. 46 00:04:09,180 --> 00:04:16,780 But who is to say that the app doesn't get only the information that is displayed on the lousy scanner. 47 00:04:16,780 --> 00:04:21,880 So only a list of nine Pokemon and the footprints of how far they are from you. 48 00:04:21,920 --> 00:04:23,400 Well, there are two hints. 49 00:04:23,400 --> 00:04:36,600 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. 50 00:04:36,960 --> 00:04:40,080 The second hint is that servers are lazy. 51 00:04:40,080 --> 00:04:46,920 So no one wants to do this heavy computation that has to do with determining how far a Pokemon is to you. 52 00:04:47,560 --> 00:04:52,000 And Niantic would be happy to delegate this computation to your device. 53 00:04:52,000 --> 00:04:58,800 You have a very powerful Android device or Apple device in your pocket that can do this calculation for you. 54 00:04:58,800 --> 00:05:03,840 So I'm not sure that I convinced you but I did convince myself back then and I'm happy that I did. 55 00:05:04,760 --> 00:05:09,740 And I wanted to see how to be able to do this request. 56 00:05:09,740 --> 00:05:12,640 I wanted to see how the protocol looks like. 57 00:05:12,640 --> 00:05:20,940 And to see the protocol, I have to look at the traffic that goes between the Pokemon Go app and the Pokemon Go server. 58 00:05:20,940 --> 00:05:24,640 And this is a tech called sniffing attack. 59 00:05:24,980 --> 00:05:38,380 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. 60 00:05:38,380 --> 00:05:40,300 In Android, that's pretty simple. 61 00:05:40,300 --> 00:05:52,680 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. 62 00:05:52,940 --> 00:05:55,320 I used filler classic back then. 63 00:05:55,320 --> 00:05:56,400 I still use it today. 64 00:05:56,400 --> 00:05:59,040 Call me an oldie but I really like this program. 65 00:05:59,200 --> 00:06:03,220 And this is how the real communication looks like in filler. 66 00:06:03,220 --> 00:06:14,300 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. 67 00:06:14,600 --> 00:06:20,180 And now we are able to see the communication between the app and the server and for this we get our first badge. 68 00:06:20,180 --> 00:06:21,920 The badge of sniffing. 69 00:06:23,580 --> 00:06:24,220 Okay. 70 00:06:24,220 --> 00:06:25,500 We have the communication. 71 00:06:25,500 --> 00:06:28,020 Let's dig deep into the actual protocol. 72 00:06:28,020 --> 00:06:37,720 So as you can see here, we can see the request content type that is reported by the app is actually form URL encoded. 73 00:06:37,720 --> 00:06:40,120 As you can see, it is lying. 74 00:06:40,120 --> 00:06:43,920 Because if you ever saw form URL encoded, it's textual protocol. 75 00:06:43,920 --> 00:06:47,100 And here the protocol is clearly binary. 76 00:06:47,580 --> 00:06:49,060 So what's going on? 77 00:06:49,060 --> 00:06:54,200 Let's look a bit deeper into the actual binary of the request. 78 00:06:54,200 --> 00:07:04,020 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. 79 00:07:04,320 --> 00:07:14,520 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. 80 00:07:14,520 --> 00:07:28,360 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. 81 00:07:28,420 --> 00:07:30,860 Protobuf is short for protocol buffers. 82 00:07:30,860 --> 00:07:50,340 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. 83 00:07:50,340 --> 00:07:58,980 So let's take a second and switch the screen to this very, very nice pink hue to talk about protobuf. 84 00:07:58,980 --> 00:08:10,540 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. 85 00:08:10,560 --> 00:08:12,440 We define a search request message. 86 00:08:12,440 --> 00:08:13,700 It has four fields. 87 00:08:13,700 --> 00:08:16,080 The first field is a query of type string. 88 00:08:16,080 --> 00:08:23,520 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. 89 00:08:23,680 --> 00:08:32,500 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. 90 00:08:32,620 --> 00:08:38,500 As you can see, its type is a search option so you can embed messages within other messages. 91 00:08:38,620 --> 00:08:42,820 And we don't have a declaration of a search option here and that's on purpose. 92 00:08:42,920 --> 00:08:49,320 And to use it, you use a tool, as I said, developed by Google named Proto C. 93 00:08:49,320 --> 00:08:54,900 You take this definition, you kind of compile it into your favorite language. 94 00:08:54,900 --> 00:09:03,100 For this example I compiled it into Python and then you can simply import the resulting file as you can see here. 95 00:09:04,000 --> 00:09:16,000 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. 96 00:09:16,880 --> 00:09:17,680 Good. 97 00:09:17,680 --> 00:09:21,500 So we know now about Protobuf but we have a problem. 98 00:09:21,500 --> 00:09:26,480 We see the serialized data on the wire but we don't have the original definitions. 99 00:09:26,480 --> 00:09:28,420 So what we can do about that? 100 00:09:28,420 --> 00:09:41,180 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. 101 00:09:41,180 --> 00:09:50,940 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. 102 00:09:50,940 --> 00:10:11,180 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. 103 00:10:11,820 --> 00:10:16,740 And we can even tell some things about the message that we didn't see the declaration of, right? 104 00:10:16,740 --> 00:10:19,600 You can see it has two fields, both of them are strings. 105 00:10:19,840 --> 00:10:25,280 So let's apply this technique to the actual message that we just saw for Pokemon Go. 106 00:10:25,280 --> 00:10:26,100 So here it is. 107 00:10:26,100 --> 00:10:29,060 It's very loud, you probably can't see anything but that's fine. 108 00:10:31,280 --> 00:10:46,700 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. 109 00:10:46,700 --> 00:10:51,220 Back then understanding protocol definitions was nothing short of an art. 110 00:10:51,580 --> 00:10:58,020 And I use several techniques to understand how messages look like and how the protocol works. 111 00:10:58,020 --> 00:11:05,320 I go deeper into them in my blog post but here I just cover the three main tips and tricks that I use. 112 00:11:05,320 --> 00:11:08,860 The first one is you can tell a lot about fields using their values. 113 00:11:08,860 --> 00:11:21,520 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. 114 00:11:22,300 --> 00:11:32,840 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. 115 00:11:32,840 --> 00:11:39,600 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. 116 00:11:39,600 --> 00:11:46,600 And if you would go and convert those hex encoded integers into floats, you would just see that they are coordinates. 117 00:11:46,600 --> 00:11:48,000 So this is my location. 118 00:11:49,220 --> 00:12:00,300 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. 119 00:12:00,300 --> 00:12:05,460 And using these changes I can infer a lot of information about the underlying declaration. 120 00:12:05,520 --> 00:12:06,740 I will save you all of that. 121 00:12:06,740 --> 00:12:08,900 You are welcome to go to the blog to read more. 122 00:12:08,900 --> 00:12:17,520 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. 123 00:12:17,760 --> 00:12:21,680 So how a request looks like from the Pokemon Go app. 124 00:12:22,000 --> 00:12:26,580 So it's actually, I call it a request container because it contains requests. 125 00:12:26,600 --> 00:12:43,460 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. 126 00:12:43,460 --> 00:12:49,260 Each request has a request type and optionally request bytes if it needs to. 127 00:12:49,260 --> 00:12:54,460 So here it sends three different requests, 106, 126 and 4. 128 00:12:55,280 --> 00:12:58,940 And the server response looks relatively the same. 129 00:12:58,940 --> 00:13:03,980 So it has a response container with the same request ID and a repeated response field. 130 00:13:04,100 --> 00:13:10,200 Each response corresponding to one request so it's always matching one to one according to the same order. 131 00:13:11,100 --> 00:13:19,600 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? 132 00:13:19,600 --> 00:13:21,920 That's what we wanted to do for the scanner. 133 00:13:22,020 --> 00:13:26,240 But there are tons of different types of requests. 134 00:13:26,400 --> 00:13:35,620 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. 135 00:13:35,620 --> 00:13:39,280 And what actually solved it for me is playing Pokemon. 136 00:13:39,280 --> 00:13:44,100 So if you played Pokemon, you know that all of them are indexed by an incrementing number. 137 00:13:44,560 --> 00:13:53,060 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. 138 00:13:53,060 --> 00:14:10,420 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. 139 00:14:10,420 --> 00:14:25,000 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. 140 00:14:25,000 --> 00:14:33,720 It also includes spawn points and Pokemon and more importantly it has the exact location of the specific Pokemon in this map cell. 141 00:14:33,720 --> 00:14:40,360 As you can see there is a catchable Pokemon at a very specific location and this is the Pokemon number 23. 142 00:14:40,360 --> 00:14:42,820 So who is that Pokemon? 143 00:14:43,780 --> 00:14:45,300 I hope you know it. 144 00:14:46,060 --> 00:14:57,180 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. 145 00:14:57,840 --> 00:15:01,640 So what do we know so far? 146 00:15:01,640 --> 00:15:09,840 We know that the communication, the protocol uses protobuf and the main message that is being sent is a request container. 147 00:15:09,840 --> 00:15:21,480 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. 148 00:15:21,480 --> 00:15:29,640 It gets a cell ID and responds with the exact location of Pokemon which is the best case scenario for building a scanner. 149 00:15:29,820 --> 00:15:31,980 But we still have three open questions. 150 00:15:31,980 --> 00:15:35,380 So the first one is how do you construct a request container? 151 00:15:35,380 --> 00:15:39,120 So it has complicated fields like authentication fields. 152 00:15:39,120 --> 00:15:41,520 How do you create them successfully? 153 00:15:41,660 --> 00:15:46,300 Second, there are still plenty of fields and request types that I just didn't know. 154 00:15:46,300 --> 00:15:49,160 So I called them unknown like unknown six. 155 00:15:50,500 --> 00:15:54,100 So do I need to create them in order to make a successful request? 156 00:15:54,100 --> 00:15:55,920 I don't know what they are used for. 157 00:15:55,980 --> 00:15:58,340 And lastly, what the hell is a cell ID? 158 00:15:58,340 --> 00:15:59,860 I'm used to coordinates. 159 00:15:59,860 --> 00:16:01,660 I don't know anything about cells. 160 00:16:01,680 --> 00:16:05,960 So it turns out the answer to the first two questions was actually pretty simple. 161 00:16:05,960 --> 00:16:07,620 The server just doesn't care. 162 00:16:07,900 --> 00:16:12,540 It was very, very relaxed regarding what the data that it expects in a request container. 163 00:16:12,540 --> 00:16:23,060 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. 164 00:16:23,060 --> 00:16:26,240 It didn't care about other fields that I understood. 165 00:16:26,240 --> 00:16:28,380 It didn't care about all the fields that I didn't understand. 166 00:16:28,380 --> 00:16:30,560 It didn't care about other request types. 167 00:16:30,680 --> 00:16:32,460 So best case scenario for me. 168 00:16:32,660 --> 00:16:39,660 About that cell ID, so keen eyed of you may have noticed in the previous slide, I call this an S2 cell ID. 169 00:16:39,660 --> 00:16:44,140 It turns out Pokemon Go uses a framework named S2 cells. 170 00:16:44,140 --> 00:16:48,360 It splits a sphere, in this case the earth, into cells. 171 00:16:48,500 --> 00:16:53,020 You decide on a level which basically controls the size of a specific cell. 172 00:16:53,020 --> 00:16:57,500 Pokemon Go works with at least get map object works with level 15. 173 00:16:57,940 --> 00:17:20,360 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. 174 00:17:20,460 --> 00:17:25,140 So with all the questions answered, I went and created a Pokemon scanner. 175 00:17:25,140 --> 00:17:27,200 This is my code from back there. 176 00:17:27,340 --> 00:17:28,560 A very nice code. 177 00:17:28,560 --> 00:17:31,200 I'm sure you can see for yourself. 178 00:17:31,980 --> 00:17:35,020 It gets authentication info from Google. 179 00:17:35,020 --> 00:17:39,720 It constructs a request container with authentication info, request identifier. 180 00:17:40,200 --> 00:17:44,440 So it starts on with a specific location basically all around me. 181 00:17:44,440 --> 00:17:48,700 I scan like a radius of a few miles. 182 00:17:49,480 --> 00:18:05,560 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. 183 00:18:06,280 --> 00:18:14,480 And dumb me, I didn't really record any of the actual maps that I built with Pokemon from back there. 184 00:18:14,480 --> 00:18:18,760 I only actually had this one picture of a log that I had. 185 00:18:18,760 --> 00:18:24,140 And you can tell that it's not fake and real because I had to blur out my actual location. 186 00:18:24,300 --> 00:18:26,200 So that's my only proof to you. 187 00:18:26,200 --> 00:18:30,160 But this is an example log from the scanner that searches for different Pokemon. 188 00:18:30,160 --> 00:18:32,200 I think it found a Pidgey. 189 00:18:32,740 --> 00:18:34,000 And it was great. 190 00:18:34,000 --> 00:18:35,880 I flexed on all my friends. 191 00:18:35,880 --> 00:18:37,060 I found all the cool Pokemon. 192 00:18:37,060 --> 00:18:39,960 I used it for a couple of weeks. 193 00:18:40,160 --> 00:18:45,980 And upon successfully creating a Pokemon scanner, we get our third badge, the badge of Pokemon. 194 00:18:47,320 --> 00:18:56,320 So one quiet Wednesday I got back home and I started my Pokemon scanner to play a nice evening of Pokemon Go. 195 00:18:56,320 --> 00:18:59,440 Only to discover that it didn't work. 196 00:19:00,300 --> 00:19:05,380 So my scanner got like a generic error that I really didn't understand. 197 00:19:05,380 --> 00:19:11,600 So naturally I opened up Fiddler, my HTTP proxy, to see how the information, how the protocol looks like. 198 00:19:11,600 --> 00:19:16,280 I knew that a few days earlier a new update was pushed to the app. 199 00:19:16,280 --> 00:19:22,200 Maybe something, some stuff in the protocol has changed and I needed to update my scanner. 200 00:19:22,620 --> 00:19:25,740 And Fiddler didn't record anything. 201 00:19:25,740 --> 00:19:32,960 And in fact, while it was open, the Pokemon Go app refused to turn on and refused to do anything. 202 00:19:33,820 --> 00:19:36,180 So okay, we have a challenge . 203 00:19:36,180 --> 00:19:37,880 We have a fighter on hand. 204 00:19:38,320 --> 00:19:44,040 So naturally I went online to search if anyone else has encountered this problem. 205 00:19:44,040 --> 00:19:50,120 And I realized that I wasn't the only smart guy in the room that decided to build their own Pokemon scanner. 206 00:19:50,120 --> 00:19:55,240 There were actually many different communities online doing this stuff. 207 00:19:55,240 --> 00:20:02,420 One in particular was PogoDev, a community dedicated to creating unofficial API for Pokemon Go. 208 00:20:02,460 --> 00:20:07,800 They had noticed this issue as well and started tackling it. 209 00:20:07,800 --> 00:20:17,300 And in fact I found that their administrator had actually put up a Reddit post saying, well, we know our API is down. 210 00:20:17,300 --> 00:20:19,340 Something has changed in the app. 211 00:20:19,340 --> 00:20:23,580 We've created a Discord server to coordinate efforts around this. 212 00:20:23,580 --> 00:20:25,440 So naturally I went on the Discord server. 213 00:20:25,440 --> 00:20:31,220 I joined the internal hacking channel and we started working towards solving this. 214 00:20:31,220 --> 00:20:47,620 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. 215 00:20:47,720 --> 00:20:52,520 I will make sure to, and we used various techniques to overcome these issues. 216 00:20:52,520 --> 00:20:55,120 I will make sure to stop when I introduce a new technique. 217 00:20:55,120 --> 00:20:55,940 I will name it. 218 00:20:55,940 --> 00:20:57,260 I will explain how it works. 219 00:20:57,260 --> 00:21:00,260 And then we can see how we used it to overcome the defenses. 220 00:21:00,480 --> 00:21:05,640 On top of the title you can see the timeline. 221 00:21:05,640 --> 00:21:07,400 So this started around 1 a.m. 222 00:21:07,400 --> 00:21:08,680 in the first day. 223 00:21:08,680 --> 00:21:12,820 So you can follow along how long it took us to do every step. 224 00:21:13,620 --> 00:21:22,240 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. 225 00:21:22,960 --> 00:21:33,760 And we thought, and actually one researcher found this interesting class was added to the Pokemon Go app named Niantic trust manager. 226 00:21:34,080 --> 00:21:44,360 And so it implemented a check server trusted function which seems like it implements a defense called certificate pinning. 227 00:21:44,500 --> 00:21:52,120 And to understand how we overcome it, we first need to understand why it works against HTTP proxies and basically blocks their behavior. 228 00:21:52,120 --> 00:21:54,920 We need to talk a little bit about HTTP proxy. 229 00:21:54,920 --> 00:21:59,560 So here you can see a very, very high level overview of how HTTP proxy works. 230 00:22:01,720 --> 00:22:09,740 Basically, normally when you work with HTTPS, the client communicates with the server in an encrypted form. 231 00:22:09,740 --> 00:22:11,460 That's what the S stands for. 232 00:22:11,460 --> 00:22:12,400 Secure. 233 00:22:12,600 --> 00:22:17,600 Based on a certificate that is provided to the server to the client. 234 00:22:17,660 --> 00:22:21,600 And besides confidentiality, HTTPS also promises you integrity. 235 00:22:21,600 --> 00:22:28,740 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. 236 00:22:29,280 --> 00:22:31,920 But that's exactly what HTTP proxy needs to do. 237 00:22:31,920 --> 00:22:42,100 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. 238 00:22:42,100 --> 00:22:44,720 So it works because you own the client. 239 00:22:44,720 --> 00:22:59,800 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. 240 00:22:59,800 --> 00:23:04,180 This is how the certificate of filler looks like on my Windows machine. 241 00:23:04,180 --> 00:23:05,820 It works the same way for Android. 242 00:23:05,820 --> 00:23:08,620 I was too lazy to pull it up from my machine. 243 00:23:10,040 --> 00:23:10,540 Okay. 244 00:23:10,540 --> 00:23:12,780 So now we understand how this works. 245 00:23:12,780 --> 00:23:15,760 So how do certificate pinning works? 246 00:23:15,760 --> 00:23:27,400 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. 247 00:23:27,480 --> 00:23:31,460 And what the application does, it wants a new session of HTTPS starts. 248 00:23:31,460 --> 00:23:36,740 It verifies that the public key of the server matches the public key that is embedded in the code. 249 00:23:36,740 --> 00:23:51,580 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. 250 00:23:51,940 --> 00:23:53,200 So how do we overcome it? 251 00:23:53,200 --> 00:23:57,560 We have to use a new technique that I call dynamic reverse engineering. 252 00:23:57,560 --> 00:23:58,940 So we have to learn it. 253 00:24:01,340 --> 00:24:10,160 So what dynamic reverse engineering means is intervening in the running code of an application and basically changing stuff on the way. 254 00:24:10,160 --> 00:24:18,060 You can think about it similarly to developing code and debugging it and changing values while it is debugging, only automatically. 255 00:24:18,180 --> 00:24:22,660 And there are a few frameworks that allows you to do it for Android in particular. 256 00:24:22,660 --> 00:24:31,900 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. 257 00:24:31,900 --> 00:24:34,240 So we wrote this short exposed model. 258 00:24:34,240 --> 00:24:35,720 It is actually very short. 259 00:24:35,720 --> 00:24:39,880 I just removed the original change because it is very long. 260 00:24:39,880 --> 00:24:54,600 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. 261 00:24:54,600 --> 00:24:58,500 That's a good way to find certificate pinning if you ever want to do so. 262 00:24:58,760 --> 00:25:01,480 We took the original chain from the actual server. 263 00:25:01,480 --> 00:25:02,100 This is public. 264 00:25:02,100 --> 00:25:03,420 It is very easy to get. 265 00:25:03,420 --> 00:25:06,960 And what we do is we did a before hook. 266 00:25:06,960 --> 00:25:15,820 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. 267 00:25:15,840 --> 00:25:22,300 So that way the app always thinks it interacts with the actual server even though it is not. 268 00:25:22,320 --> 00:25:24,560 So we fool it that way. 269 00:25:25,500 --> 00:25:30,100 So this allowed us to see the traffic again. 270 00:25:30,140 --> 00:25:32,180 And what we saw kind of surprised us. 271 00:25:32,180 --> 00:25:34,220 We saw that nothing changed. 272 00:25:34,220 --> 00:25:38,100 So all the protocol looked exactly the same as it was before. 273 00:25:39,560 --> 00:25:41,740 So what was the problem? 274 00:25:42,200 --> 00:25:53,740 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. 275 00:25:53,740 --> 00:26:01,440 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. 276 00:26:01,580 --> 00:26:07,300 So to figure out the specific field, we had to use a second technique that I call active probing. 277 00:26:07,300 --> 00:26:19,720 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. 278 00:26:19,720 --> 00:26:27,060 So what we did is we basically started removing fields that we knew were optional one by one until the server returned an error. 279 00:26:27,080 --> 00:26:37,080 And that way we actually found a specific field, the sixth field of the request container became required which was optional before. 280 00:26:38,360 --> 00:26:44,760 And so we did know a bit about the format of the sixth field. 281 00:26:44,760 --> 00:26:46,760 We called it unknown six. 282 00:26:46,780 --> 00:26:55,320 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. 283 00:26:55,320 --> 00:27:05,800 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. 284 00:27:05,800 --> 00:27:11,280 So we called ourselves team unknown six and we focused on cracking this. 285 00:27:12,020 --> 00:27:16,120 So starting off, we wanted to know more about unknown six and how it looks like. 286 00:27:16,120 --> 00:27:21,940 And to do this, we'll use our third technique which is kind of like the counterpart to the active probing. 287 00:27:21,940 --> 00:27:23,640 I call this passive analysis. 288 00:27:23,640 --> 00:27:26,600 Passive analysis was also used for the Pokemon scanner. 289 00:27:26,620 --> 00:27:36,240 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. 290 00:27:36,260 --> 00:27:41,400 Looking at all these requests, you can infer a lot of details about how the protocol works. 291 00:27:41,480 --> 00:27:46,660 So what we did, we generated a bunch of unknown six examples. 292 00:27:46,660 --> 00:27:48,000 This is one specific example. 293 00:27:48,000 --> 00:27:51,840 As you can see, most of the information is within the one field over there. 294 00:27:51,840 --> 00:27:54,980 I'll just call this unknown six for short. 295 00:27:55,340 --> 00:28:00,200 And we noticed something peculiar from all of these samples. 296 00:28:00,200 --> 00:28:03,500 The size of this unknown six. 297 00:28:03,640 --> 00:28:11,740 So it turned out that the size of this was always a multiple of 256, one of my favorite numbers, plus 32. 298 00:28:11,740 --> 00:28:18,740 So the size of this is just one block of 256 and 32, so 288 tokens. 299 00:28:18,740 --> 00:28:19,400 So it's a bit peculiar. 300 00:28:20,860 --> 00:28:31,520 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. 301 00:28:31,520 --> 00:28:38,000 And he noticed that all of the samples of unknown six that he generated began with the same 32 bytes. 302 00:28:38,000 --> 00:28:47,420 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. 303 00:28:47,420 --> 00:28:58,160 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. 304 00:28:58,160 --> 00:29:03,440 Which means that this unknown six is strongly tied to the request we make. 305 00:29:03,440 --> 00:29:14,980 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. 306 00:29:14,980 --> 00:29:26,760 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. 307 00:29:27,460 --> 00:29:37,900 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. 308 00:29:38,280 --> 00:29:43,520 And we knew that everything that has to do with protobuf is actually in the native part of the application. 309 00:29:44,320 --> 00:29:45,640 So let me stop for a second. 310 00:29:45,640 --> 00:29:51,040 I speak a lot about the Java part of the application and the native part of the application, so let me explain. 311 00:29:51,180 --> 00:29:53,940 An Android application is basically split into two parts. 312 00:29:53,940 --> 00:30:00,660 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. 313 00:30:01,100 --> 00:30:11,160 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. 314 00:30:11,380 --> 00:30:12,960 This is an interface between them. 315 00:30:12,960 --> 00:30:18,220 Actually the certificate pinning called, it was a Java class that was calling a native part. 316 00:30:18,220 --> 00:30:30,020 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. 317 00:30:30,020 --> 00:30:32,820 Specifically Pokemon Go I think relies on unity. 318 00:30:34,600 --> 00:30:39,440 Okay, so what do you do with the Java part and the native part? 319 00:30:39,440 --> 00:30:51,000 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. 320 00:30:51,040 --> 00:31:02,240 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. 321 00:31:02,400 --> 00:31:05,020 These programs basically do the other way around. 322 00:31:05,020 --> 00:31:17,560 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. 323 00:31:18,460 --> 00:31:20,640 With Java we have Jadix. 324 00:31:20,640 --> 00:31:23,260 It's an amazing tool. 325 00:31:23,260 --> 00:31:24,260 It does an excellent job. 326 00:31:24,260 --> 00:31:34,140 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. 327 00:31:34,140 --> 00:31:42,440 It does an excellent job reflecting back the byte code of Java into the actual code as close as possible to the original. 328 00:31:42,600 --> 00:31:47,780 And it's relatively easy because Java is only compiled into an intermediate language. 329 00:31:48,000 --> 00:31:52,400 When it comes to native code this is a bit harder and you have to use different tools. 330 00:31:52,600 --> 00:31:54,020 This is an example from Ida. 331 00:31:54,020 --> 00:31:56,680 Today we have Gidra which is also a great tool. 332 00:31:57,080 --> 00:31:59,380 They basically show you the actual assembly. 333 00:32:00,060 --> 00:32:11,900 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. 334 00:32:11,900 --> 00:32:30,920 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. 335 00:32:31,920 --> 00:32:38,120 So we knew, as I said, we knew that everything related to protobuf including creation of unknown 6 is in the native part. 336 00:32:38,140 --> 00:32:41,640 Specifically in a library named Lib Niantic manager. 337 00:32:41,640 --> 00:32:49,140 So we opened it in Ida and we had to pinpoint the actual function that generates unknown 6. 338 00:32:49,160 --> 00:32:51,080 And there were a few methods to do it. 339 00:32:51,080 --> 00:32:54,320 I think I laid down three different methods in my blog. 340 00:32:54,320 --> 00:32:57,880 Here I will only share one method due to a lack of time. 341 00:32:57,880 --> 00:32:59,760 This was the method that I used. 342 00:32:59,800 --> 00:33:12,960 If you recall, using static analysis, we found that the starting bytes of the unknown 6 message are only dependent on time. 343 00:33:12,960 --> 00:33:18,220 So naturally the code that generates unknown 6 has to rely on time somehow. 344 00:33:18,220 --> 00:33:27,160 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. 345 00:33:27,280 --> 00:33:32,400 So I went to Ida, to the import table, and I did find the time function being imported. 346 00:33:32,480 --> 00:33:39,380 And I looked at all the cross references meaning all the locations in the assembly in the library that calls time. 347 00:33:39,380 --> 00:33:40,360 I found two. 348 00:33:40,360 --> 00:33:42,520 The bottom one wasn't related at all. 349 00:33:42,520 --> 00:33:43,800 It was very easy to see. 350 00:33:43,800 --> 00:33:48,520 The top one, the function at offset 87444, I can't even see it. 351 00:33:48,520 --> 00:33:49,640 I remember it. 352 00:33:50,640 --> 00:34:00,560 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. 353 00:34:00,560 --> 00:34:04,240 Then this function generates 32 random bytes. 354 00:34:04,240 --> 00:34:16,680 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. 355 00:34:16,680 --> 00:34:18,620 And for this, we get our fourth badge. 356 00:34:18,620 --> 00:34:20,160 Badge of unknown 6. 357 00:34:21,260 --> 00:34:22,220 Okay. 358 00:34:22,560 --> 00:34:27,300 So at this point, we looked at a specific function that we pinpointed. 359 00:34:27,300 --> 00:34:32,200 We called it sig encrypt function because we believe it encrypts a signature. 360 00:34:32,200 --> 00:34:33,600 It was only natural. 361 00:34:34,080 --> 00:34:41,020 And we decided to verify beyond doubt that it's exactly the function that we wanted to generate unknown 6. 362 00:34:41,020 --> 00:34:48,280 So we used active probing again, excuse me, dynamic reverse engineering again to detect that. 363 00:34:48,340 --> 00:34:51,560 This time, instead of exposed, we used Frida. 364 00:34:51,560 --> 00:34:59,360 Frida is a very, very powerful tool that allows you to basically hook using JavaScript any function that you want. 365 00:34:59,360 --> 00:35:01,600 It works on Windows, Linux, Android. 366 00:35:02,220 --> 00:35:03,500 It's very strong for Android. 367 00:35:03,500 --> 00:35:09,160 Here you can see a short Frida script that basically finds the ‑‑ so it hooks on the native library. 368 00:35:09,160 --> 00:35:13,900 It finds the actual address of the function that we wanted, offset 87444. 369 00:35:13,900 --> 00:35:19,480 It hooks both the enter of the function, so every time it runs, and the return. 370 00:35:19,480 --> 00:35:22,140 And simply dumps the input and the output. 371 00:35:22,140 --> 00:35:36,540 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. 372 00:35:37,340 --> 00:35:50,820 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. 373 00:35:50,820 --> 00:35:52,720 So I heard you like port above. 374 00:35:53,180 --> 00:35:56,400 And it's a very, very long object. 375 00:35:56,540 --> 00:36:02,720 And there are some interesting strings there, like one plus that was my device back then. 376 00:36:03,560 --> 00:36:07,920 And it looked like field that was supposed to be in the signature, so we had that. 377 00:36:07,920 --> 00:36:17,920 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. 378 00:36:17,920 --> 00:36:19,880 And it turned out to be quite simple. 379 00:36:19,880 --> 00:36:22,360 So I will be able to show you this today. 380 00:36:22,360 --> 00:36:26,880 Here you can see the decompiled version of the sig encrypt function. 381 00:36:27,480 --> 00:36:30,600 And let's start with an input of length 700. 382 00:36:30,600 --> 00:36:33,120 I split it into 256 chunks. 383 00:36:33,120 --> 00:36:38,040 The less chunks is a shorter one, just for easier understanding. 384 00:36:38,180 --> 00:36:47,560 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. 385 00:36:47,560 --> 00:36:51,240 So that's the 32 bytes that we saw in the final version. 386 00:36:51,700 --> 00:36:57,040 Then it pads the input to the next closest block of 256. 387 00:36:57,420 --> 00:37:04,540 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. 388 00:37:04,540 --> 00:37:06,220 And this is not the interesting part. 389 00:37:06,220 --> 00:37:07,440 This is the interesting part. 390 00:37:07,440 --> 00:37:08,480 We have encryption. 391 00:37:08,480 --> 00:37:12,400 So we have encryption at offset 9E9D8. 392 00:37:12,420 --> 00:37:14,120 This is the encryption function. 393 00:37:14,240 --> 00:37:23,440 And first the function starts by expanding the seed into a block of 256 using an expansion mechanism. 394 00:37:23,700 --> 00:37:25,500 And then encryption works. 395 00:37:25,560 --> 00:37:36,520 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. 396 00:37:36,520 --> 00:37:52,120 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. 397 00:37:52,380 --> 00:37:54,060 And this is nothing proprietary. 398 00:37:54,060 --> 00:38:03,060 This is a very well-known cryptographic scheme named CBC mode that has to do with encrypting blocks based on initialization vector. 399 00:38:03,580 --> 00:38:07,880 So now that we know how the sync and encrypt function works, we split into two groups. 400 00:38:07,880 --> 00:38:17,600 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. 401 00:38:17,600 --> 00:38:27,300 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. 402 00:38:28,040 --> 00:38:33,220 And actually, I think it was five hours later, the first group already succeeded. 403 00:38:33,220 --> 00:38:34,580 They were very, very good. 404 00:38:34,780 --> 00:38:37,920 And replicating and getting the encryption to work. 405 00:38:37,920 --> 00:38:39,460 So how did they do it? 406 00:38:39,560 --> 00:38:47,880 They were very smart and they walked through the entire call chain of the encryption whatever numbers that came afterwards. 407 00:38:47,880 --> 00:39:11,280 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 408 00:39:11,280 --> 00:39:20,660 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. 409 00:39:21,180 --> 00:39:28,140 And for successfully replicating the encryption function, we get our fifth badge, the badge of encryption. 410 00:39:30,320 --> 00:39:38,800 So meanwhile, the second group that I was a part of actually focused on understanding how the signature works. 411 00:39:38,800 --> 00:39:46,880 So there are a few subfields within the signature message that were very easy to understand according to the values in the field. 412 00:39:46,880 --> 00:39:47,880 And you saw them earlier. 413 00:39:47,880 --> 00:40:03,700 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. 414 00:40:04,460 --> 00:40:11,060 And actually the third message that we found, we understood what it means quite funnily. 415 00:40:11,060 --> 00:40:23,100 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. 416 00:40:23,160 --> 00:40:26,540 So we understood that it contained sense of information. 417 00:40:26,540 --> 00:40:30,280 Obviously emulators don't have any sense of information, real devices does. 418 00:40:31,460 --> 00:40:36,920 It contains a lot of information regarding acceleration, altitude, gravity, etc. 419 00:40:37,480 --> 00:40:48,360 And actually at this point, so this is how the signature declaration looked like at the time, what we understood so far. 420 00:40:49,020 --> 00:40:56,140 And inclusion of fields like this field, like the sensor info field, actually something before that. 421 00:40:56,420 --> 00:41:04,740 So people that were using active probing to understand things about the signature protobuf, started getting their account banned. 422 00:41:05,280 --> 00:41:18,480 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. 423 00:41:18,520 --> 00:41:25,140 And if you consider things like sensor info, this is kind of akin to tracking your mouse movement for captures. 424 00:41:25,420 --> 00:41:33,740 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. 425 00:41:34,000 --> 00:41:40,160 But this thought also made us wonder, does the server actually verify this? 426 00:41:40,160 --> 00:41:47,320 So to verify things like sensor information based on previous sensor information is a very , very difficult computational job. 427 00:41:47,320 --> 00:41:51,460 And we knew that the servers were under high load at the time. 428 00:41:51,460 --> 00:41:56,360 So we thought, well, maybe not all fields in the signature are necessary. 429 00:41:56,360 --> 00:42:02,720 So we employed active probing again using dynamic reverse engineering, using Frida. 430 00:42:02,720 --> 00:42:10,080 We started removing fields from the signature before it was encrypted and seeing when the server starts responding with an error. 431 00:42:10,080 --> 00:42:13,820 And we found out that most of the signature was not needed. 432 00:42:14,040 --> 00:42:18,260 So all the fields that you can see that are marked with not required, were not required. 433 00:42:18,580 --> 00:42:21,000 And actually only six fields were required. 434 00:42:21,000 --> 00:42:22,600 All of these highlighted here. 435 00:42:22,600 --> 00:42:26,480 Two of which were just regular time stamps, which were very simple. 436 00:42:26,480 --> 00:42:29,540 So we were left with just four fields to go. 437 00:42:29,960 --> 00:42:33,980 Field 10, field 20, field 22 and field 24. 438 00:42:34,640 --> 00:42:37,920 At this point, I recall, the discord was going crazy. 439 00:42:37,920 --> 00:42:43,580 So here we are at the end of the second day of the hackathon and we were very tired at the time. 440 00:42:43,920 --> 00:43:00,200 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. 441 00:43:00,220 --> 00:43:05,960 And another thing that happened, so we had this channel named RE research, which all the hackers were a part of. 442 00:43:06,200 --> 00:43:10,660 And eventually, because people kept asking, it was open to the public. 443 00:43:10,660 --> 00:43:12,900 But only for view, not for chatting. 444 00:43:12,900 --> 00:43:14,580 So only we were able to chat. 445 00:43:14,580 --> 00:43:22,680 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. 446 00:43:22,680 --> 00:43:26,440 It was a very humbling experience, I can say. 447 00:43:26,800 --> 00:43:28,880 But it was very, very crazy. 448 00:43:29,140 --> 00:43:47,220 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, 449 00:43:47,220 --> 00:43:49,660 which kind of looks like a hashing function. 450 00:43:49,880 --> 00:43:56,420 And we found that field 20 was a very simple hash of this number. 451 00:43:56,420 --> 00:43:58,580 We don't know what it means to this day. 452 00:43:58,580 --> 00:44:00,040 If you know, please approach me. 453 00:44:00,040 --> 00:44:01,400 I would be happy to know. 454 00:44:01,960 --> 00:44:06,560 And the string of your location chained together . 455 00:44:07,240 --> 00:44:11,140 And the output of the function was inserted in the field 20. 456 00:44:11,140 --> 00:44:13,840 Field 10 was a bit more complicated, but not so much. 457 00:44:13,840 --> 00:44:22,900 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. 458 00:44:22,900 --> 00:44:29,120 So we have two hashes, both on the location of the user, one of which is also on the dedication info. 459 00:44:31,620 --> 00:44:34,080 So at this point we tried to understand what's the hash. 460 00:44:34,080 --> 00:44:38,940 And one technique to do it is to look at the constants being used in the hash and comparing them to known hashes. 461 00:44:38,940 --> 00:44:43,120 Using this we very easily found that it's a very famous hash named XX hash. 462 00:44:43,140 --> 00:44:45,460 And this was a 32-bit version of it. 463 00:44:45,460 --> 00:44:48,000 We also found a 64-bit version of it. 464 00:44:48,000 --> 00:44:50,500 And it was actually used for field 24. 465 00:44:50,500 --> 00:44:54,840 So field 24 was a repeated field, at least as you can see from this. 466 00:44:54,980 --> 00:45:04,460 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. 467 00:45:04,600 --> 00:45:08,120 And it was the hashing, the hash was added to field 24. 468 00:45:08,120 --> 00:45:11,260 So field 24 contained as many hashes as you had requests. 469 00:45:11,300 --> 00:45:14,440 So for this example you had three hashes in field 24. 470 00:45:14,640 --> 00:45:18,800 And then we had the last field, the final field, the toughest nuts to crack. 471 00:45:18,800 --> 00:45:26,080 We actually went in the wrong direction for a while because we saw that it changes frequently when your dedication info changes. 472 00:45:27,000 --> 00:45:29,500 But it turned out to be completely false. 473 00:45:29,500 --> 00:45:35,880 One researcher found that the function that generates this field didn't get any input. 474 00:45:36,180 --> 00:45:40,680 So this field could be basically any thing. 475 00:45:40,880 --> 00:45:44,380 And once we tried to do it, we at 7 p.m. 476 00:45:44,380 --> 00:45:51,240 the third day, 67 hours after the hackathon started, we finally managed to make our first successful API request. 477 00:45:51,260 --> 00:45:54,600 And for this we get our final badge, the badge of API. 478 00:45:56,400 --> 00:45:57,440 Thank you. 479 00:45:58,260 --> 00:45:59,640 I'll just take one minute. 480 00:46:00,260 --> 00:46:07,740 One minute to talk about, so I was very interested to, so this is my code from back there that implements the actual authentication. 481 00:46:07,740 --> 00:46:10,400 You can laugh at it while I talk for the last minute. 482 00:46:11,040 --> 00:46:14,020 I was kind of interested to know what happened afterwards. 483 00:46:14,020 --> 00:46:22,560 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. 484 00:46:22,560 --> 00:46:30,680 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. 485 00:46:31,480 --> 00:46:35,600 And I was interested to know where the Pokemon Go hacking scene went from this. 486 00:46:35,600 --> 00:46:39,460 So I kind of didn't get involved into more stuff afterwards. 487 00:46:39,460 --> 00:46:46,420 So Pocodev continued maintaining their API for about a year and a half after this, after which they stopped. 488 00:46:46,560 --> 00:46:48,100 Today I search online. 489 00:46:48,100 --> 00:46:50,900 There's also a couple of bots that are offered for cash. 490 00:46:51,300 --> 00:47:00,500 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. 491 00:47:02,360 --> 00:47:07,760 I'll just like to thank both the team, Anon8, they were amazing guys. 492 00:47:07,760 --> 00:47:09,540 I had fun to work with them. 493 00:47:09,540 --> 00:47:13,740 I would also like EFF for supporting me and counseling me on giving this talk today. 494 00:47:13,740 --> 00:47:15,580 If not for them, I was not here. 495 00:47:15,580 --> 00:47:17,560 I will also thank you for coming. 496 00:47:17,920 --> 00:47:19,780 And there's a reference slide. 497 00:47:19,780 --> 00:47:21,620 Feel free to come, grab some stickers. 498 00:47:21,620 --> 00:47:22,620 Thank you for listening.