From 6f3376d80efb30a91984632a3ed6010a0469db62 Mon Sep 17 00:00:00 2001 From: fragonib Date: Mon, 30 May 2011 23:29:52 +0200 Subject: ShareLinksBiz decrypter --- module/plugins/crypter/ShareLinksBiz.py | 254 ++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 module/plugins/crypter/ShareLinksBiz.py (limited to 'module/plugins') diff --git a/module/plugins/crypter/ShareLinksBiz.py b/module/plugins/crypter/ShareLinksBiz.py new file mode 100644 index 000000000..407d2ff56 --- /dev/null +++ b/module/plugins/crypter/ShareLinksBiz.py @@ -0,0 +1,254 @@ +# -*- coding: utf-8 -*- + +from Crypto.Cipher import AES +from module.plugins.Crypter import Crypter +from module.plugins.ReCaptcha import ReCaptcha +import base64 +import binascii +import re + + +class ShareLinksBiz(Crypter): + __name__ = "ShareLinksBiz" + __type__ = "crypter" + __pattern__ = r"(http://[\w\.]*?share-links\.biz)/(?P_[0-9a-z]+)(/.*)?" + __version__ = "1.0" + __description__ = """Share-Links.biz Crypter""" + __author_name__ = ("fragonib") + __author_mail__ = ("fragonib[AT]yahoo[DOT]es") + + + def setup(self): + self.html = None + self.baseUrl = None + self.fileId = None + self.captcha = False + self.package = None + + def decrypt(self, pyfile): + + # Init + self.package = pyfile.package() + self.baseUrl = re.search(self.__pattern__, pyfile.url).group(1) + self.fileId = re.match(self.__pattern__, pyfile.url).group('id') + + # Request package + url = self.baseUrl + '/' + self.fileId + self.html = self.load(url) + + # Unblock server (load all images) + self.unblockServer() + + # Check for protection + if self.isPasswordProtected(): + self.unlockPasswordProtection() + self.handleErrors() + + if self.isCaptchaProtected(): + self.captcha = True + self.unlockCaptchaProtection() + self.handleErrors() + + # Extract package links + package_links = [] + package_links.extend(self.handleWebLinks()) + package_links.extend(self.handleContainers()) + package_links.extend(self.handleCNL2()) + package_links = set(package_links) + + # Get package info + package_name, package_folder = self.getPackageInfo() + + # Pack + self.packages = [(package_name, package_links, package_folder)] + + def isOnline(self): + if "No usable content was found" in self.html: + self.log.debug("%s: File not found" % self.__name__) + return False + return True + + def isPasswordProtected(self): + if re.search(r'''''', self.html): + self.log.debug("%s: Links are protected" % self.__name__) + return True + return False + + def isCaptchaProtected(self): + if '=x1 and x<=x2) and (y>=y1 and y<=y2): + return href + + def handleErrors(self): + if "The inserted password was wrong" in self.html: + self.log.debug("%s: Incorrect password, please set right password on 'Edit package' form and retry" % self.__name__) + self.fail("Incorrect password, please set right password on 'Edit package' form and retry") + + if self.captcha: + if "Your choice was wrong" in self.html: + self.log.debug("%s: Invalid captcha, retrying" % self.__name__) + self.invalidCaptcha() + self.setWait(5) + self.wait() + self.retry() + else: + self.correctCaptcha() + + def getPackageInfo(self): + title_re = r'

(.*)

' + m = re.search(title_re, self.html, re.DOTALL) + if m is not None: + title = m.group(1).strip() + name = folder = title + self.log.debug("%s: Found name [%s] and folder [%s] in package info" % (self.__name__, name, folder)) + else: + name = self.package.name + folder = self.package.folder + self.log.debug("%s: Package info not found, defaulting to pyfile name [%s] and folder [%s]" % (self.__name__, name, folder)) + return name, folder + + def handleWebLinks(self): + package_links = [] + self.log.debug("%s: Handling Web links" % self.__name__) + + #@TODO: Gather paginated web links + pattern = r"javascript:_get\('(.*?)', \d+, ''\)" + ids = re.findall(pattern, self.html) + self.log.debug("%s: Decrypting %d Web links" % (self.__name__, len(ids))) + for i, id in enumerate(ids): + try: + self.log.debug("%s: Decrypting Web link %d, [%s]" % (self.__name__, i+1, id)) + dwLink = self.baseUrl + "/get/lnk/" + id + response = self.load(dwLink) + code = re.search(r'frm/(\d+)', response).group(1) + fwLink = self.baseUrl + "/get/frm/" + code + response = self.load(fwLink) + jscode = re.search(r'', response, re.DOTALL).group(1) + jscode = self.js.eval("f = %s" % jscode) + jslauncher = "window=''; parent={frames:{Main:{location:{href:''}}},location:''}; %s; parent.frames.Main.location.href" + dlLink = self.js.eval(jslauncher % jscode) + self.log.debug("%s: JsEngine returns value [%s] for redirection link" % (self.__name__, dlLink)) + package_links.append(dlLink) + except Exception, detail: + self.log.debug("%s: Error decrypting Web link [%s], %s" % (self.__name__, id, detail)) + return package_links + + def handleContainers(self): + package_links = [] + self.log.debug("%s: Handling Container links" % self.__name__) + + pattern = r"javascript:_get\('(.*?)', 0, '(rsdf|ccf|dlc)'\)" + containersLinks = re.findall(pattern, self.html) + self.log.debug("%s: Decrypting %d Container links" % (self.__name__, len(containersLinks))) + for containerLink in containersLinks: + link = "%s/get/%s/%s" % (self.baseUrl, containerLink[1], containerLink[0]) + package_links.append(link) + return package_links + + def handleCNL2(self): + package_links = [] + self.log.debug("%s: Handling CNL2 links" % self.__name__) + + if '/lib/cnl2/ClicknLoad.swf' in self.html: + try: + (crypted, jk) = self._getCipherParams() + package_links.extend(self._getLinks(crypted, jk)) + except: + self.fail("Unable to decrypt CNL2 links") + return package_links + + def _getCipherParams(self): + + # Request CNL2 + code = re.search(r'ClicknLoad.swf\?code=(.*?)"', self.html).group(1) + url = "%s/get/cnl2/%s" % (self.baseUrl, code) + response = self.load(url) + params = response.split(";;") + + # Get jk + strlist = list(base64.standard_b64decode(params[1])) + strlist.reverse() + jk = ''.join(strlist) + + # Get crypted + strlist = list(base64.standard_b64decode(params[2])) + strlist.reverse() + crypted = ''.join(strlist) + + # Log and return + return crypted, jk + + def _getLinks(self, crypted, jk): + + # Get key + jreturn = self.js.eval("%s f()" % jk) + self.log.debug("%s: JsEngine returns value [%s]" % (self.__name__, jreturn)) + key = binascii.unhexlify(jreturn) + + # Decode crypted + crypted = base64.standard_b64decode(crypted) + + # Decrypt + Key = key + IV = key + obj = AES.new(Key, AES.MODE_CBC, IV) + text = obj.decrypt(crypted) + + # Extract links + text = text.replace("\x00", "").replace("\r", "") + links = text.split("\n") + links = filter(lambda x: x != "", links) + + # Log and return + self.log.debug("%s: Block has %d links" % (self.__name__, len(links))) + return links \ No newline at end of file -- cgit v1.2.3