Last active
January 10, 2025 00:05
-
-
Save hungte/47b7a81701ea8fd2d75302b84ec8fe0c to your computer and use it in GitHub Desktop.
A tool to decrypt mega encrypted link, inspired from https://github.com/denysvitali/megadecrypter/ because installing Crystal-lang is not an easy thing for most people.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright 2018 Hung-Te Lin. All rights reserved. | |
# Use of this source code is governed by MIT license. | |
"""A program to decrypt mega://enc2?.... link. | |
Inspired from https://github.com/denysvitali/megadecrypter | |
""" | |
import base64 | |
import binascii | |
import re | |
import subprocess | |
import sys | |
class MegaLinkCrypto(object): | |
enc_xor = [12, 57, 251, 120, 18, 75, 6, 250, 85] | |
pwd2 = [110, 89, 114, 88, 97, 64, 57, 81, 63, 49, 38, 104, 67, 87, 77, 92, | |
57, 40, 55, 51, 49, 66, 112, 63, 116, 52, 50, 61, 33, 107, 51, 46] | |
iv = [121, 241, 10, 1, 132, 74, 11, 39, 255, 91, 45, 78, 14, 211, 22, 62] | |
def __init__(self): | |
pass | |
def getBytes(self): | |
byteDecKey = self.pwd2[:] | |
for i in xrange(160): | |
byteDecKey[i % 32] = byteDecKey[i % 32] ^ self.enc_xor[i % 9] | |
return byteDecKey | |
@staticmethod | |
def hexlify(value): | |
return ''.join('%02x' % d for d in value) | |
def decrypt(self, value): | |
cipher = ''.join(self.toBase64(value).splitlines()) | |
key = self.hexlify(self.getBytes()) | |
iv = self.hexlify(self.iv) | |
command = ('echo "%s" | openssl aes-256-cbc -d -iv %s -K %s -a -A' % | |
(cipher, iv, key)) | |
plaintext = subprocess.check_output(command, shell=True) | |
return plaintext.replace('+', '-').replace('/', '_').replace('=', '') | |
def toBase64(self, value): | |
return (value.replace('-', '+').replace('_', '/').replace( ',', '') + | |
'==') | |
def decryptLink(self, link): | |
"""Decrypts a mega://enc2?XXXXX link to HTTP URL.""" | |
r = re.match(r'^mega://(f|)enc2\?(.*)$', link) | |
if not r: | |
raise RuntimeError('Incorrect link (need mega://enc2...)') | |
folder, data = r.groups() | |
mega_link = self.decrypt(data) | |
if '!' not in mega_link: | |
raise RuntimeError('Invalid mega encryped link.') | |
return 'https://mega.nz/#%s%s' % ('F' if folder else '', mega_link) | |
def main(): | |
if len(sys.argv) != 2: | |
exit('Usage: %s mega://enc2?.....' % sys.argv[0]) | |
try: | |
c = MegaLinkCrypto() | |
print(c.decryptLink(sys.argv[1])) | |
except Exception as e: | |
print('ERROR: %s' % e) | |
exit(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how do I use that?