1
+ #!/usr/bin/env python
1
2
import requests
2
3
import re
3
4
import struct
4
5
import json
5
6
import argparse
6
7
import pokemon_pb2
7
8
9
+ from gpsoauth import perform_master_login , perform_oauth
8
10
from datetime import datetime
9
11
from geopy .geocoders import GoogleV3
10
12
from requests .packages .urllib3 .exceptions import InsecureRequestWarning
26
28
COORDS_LONGITUDE = 0
27
29
COORDS_ALTITUDE = 0
28
30
31
+ ANDROID_ID = '9774d56d682e549c'
32
+ SERVICE = 'audience:server:client_id:848232511240-7so421jotr2609rmqakceuu1luuq0ptb.apps.googleusercontent.com'
33
+ APP = 'com.nianticlabs.pokemongo'
34
+ CLIENT_SIG = '321187995bc7cdc2b5fc91b11a96e2baa8602c62'
35
+
29
36
def f2i (float ):
30
37
return struct .unpack ('<Q' , struct .pack ('<d' , float ))[0 ]
31
38
@@ -52,7 +59,7 @@ def set_location_coords(lat, long, alt):
52
59
def get_location_coords ():
53
60
return (COORDS_LATITUDE , COORDS_LONGITUDE , COORDS_ALTITUDE )
54
61
55
- def api_req (api_endpoint , access_token , req ):
62
+ def api_req (service , api_endpoint , access_token , req ):
56
63
try :
57
64
p_req = pokemon_pb2 .RequestEnvelop ()
58
65
p_req .unknown1 = 2
@@ -63,7 +70,7 @@ def api_req(api_endpoint, access_token, req):
63
70
p_req .latitude , p_req .longitude , p_req .altitude = get_location_coords ()
64
71
65
72
p_req .unknown12 = 989
66
- p_req .auth .provider = 'ptc'
73
+ p_req .auth .provider = service
67
74
p_req .auth .token .contents = access_token
68
75
p_req .auth .token .unknown13 = 59
69
76
protobuf = p_req .SerializeToString ()
@@ -79,7 +86,7 @@ def api_req(api_endpoint, access_token, req):
79
86
return None
80
87
81
88
82
- def get_api_endpoint (access_token ):
89
+ def get_api_endpoint (service , access_token ):
83
90
req = pokemon_pb2 .RequestEnvelop ()
84
91
85
92
req1 = req .requests .add ()
@@ -94,25 +101,33 @@ def get_api_endpoint(access_token):
94
101
req5 .type = 5
95
102
req5 .message .unknown4 = "4a2e9bc330dae60e7b74fc85b98868ab4700802e"
96
103
97
- p_ret = api_req (API_URL , access_token , req .requests )
104
+ p_ret = api_req (service , API_URL , access_token , req .requests )
98
105
99
106
try :
100
107
return ('https://%s/rpc' % p_ret .api_url )
101
108
except :
102
109
return None
103
110
104
111
105
- def get_profile (api_endpoint , access_token ):
112
+ def get_profile (service , api_endpoint , access_token ):
106
113
req = pokemon_pb2 .RequestEnvelop ()
107
114
108
115
req1 = req .requests .add ()
109
116
req1 .type = 2
110
117
111
- return api_req (api_endpoint , access_token , req .requests )
118
+ return api_req (service , api_endpoint , access_token , req .requests )
119
+
120
+
121
+ def login_google (username , password ):
122
+ print ('[!] Google login for: {}' .format (username ))
123
+ r1 = perform_master_login (username , password , ANDROID_ID )
124
+ r2 = perform_oauth (username , r1 .get ('Token' , '' ), ANDROID_ID , SERVICE , APP ,
125
+ CLIENT_SIG )
112
126
127
+ return r2 .get ('Auth' ) # access token
113
128
114
129
def login_ptc (username , password ):
115
- print ('[!] login for: {}' .format (username ))
130
+ print ('[!] PTC login for: {}' .format (username ))
116
131
head = {'User-Agent' : 'niantic' }
117
132
r = SESSION .get (LOGIN_URL , headers = head )
118
133
jdata = json .loads (r .content )
@@ -149,14 +164,20 @@ def login_ptc(username, password):
149
164
150
165
def main ():
151
166
parser = argparse .ArgumentParser ()
152
- parser .add_argument ("-u" , "--username" , help = "PTC Username" , required = True )
153
- parser .add_argument ("-p" , "--password" , help = "PTC Password" , required = True )
167
+ parser .add_argument ("-a" , "--auth_service" , help = "Auth Service" ,
168
+ required = True )
169
+ parser .add_argument ("-u" , "--username" , help = "Username" , required = True )
170
+ parser .add_argument ("-p" , "--password" , help = "Password" , required = True )
154
171
parser .add_argument ("-l" , "--location" , help = "Location" , required = True )
155
172
parser .add_argument ("-d" , "--debug" , help = "Debug Mode" , action = 'store_true' )
156
173
parser .add_argument ("-s" , "--client_secret" , help = "PTC Client Secret" )
157
174
parser .set_defaults (DEBUG = True )
158
175
args = parser .parse_args ()
159
176
177
+ if args .auth_service not in ['ptc' , 'google' ]:
178
+ print ('[!] Invalid Auth service specified' )
179
+ return
180
+
160
181
if args .debug :
161
182
global DEBUG
162
183
DEBUG = True
@@ -168,19 +189,23 @@ def main():
168
189
169
190
set_location (args .location )
170
191
171
- access_token = login_ptc (args .username , args .password )
192
+ if args .auth_service == 'ptc' :
193
+ access_token = login_ptc (args .username , args .password )
194
+ else :
195
+ access_token = login_google (args .username , args .password )
196
+
172
197
if access_token is None :
173
198
print ('[-] Wrong username/password' )
174
199
return
175
200
print ('[+] RPC Session Token: {} ...' .format (access_token [:25 ]))
176
201
177
- api_endpoint = get_api_endpoint (access_token )
202
+ api_endpoint = get_api_endpoint (args . auth_service , access_token )
178
203
if api_endpoint is None :
179
204
print ('[-] RPC server offline' )
180
205
return
181
206
print ('[+] Received API endpoint: {}' .format (api_endpoint ))
182
207
183
- profile = get_profile (api_endpoint , access_token )
208
+ profile = get_profile (args . auth_service , api_endpoint , access_token )
184
209
if profile is not None :
185
210
print ('[+] Login successful' )
186
211
0 commit comments