forked from biemster/FindMy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (69 loc) · 2.3 KB
/
main.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
#!/usr/bin/env python3
"""
- Fetch private keys from API.
- Send reports to API.
"""
from argparse import ArgumentParser
import json
from time import sleep
from api import fetch_devices, send_reports
from cryptic import b64_ascii, get_hashed_public_key, bytes_to_int
from apple_fetch import apple_fetch
from helpers import chunks
from report import create_reports
def get_args():
"""Returns script arguments"""
parser = ArgumentParser()
parser.add_argument(
"-k",
"--key",
required=True,
help="iCloud decryption key ($ security find-generic-password -ws 'iCloud')",
)
parser.add_argument(
"-s",
"--startpoint",
help="URL to get devices from",
)
parser.add_argument(
"-x",
"--headers",
type=json.loads,
help="Headers for API",
)
parser.add_argument(
"-e",
"--endpoint",
help="URL to send report",
)
parser.add_argument("-V", "--verbose", help="be verbose", action="store_true")
return parser.parse_args()
if __name__ == "__main__":
command_args = get_args()
beamer_devices = fetch_devices(
command_args.startpoint, headers=command_args.headers
)
if command_args.verbose:
print("Beamers:", len(beamer_devices))
device_mapping = {}
for device in beamer_devices:
privateKeyBytes = bytes(device["privateKey"]["data"])
del device["privateKey"]
device["privateKeyNumeric"] = bytes_to_int(privateKeyBytes)
publicHashBase64 = b64_ascii(get_hashed_public_key(privateKeyBytes))
device_mapping[publicHashBase64] = device
for devices_chunk in chunks(device_mapping, 10):
apple_result = apple_fetch(command_args.key, list(devices_chunk.keys()))
if command_args.verbose:
print("Results:", len(apple_result["results"]))
report_list = create_reports(apple_result, device_mapping)
for report in report_list:
if "privateKeyNumeric" in report:
del report["privateKeyNumeric"]
for report_list_chunk in chunks(report_list, 100):
send_reports(
command_args.endpoint, report_list_chunk, headers=command_args.headers
)
if command_args.verbose:
print(report_list)
sleep(0.1)