Repository navigation
Expand file tree
/
Copy pathRelinkUs.py
More file actions
293 lines (214 loc) · 9.48 KB
/
Copy pathRelinkUs.py
File metadata and controls
293 lines (214 loc) · 9.48 KB
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
# -*- coding: utf-8 -*-
from __future__ import with_statement
import binascii
import re
import os
from Crypto.Cipher import AES
from module.plugins.internal.Crypter import Crypter
from module.utils import save_join as fs_join
class RelinkUs(Crypter):
__name__ = "RelinkUs"
__type__ = "crypter"
__version__ = "3.14"
__status__ = "testing"
__pattern__ = r'http://(?:www\.)?relink\.us/(f/|((view|go)\.php\?id=))(?P<ID>.+)'
__config__ = [("use_subfolder" , "bool", "Save package to subfolder" , True),
("subfolder_per_pack", "bool", "Create a subfolder for each package", True)]
__description__ = """Relink.us decrypter plugin"""
__license__ = "GPLv3"
__authors__ = [("fragonib", "fragonib[AT]yahoo[DOT]es"),
("AndroKev", "neureither.kevin@gmail.com")]
PREFERRED_LINK_SOURCES = ["cnl2", "dlc", "web"]
OFFLINE_TOKEN = r'<title>Tattooside'
PASSWORD_TOKEN = r'container_password.php'
PASSWORD_ERROR_ROKEN = r'You have entered an incorrect password'
PASSWORD_SUBMIT_URL = r'http://www.relink.us/container_password.php'
CAPTCHA_TOKEN = r'container_captcha.php'
CAPTCHA_ERROR_ROKEN = r'You have solved the captcha wrong'
CAPTCHA_IMG_URL = r'http://www.relink.us/core/captcha/circlecaptcha.php'
CAPTCHA_SUBMIT_URL = r'http://www.relink.us/container_captcha.php'
FILE_TITLE_REGEX = r'<th>Title</th><td>(.*)</td></tr>'
FILE_NOTITLE = r'No title'
CNL2_FORM_REGEX = r'<form id="cnl_form-(.*?)</form>'
CNL2_FORMINPUT_REGEX = r'<input.*?name="%s".*?value="(.*?)"'
CNL2_JK_KEY = "jk"
CNL2_CRYPTED_KEY = "crypted"
DLC_LINK_REGEX = r'<a href=".*?" class="dlc_button" target="_blank">'
DLC_DOWNLOAD_URL = r'http://www.relink.us/download.php'
WEB_FORWARD_REGEX = r'getFile\(\'(.+)\'\)'
WEB_FORWARD_URL = r'http://www.relink.us/frame.php'
WEB_LINK_REGEX = r'<iframe name="Container" height="100%" frameborder="no" width="100%" src="(.+)"></iframe>'
def setup(self):
self.fileid = None
self.package = None
self.captcha = False
def decrypt(self, pyfile):
#: Init
self.init_package(pyfile)
#: Request package
self.request_package()
#: Check for online
if not self.is_online():
self.offline()
#: Check for protection
if self.is_password_protected():
self.unlock_password_protection()
self.handle_errors()
if self.is_captcha_protected():
self.captcha = True
self.unlock_captcha_protection()
self.handle_errors()
#: Get package name and folder
(package_name, folder_name) = self.get_package_info()
#: Extract package links
package_links = []
for sources in self.PREFERRED_LINK_SOURCES:
package_links.extend(self.handle_link_source(sources))
if package_links: #: Use only first source which provides links
break
package_links = set(package_links)
#: Pack
if package_links:
self.packages = [(package_name, package_links, folder_name)]
def init_package(self, pyfile):
self.fileid = re.match(self.__pattern__, pyfile.url).group('ID')
self.package = pyfile.package()
def request_package(self):
self.html = self.load(self.pyfile.url)
def is_online(self):
if self.OFFLINE_TOKEN in self.html:
self.log_debug("File not found")
return False
return True
def is_password_protected(self):
if self.PASSWORD_TOKEN in self.html:
self.log_debug("Links are password protected")
return True
def is_captcha_protected(self):
if self.CAPTCHA_TOKEN in self.html:
self.log_debug("Links are captcha protected")
return True
return False
def unlock_password_protection(self):
password = self.get_password()
self.log_debug("Submitting password [%s] for protected links" % password)
if password:
passwd_url = self.PASSWORD_SUBMIT_URL + "?id=%s" % self.fileid
passwd_data = {'id': self.fileid, 'password': password, 'pw': 'submit'}
self.html = self.load(passwd_url, post=passwd_data)
def unlock_captcha_protection(self):
self.log_debug("Request user positional captcha resolving")
captcha_img_url = self.CAPTCHA_IMG_URL + "?id=%s" % self.fileid
coords = self.captcha.decrypt(captcha_img_url, input_type="png", output_type='positional', ocr="CircleCaptcha")
self.log_debug("Captcha resolved, coords [%s]" % str(coords))
captcha_post_url = self.CAPTCHA_SUBMIT_URL + "?id=%s" % self.fileid
captcha_post_data = {'button.x': coords[0], 'button.y': coords[1], 'captcha': 'submit'}
self.html = self.load(captcha_post_url, post=captcha_post_data)
def get_package_info(self):
name = folder = None
#: Try to get info from web
m = re.search(self.FILE_TITLE_REGEX, self.html)
if m:
title = m.group(1).strip()
if not self.FILE_NOTITLE in title:
name = folder = title
self.log_debug("Found name [%s] and folder [%s] in package info" % (name, folder))
#: Fallback to defaults
if not name or not folder:
name = self.package.name
folder = self.package.folder
self.log_debug("Package info not found, defaulting to pyfile name [%s] and folder [%s]" % (name, folder))
#: Return package info
return name, folder
def handle_errors(self):
if self.PASSWORD_ERROR_ROKEN in self.html:
msg = "Incorrect password, please set right password on 'Edit package' form and retry"
self.log_debug(msg)
self.fail(_(msg))
if self.captcha:
if self.CAPTCHA_ERROR_ROKEN in self.html:
self.captcha.invalid()
self.retry()
else:
self.captcha.correct()
def handle_link_source(self, source):
if source == "cnl2":
return self.handle_CNL2Links()
elif source == "dlc":
return self.handle_DLC_links()
elif source == "web":
return self.handle_WEB_links()
else:
self.error(_('Unknown source type "%s"') % source)
def handle_CNL2Links(self):
self.log_debug("Search for CNL2 links")
package_links = []
m = re.search(self.CNL2_FORM_REGEX, self.html, re.S)
if m:
cnl2_form = m.group(1)
try:
(vcrypted, vjk) = self._get_cipher_params(cnl2_form)
for (crypted, jk) in zip(vcrypted, vjk):
package_links.extend(self._get_links(crypted, jk))
except Exception:
self.log_debug("Unable to decrypt CNL2 links")
return package_links
def handle_DLC_links(self):
self.log_debug("Search for DLC links")
package_links = []
m = re.search(self.DLC_LINK_REGEX, self.html)
if m:
container_url = self.DLC_DOWNLOAD_URL + "?id=%s&dlc=1" % self.fileid
self.log_debug("Downloading DLC container link [%s]" % container_url)
try:
dlc = self.load(container_url)
dlc_filename = self.fileid + ".dlc"
dlc_filepath = fs_join(self.pyload.config.get("general", "download_folder"), dlc_filename)
with open(dlc_filepath, "wb") as f:
f.write(dlc)
package_links.append(dlc_filepath)
except Exception:
self.fail(_("Unable to download DLC container"))
return package_links
def handle_WEB_links(self):
self.log_debug("Search for WEB links")
package_links = []
params = re.findall(self.WEB_FORWARD_REGEX, self.html)
self.log_debug("Decrypting %d Web links" % len(params))
for index, param in enumerate(params):
try:
url = self.WEB_FORWARD_URL + "?%s" % param
self.log_debug("Decrypting Web link %d, %s" % (index + 1, url))
res = self.load(url)
link = re.search(self.WEB_LINK_REGEX, res).group(1)
package_links.append(link)
except Exception, detail:
self.log_debug("Error decrypting Web link %s, %s" % (index, detail))
self.wait(4)
return package_links
def _get_cipher_params(self, cnl2_form):
#: Get jk
jk_re = self.CNL2_FORMINPUT_REGEX % self.CNL2_JK_KEY
vjk = re.findall(jk_re, cnl2_form, re.I)
#: Get crypted
crypted_re = self.CNL2_FORMINPUT_REGEX % RelinkUs.CNL2_CRYPTED_KEY
vcrypted = re.findall(crypted_re, cnl2_form, re.I)
#: Log and return
self.log_debug("Detected %d crypted blocks" % len(vcrypted))
return vcrypted, vjk
def _get_links(self, crypted, jk):
#: Get key
jreturn = self.js.eval("%s f()" % jk)
self.log_debug("JsEngine returns value [%s]" % jreturn)
key = binascii.unhexlify(jreturn)
#: Decrypt
Key = key
IV = key
obj = AES.new(Key, AES.MODE_CBC, IV)
text = obj.decrypt(crypted.decode('base64'))
#: Extract links
text = text.replace("\x00", "").replace("\r", "")
links = filter(bool, text.split('\n'))
#: Log and return
self.log_debug("Package has %d links" % len(links))
return links