-
Notifications
You must be signed in to change notification settings - Fork 7
/
gcm.py
100 lines (69 loc) · 1.97 KB
/
gcm.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
import socket
from bitstring import BitStream
import mcs_pb2
import ssl
import json
import varint
# attempt at logging into gcm server. need androidId and securityToken,
# which can be pulled from a getToken request in a mitm proxy (fiddler)
# currently returns code 4 which means "CLOSE"
with open('credentials.txt', 'r') as f:
data = json.loads(f.read())
android_id = data['android_id']
security_token = data['security_token']
HOST = "mtalk.google.com"
PORT = 5228
lr = mcs_pb2.LoginRequest()
lr.adaptive_heartbeat = False
lr.auth_service = 2
lr.auth_token = str(security_token)
lr.id = "android-11"
lr.domain = "mcs.android.com"
lr.device_id = "android-" + hex(android_id)[2:]
lr.network_type = 1
lr.resource = str(android_id)
lr.user = str(android_id)
lr.use_rmq2 = True
lr.account_id = android_id
lr.received_persistent_id.append("") # possible source of error
s = lr.setting.add()
s.name = "new_vc"
s.value = "1"
x = lr.SerializeToString()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = ssl.wrap_socket(s)
s.connect((HOST, PORT))
s.send(bytes([41]))
s.send(bytes([2]))
s.send(varint.encode(len(x)))
s.send(x)
print("reading")
version = s.recv(1)
while True:
responseTag = s.recv(1)
if responseTag in [b'\x03', b'\x07', b'\x08']:
length = varint.decode_stream(s)
msg = s.recv(length)
if responseTag == b'\x03':
lresp = mcs_pb2.LoginResponse()
lresp.ParseFromString(msg)
print("RECV LOGIN RESP")
print(lresp)
elif responseTag == b'\x07':
iqs = mcs_pb2.IqStanza()
iqs.ParseFromString(msg)
print("RECV IQ")
print(iqs)
elif responseTag == b'\x08':
dms = mcs_pb2.DataMessageStanza()
dms.ParseFromString(msg)
print("RECV DATA MESSAGE")
print(dms)
elif responseTag == b'\x04':
break
else:
if not responseTag:
break
print("unknown response: " + str(responseTag))
s.close()
print("closed")