-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscrapkeys.py
executable file
·148 lines (127 loc) · 3.9 KB
/
scrapkeys.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
#!/usr/bin/python3
import sys
import os
import json
from urllib.request import urlopen
import mechanicalsoup
class colors :
GREEN = '\033[92m'
ENDG = '\033[0m'
def parse_iphonewiki(url2parse, img_type):
br = mechanicalsoup.StatefulBrowser()
html = br.open(url2parse)
keypage = list()
keypage = ["rootfs-key", "updateramdisk-iv", "updateramdisk-key",
"restoreramdisk-iv", "restoreramdisk-key", "applelogo-iv",
"applelogo-key", "batterycharging0-iv", "batterycharging0-key",
"batterycharging1-iv", "batterycharging1-key", "batteryfull-iv",
"batteryfull-key", "batterylow0-iv", "batterylow0-key",
"batterylow1-iv", "batterylow1-key", "devicetree-iv",
"devicetree-key", "glyphcharging-iv", "glyphcharging-key",
"glyphplugin-iv", "glyphplugin-key",
"ibec-iv", "ibec-key", "iboot-iv", "iboot-key",
"ibss-iv", "ibss-key", "kernelcache-iv",
"kernelcache-key", "llb-iv", "llb-key",
"recoverymode-iv", "recoverymode-key",
"sepfirmware-iv", "sepfirmware-key"]
j = 0
key = ""
for i in range(0, len(keypage)):
for hit in br.get_current_page().find_all(attrs={'id': "keypage-" + keypage[i]}):
if img_type == None:
bl = keypage[i]
print(bl + ":\n\t %s" % hit.text)
elif img_type != None and img_type == keypage[i].split('-')[0]:
j += 1
key += hit.text
if j == 2:
return key
# Used to 'convert' version -> build ID and vice versa
# I just parse firmwares.json on api.ipsw.me
def version_or_build(model, version, build):
get_buildid = False
get_version = False
json_file = urlopen("https://api.ipsw.me/v4/device/" + model)
with open(model, 'wb') as output:
output.write(json_file.read())
data = json.load(open(model))
if build is None:
get_buildid = True
elif version is None:
get_version = True
i = 0
with open(model):
while True:
if get_buildid is True:
result = data["firmwares"][i]["buildid"]
ios_version = data["firmwares"][i]["version"]
if ios_version == version:
break
elif get_version is True:
buildid = data["firmwares"][i]["buildid"]
result= data["firmwares"][i]["version"]
if build == buildid:
break
i += 1
os.remove(model)
return result
# we need to get the codename of the firmware to access the URL
def get_codename(device, version, build):
version = version.split('.')[0] + ".x"
url = "https://www.theiphonewiki.com/wiki/Firmware_Keys/" + version
br = mechanicalsoup.StatefulBrowser()
html = br.open(url) #.read()
i = 0
checker = False
data = br.get_current_page().find_all('a')
device = "(%s)" % device
for hit in data:
# some beta may have the same codename, first in first out
if checker is False:
try:
if data[i].get('href').split('_')[1] == build and data[i].get('href').split('_')[2] == device:
checker = True
codename = data[i].get('href').split('/')[2].split('_')[0]
return codename
except:
pass
i += 1
def usage(toolname):
print("usage: " + toolname + " [args]")
print(" -d <device>")
print(" -i <version>")
print(" -b <build ID>")
print(" -c <codename>")
if __name__ == '__main__':
argc = len(sys.argv)
argv = sys.argv
check = 0
codename = None
ios_v = None
build = None
set_ios_version = None
if argc <= 4:
usage(argv[0])
sys.exit(-1)
for i in range(0,argc):
if argv[i] == "-i":
ios_v = argv[i + 1]
set_ios_version = True
elif argv[i] == "-b" :
build = argv[i + 1]
elif argv[i] == "-d" :
device = argv[i + 1]
elif argv[i] == "-c":
codename = argv[i + 1]
if set_ios_version is True:
build = version_or_build(device, ios_v, build)
else:
ios_v = version_or_build(device, ios_v, build)
if codename is None:
codename = get_codename(device, ios_v, build)
print("[+] build ID : " + build)
if codename is None:
codename = get_codename(device, ios_v, build)
url = "https://www.theiphonewiki.com/wiki/" + codename + "_" + build + "_" + "(" + device + ")"
print("[+] grabbing keys from " + url)
parse_iphonewiki(url, None)