-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws.py
319 lines (223 loc) · 11.5 KB
/
ws.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
import websocket
import threading
import _thread
import uuid
import time
import qrcode
import requests
import base64
import jwt
from xml.dom import minidom
import json
import argparse
import signal
class Auth:
def __init__(self):
self.timeout_scan = 30
self.status = 0
self.clientId = ""
self.token = ""
def web_client_start(self):
endpoint = '''https://grindr.mobi/v4/web-clients'''
params = {}
headers = {'User-Agent': 'Firefox 69'}
r = requests.post(url = endpoint, params = params, headers = headers)
raw = r.json()
qrdata = "grindrwebchat_"+str(raw["webClientId"])
self.clientId = str(raw["webClientId"])
#print("Request: "+qrdata)
q = qrcode.QRCode()
q.add_data(qrdata)
q.make()
q.print_ascii()
print("Escanea este QR desde Grindr", end="", flush=True)
self.status = 1
def token_decode(self, token):
token_data = jwt.decode(token,verify=False, algorithms=['HS256'])
self.profileId = token_data["profileId"]
self.exp = token_data["exp"]
#Hay otros campos pero no les veo la utilidad, ej:
# {'features': ['DiscreetIcon', 'PINLock', 'VideoCallDailyFree', 'CreateVideoCall', 'WebChat'], 'profileId': '2******3', 'roles': [], 'exp': 1583344096}
def wait_scanned(self):
endpoint = '''https://grindr.mobi/v4/authtokens/web/'''+self.clientId
for i in range(self.timeout_scan):
r = requests.get(url = endpoint)
time.sleep(1)
if r.status_code == 200:
print('OK!')
self.token = r.json()["authtoken"]
self.status = 3
self.token_decode(self.token)
return True
elif r.status_code == 404:
print('.', end="", flush=True)
self.status = 2
self.status = 4
return False
'''class ChatSync:
wss://chatsync.grindr.com/session/websocket?profile_id=[profileId]&token=[token]&type=web
class Grid:
# To be decoded
# https://grindr.mobi/v4/locations/ezjmg1f7y05n/profiles?myType=true&online=false&faceOnly=false&photoOnly=false¬RecentlyChatted=false&ageMaximum=37&weightMaximum=118000&heightMaximum=186&grindrTribesIds=5&bodyTypeIds=4&sexualPositionIds=4ðnicityIds=4&lookingForIds=2&relationshipStatusIds=4,-1,3&meetAtIds=2,-1&nsfwIds=3'''
class XMPPClient:
def __init__(self, auth):
self.auth = auth
self.reset()
self.reconnect = True
self.reconnect_count = 0
def reset(self):
self.ackn = 1
self.status = 0
def send_test_msg(self,text):
to = "171176511"
msgid = str(uuid.uuid4())
data = {"sourceProfileId":self.auth["profileId"],"targetProfileId":to,"messageId":msgid,"sourceDisplayName":self.auth["profileId"],"type":"text","timestamp":int(time.time() *1000),"body":text}
msg7 = '''<message from="'''+self.auth["profileId"]+'''@chat.grindr.com" id="'''+msgid+'''" to="'''+to+'''@chat.grindr.com" type="chat" xmlns="jabber:client"><body>'''+str(data)+'''</body></message>'''
self.ws.send(msg7)
def on_message(self, ws, message):
x = minidom.parseString(message)
print("\n\t"+message)
if x.firstChild.tagName == 'message':
if x.firstChild.firstChild.tagName == 'body':
#print("\t"+message)
try:
data = json.loads(x.firstChild.firstChild.firstChild.nodeValue)
except:
data = x.firstChild.firstChild.firstChild.nodeValue
#data2 = json.loads(data["body"])
print("\t"+data)
#print("\t"+data2)
#print("> "+data["body"])
elif x.firstChild.firstChild.tagName == 'sent' and x.firstChild.firstChild.firstChild.tagName == 'forwarded':
#print("\t"+message)
'''try:
data = json.loads(x.firstChild.firstChild.firstChild.firstChild.firstChild.firstChild.nodeValue)
except:
data = x.firstChild.firstChild..firstChildfirstChild.firstChild.firstChild.nodeValue
#data2 = json.loads(data["body"])
print("\t [Desde móvil] "+data)
#print("\t"+data2)
#print("> "+data["body"])'''
elif x.firstChild.firstChild.tagName == 'active':
print("\rActivo.......", end="")
elif x.firstChild.firstChild.tagName == 'translate': #Esto es raro
print("\rChat abierto..", end="")
elif x.firstChild.firstChild.tagName == 'composing':
print("\rEscribiendo...", end="")
elif x.firstChild.firstChild.tagName == 'paused':
print("\rPausado.......", end="")
elif x.firstChild.firstChild.tagName == 'displayed':
print("\rVisto.........", end="")
else:
print("?")
elif x.firstChild.tagName == 'r':
# ACK de stanzas
ackmsg = '''<a h="'''+str(self.ackn)+'''" xmlns="urn:xmpp:sm:3"/>'''
self.ws.send(ackmsg)
self.ackn += 1
elif x.firstChild.tagName == 'failure':
self.ws.close()
self.on_close(ws)
self.reconnect = False
elif x.firstChild.tagName == 'close':
self.ws.close()
#self.start()
else:
print("?")
#print("\t"+message)
def on_error(self, ws, error):
print(error)
def on_close(self, ws):
print("Reconectando!!!")
if self.reconnect and self.reconnect_count < 3:
self.reconnect_count += 1
self.reset()
self.start()
def on_open(self, ws):
def run(self):
#print(self.auth)
#quit()
auth_str_data = self.auth["profileId"]+'''@chat.grindr.com'''+'\0'+self.auth["profileId"]+'\0'+ self.auth["token"]
auth_str = str(base64.b64encode(auth_str_data.encode("UTF-8")), "UTF-8")
# Este montón de mierda se podría poner más bonito
msg1 = '''<open to="chat.grindr.com" version="1.0" xmlns="urn:ietf:params:xml:ns:xmpp-framing"/>'''
msg2 = '''<auth mechanism="PLAIN" xmlns="urn:ietf:params:xml:ns:xmpp-sasl">'''+auth_str+'''</auth>'''
msg3 = '''<open to="chat.grindr.com" version="1.0" xmlns="urn:ietf:params:xml:ns:xmpp-framing"/>'''
msg4 = '''<iq id="_bind_auth_2" type="set" xmlns="jabber:client"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>'''+self.auth["clientId"]+'''_web</resource></bind></iq>'''
msg5 = '''<iq id="_session_auth_2" type="set" xmlns="jabber:client"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>'''
msg6 = '''<iq from="'''+self.auth["profileId"]+'''@chat.grindr.com/'''+self.auth["clientId"]+'''_web" id="'''+str(uuid.uuid4())+''':carbons" type="set" xmlns="jabber:client"><enable xmlns="urn:xmpp:carbons:2"/></iq>'''
msg8 = '''<enable resume="false" xmlns="urn:xmpp:sm:3"/>'''
msg9 = '''<presence xmlns="jabber:client"/>'''
msg10 = '''<r xmlns="urn:xmpp:sm:3"/>'''
msg11 = '''<message from="[email protected]" id="'''+str(uuid.uuid4())+'''" to="[email protected]" type="chat" xmlns="jabber:client"><body>{"sourceProfileId":"277365733","targetProfileId":"250015945","messageId":"'''+str(uuid.uuid4())+'''","sourceDisplayName":"277365733","type":"image","timestamp":1583677134256,"body":"{\"imageHash\":\"taps/looking.png\",\"imageType\":2,\"tapType\":2}"}</body></message>'''
self.ws.send(msg1)
self.ws.send(msg2)
self.ws.send(msg3)
self.ws.send(msg4)
self.ws.send(msg5)
self.ws.send(msg6)
self.ws.send(msg8)
self.ws.send(msg9)
self.ws.send(msg10)
#self.ws.send(msg11)
#threading.Thread(target=run,args=(self)).start()
_thread.start_new_thread(run,((self,)))
def start(self):
print("Starting XMPP connection...")
ws_endpoint = "wss://chat.grindr.com:2443/ws-xmpp"
self.ws = websocket.WebSocketApp(ws_endpoint,
on_message = lambda ws,message: self.on_message(ws, message),
on_error = lambda ws,error: self.on_error(ws,error),
on_close = lambda ws: self.on_close(ws),
on_open = lambda ws: self.on_open(ws))
#websocket.enableTrace(True)
#self.ws.run_forever()
wst = threading.Thread(target=self.ws.run_forever, kwargs={'ping_interval': 15, 'ping_timeout' : 5})
wst.daemon = True
wst.start()
wst.join()
def finish(self):
self.reconnect = False
self.ws.close()
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--login', action="store_true")
args = parser.parse_args()
def receiveSignal(signalNumber, frame):
print('Received:', signalNumber)
return
def exit_ok(s,f):
xmpp.finish()
quit()
def register_signals():
# register the signals to be caught
signal.signal(signal.SIGHUP, receiveSignal)
signal.signal(signal.SIGINT, exit_ok)
signal.signal(signal.SIGQUIT, receiveSignal)
signal.signal(signal.SIGILL, receiveSignal)
signal.signal(signal.SIGTRAP, receiveSignal)
signal.signal(signal.SIGABRT, receiveSignal)
signal.signal(signal.SIGBUS, receiveSignal)
signal.signal(signal.SIGFPE, receiveSignal)
#signal.signal(signal.SIGKILL, receiveSignal)
signal.signal(signal.SIGUSR1, receiveSignal)
signal.signal(signal.SIGSEGV, receiveSignal)
signal.signal(signal.SIGUSR2, receiveSignal)
signal.signal(signal.SIGPIPE, receiveSignal)
signal.signal(signal.SIGALRM, receiveSignal)
signal.signal(signal.SIGTERM, receiveSignal)
register_signals()
if args.login:
auth = Auth()
auth.web_client_start()
if(auth.wait_scanned()):
token = auth.token
clientId = auth.clientId
else:
print("Ooops!")
quit()
auth_tmp = {"token": auth.token, "profileId": auth.profileId, "clientId": auth.clientId}
else:
auth_tmp = {'token': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmZWF0dXJlcyI6WyJEaXNjcmVldEljb24iLCJQSU5Mb2NrIiwiVmlkZW9DYWxsRGFpbHlGcmVlIiwiQ3JlYXRlVmlkZW9DYWxsIiwiV2ViQ2hhdCJdLCJwcm9maWxlSWQiOiIyNzczNjU3MzMiLCJyb2xlcyI6W10sImV4cCI6MTU4MzY4NTc2Nn0.tqgEcJI8vGkmba2F18nA5cmQWr4WW1foCTSiBR0oSOw', 'profileId': '277365733', 'clientId': 'ggqSJGRctALkAhDlAYqtXcGkbBEAsfpHeikKCrSbfxNVklKDOIpYldhDiBCbpIOX'}
print(auth_tmp)
xmpp = XMPPClient(auth_tmp)
xmpp.start()