├── requirements.txt ├── LICENSE ├── example.py ├── README.md ├── .gitignore ├── e2ee.py └── register.py /requirements.txt: -------------------------------------------------------------------------------- 1 | pycryptodome 2 | python-axolotl-curve25519 3 | requests 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 LRTT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /example.py: -------------------------------------------------------------------------------- 1 | from register import LineRegister 2 | from e2ee import E2EE 3 | import base64 4 | 5 | old_input = input 6 | input = lambda string: old_input(string).strip() 7 | 8 | PASSWORD = "pasunxwinhery1234" 9 | PHONE_NUMBER = input("Phone Number: ") # 80xxxxxxx 10 | COUNTRY_CODE = input("Country Code: ") # TH 11 | 12 | client = LineRegister(PHONE_NUMBER, COUNTRY_CODE) 13 | openSession = client.openSession() 14 | authSessionId = openSession["authSessionId"] 15 | getPhoneVerifMethod = client.getPhoneVerifMethod(authSessionId) 16 | if 2 in getPhoneVerifMethod["availableMethods"]: 17 | client.sendPinCodeForPhone(authSessionId, 2) 18 | client.verifyPhone(authSessionId, input("Pin Code: ")) 19 | client.validateProfile(authSessionId) 20 | e2ee = E2EE() 21 | private_key = base64.b64encode(e2ee.Curve.private_key).decode() 22 | public_key = base64.b64encode(e2ee.Curve.public_key).decode() 23 | nonce = base64.b64encode(e2ee.Curve.nonce).decode() 24 | exchangeEncryptionKey = client.exchangeEncryptionKey(authSessionId, public_key, nonce) 25 | client.setPassword(authSessionId, PASSWORD, private_key, public_key, nonce, exchangeEncryptionKey["public_key"], exchangeEncryptionKey["nonce"]) 26 | registerResult = client.registerPrimaryUsingPhone(authSessionId) 27 | print("Your Auth Key: " + registerResult["authKey"]) 28 | print("Your Auth Token: " + registerResult["authToken"]) 29 | else: 30 | print("Fail to Register") 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LINE REGISTER PRIMARY [![Status](https://img.shields.io/uptimerobot/status/m784644197-00960f85a59d732ec38d545d?style=for-the-badge)]() 2 | Register LINE primary token by using phone number. 3 | 4 | Example 5 | ------------ 6 | ```python 7 | from register import LineRegister 8 | from e2ee import E2EE 9 | import base64 10 | 11 | old_input = input 12 | input = lambda string: old_input(string).strip() 13 | 14 | PASSWORD = "pasunxwinhery1234" 15 | PHONE_NUMBER = input("Phone Number: ") # 80xxxxxxx 16 | COUNTRY_CODE = input("Country Code: ") # TH 17 | 18 | client = LineRegister(PHONE_NUMBER, COUNTRY_CODE) 19 | openSession = client.openSession() 20 | authSessionId = openSession["authSessionId"] 21 | getPhoneVerifMethod = client.getPhoneVerifMethod(authSessionId) 22 | if 2 in getPhoneVerifMethod["availableMethods"]: 23 | client.sendPinCodeForPhone(authSessionId, 2) 24 | client.verifyPhone(authSessionId, input("Pin Code: ")) 25 | client.validateProfile(authSessionId) 26 | e2ee = E2EE() 27 | private_key = base64.b64encode(e2ee.Curve.private_key).decode() 28 | public_key = base64.b64encode(e2ee.Curve.public_key).decode() 29 | nonce = base64.b64encode(e2ee.Curve.nonce).decode() 30 | exchangeEncryptionKey = client.exchangeEncryptionKey(authSessionId, public_key, nonce) 31 | client.setPassword(authSessionId, PASSWORD, private_key, public_key, nonce, exchangeEncryptionKey["public_key"], exchangeEncryptionKey["nonce"]) 32 | registerResult = client.registerPrimaryUsingPhone(authSessionId) 33 | print("Your Auth Key: " + registerResult["authKey"]) 34 | print("Your Auth Token: " + registerResult["authToken"]) 35 | else: 36 | print("Fail to Register") 37 | ``` 38 | 39 | Installation 40 | ------------ 41 | ```shell 42 | $ pip3 install -r requirements.txt 43 | ``` 44 | 45 | Special Thanks to [Crash-override404](https://github.com/crash-override404/linepy-modified) for e2ee. 46 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /e2ee.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from urllib.parse import quote, unquote, urlencode 3 | from collections import namedtuple 4 | from Crypto.Cipher import AES 5 | import base64, hashlib, os 6 | import axolotl_curve25519 as Curve25519 7 | 8 | KeyPairCurve = namedtuple('KeyPair', ['private_key', 'public_key', 'nonce']) 9 | AESKeyAndIV = namedtuple('AESKey', ['Key', 'IV']) 10 | 11 | class E2EE: 12 | 13 | def __init__(self, private_key=None, public_key=None, nonce=None): 14 | self.Curve = self.generateKeypair(private_key, public_key, nonce) 15 | 16 | def _xor(self, buf): 17 | buf_length = int(len(buf) / 2) 18 | buf2 = bytearray(buf_length) 19 | for i in range(buf_length): 20 | buf2[i] = buf[i] ^ buf[buf_length + i] 21 | return bytes(buf2) 22 | 23 | def _getSHA256Sum(self, *args): 24 | instance = hashlib.sha256() 25 | for arg in args: 26 | if isinstance(arg, str): 27 | arg = arg.encode() 28 | instance.update(arg) 29 | return instance.digest() 30 | 31 | def _encryptAESECB(self, aes_key, plain_data): 32 | aes = AES.new(aes_key, AES.MODE_ECB) 33 | return aes.encrypt(plain_data) 34 | 35 | def _decryptAESECB(self, aes_key, encrypted_data): 36 | aes = AES.new(aes_key, AES.MODE_ECB) 37 | return aes.decrypt(encrypted_data) 38 | 39 | def _encryptAESCBC(self, aes_key, aes_iv, plain_data): 40 | aes = AES.new(aes_key, AES.MODE_CBC, aes_iv) 41 | return aes.encrypt(plain_data) 42 | 43 | def _decrpytAESCBC(self, aes_key, aes_iv, encrypted_data): 44 | aes = AES.new(aes_key, AES.MODE_CBC, aes_iv) 45 | return aes.decrypt(encrypted_data) 46 | 47 | def generateKeypair(self, private_key=None, public_key=None, nonce=None): 48 | private_key = private_key if private_key else Curve25519.generatePrivateKey(os.urandom(32)) 49 | public_key = public_key if public_key else Curve25519.generatePublicKey(private_key) 50 | nonce = nonce if nonce else os.urandom(16) 51 | return KeyPairCurve(private_key, public_key, nonce) 52 | 53 | def generateParams(self): 54 | secret = base64.b64encode(self.Curve.public_key).decode() 55 | return 'secret={secret}&e2eeVersion=1'.format(secret=quote(secret)) 56 | 57 | def generateSharedSecret(self, public_key): 58 | private_key = self.Curve.private_key 59 | shared_secret = Curve25519.calculateAgreement(private_key, public_key) 60 | return shared_secret 61 | 62 | def calculateSignature(self, private_key, message): 63 | return Curve25519.calculateSignature(os.urandom(32), private_key, message) 64 | 65 | def calculateAgreement(self, private_key, public_key): 66 | return Curve25519.calculateAgreement(private_key, public_key) 67 | 68 | def generateAESKeyAndIV(self, shared_secret): 69 | aes_key = self._getSHA256Sum(shared_secret, 'Key') 70 | aes_iv = self._xor(self._getSHA256Sum(shared_secret, 'IV')) 71 | return AESKeyAndIV(aes_key, aes_iv) 72 | 73 | def generateSignature(self, aes_key, encrypted_data): 74 | data = self._xor(self._getSHA256Sum(encrypted_data)) 75 | signature = self._encryptAESECB(aes_key, data) 76 | return signature 77 | 78 | def verifySignature(self, signature, aes_key, encrypted_data): 79 | data = self._xor(self._getSHA256Sum(encrypted_data)) 80 | return self._decryptAESECB(aes_key, signature) == data 81 | 82 | def decryptKeychain(self, encrypted_keychain, public_key): 83 | public_key = base64.b64decode(public_key) 84 | encrypted_keychain = base64.b64decode(encrypted_keychain) 85 | shared_secret = self.generateSharedSecret(public_key) 86 | aes_key, aes_iv = self.generateAESKeyAndIV(shared_secret) 87 | keychain_data = self._decrpytAESCBC(aes_key, aes_iv, encrypted_keychain) 88 | return keychain_data 89 | -------------------------------------------------------------------------------- /register.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Line Auto Register By Phone Number 4 | 5 | * Note ! 6 | If you register too frequent Line will block you 7 | 8 | * How It Work ? 9 | You will send request data to our server 10 | Server will generate request body 11 | Then you will post request body to Line Server 12 | And Then you will send Line Server Response 13 | To parse to json data 14 | 15 | - LRTT TEAM 16 | 17 | """ 18 | 19 | from e2ee import E2EE 20 | import base64 21 | import requests 22 | import uuid 23 | 24 | class Config: 25 | UA = "Line/9.12.0" 26 | LA = "ANDROID\t9.12.0\tAndroid OS\t10" 27 | LAL = "en_us" 28 | 29 | UDID = uuid.uuid4().hex 30 | DeviceModel = "Nokia 6.1 Plus" 31 | 32 | SERVER_URL = "https://api.lrtt.icu/registerPrimary.do" 33 | LINE_HOST = "https://gxx.line.naver.jp/acct/pais/v1" 34 | 35 | class LineRegister: 36 | def __init__(self, phoneNumber, countryCode): 37 | self.deviceInfo = { 38 | "udid": Config.UDID, 39 | "deviceModel": Config.DeviceModel, 40 | } 41 | 42 | self.phoneInfo = { 43 | "phoneNumber": phoneNumber, 44 | "countryCode": countryCode, 45 | } 46 | 47 | self.headers = { 48 | "User-Agent": Config.UA, 49 | "X-Line-Application": Config.LA, 50 | "X-lal": Config.LAL 51 | } 52 | 53 | def post(self, raw_data): 54 | return requests.post(Config.LINE_HOST, data=raw_data, headers=self.headers).content 55 | 56 | def gen(self, method, data): 57 | return requests.post(Config.SERVER_URL + "/generate", json={**{"method": method}, **data}).content 58 | 59 | def parse(self, method, raw_data): 60 | response = requests.post(Config.SERVER_URL + "/parse", params={"method": method}, data=raw_data).json() 61 | if response["status"] == 200: 62 | return response 63 | raise Exception(response) 64 | 65 | METHODS = { 66 | 'openSession': { 67 | 'args': [], 68 | }, 69 | 'getPhoneVerifMethod': { 70 | 'args': [ 71 | 'authSessionId' 72 | ], 73 | 'self': [ 74 | 'deviceInfo', 75 | 'phoneInfo' 76 | ] 77 | }, 78 | 'sendPinCodeForPhone': { 79 | 'args': [ 80 | 'authSessionId', 81 | 'verifMethod' 82 | ], 83 | 'self': [ 84 | 'deviceInfo', 85 | 'phoneInfo' 86 | ] 87 | }, 88 | 'verifyPhone': { 89 | 'args': [ 90 | 'authSessionId', 91 | 'pinCode' 92 | ], 93 | 'self': [ 94 | 'deviceInfo', 95 | 'phoneInfo' 96 | ] 97 | }, 98 | 'validateProfile': { 99 | 'args': [ 100 | 'authSessionId' 101 | ] 102 | }, 103 | 'exchangeEncryptionKey': { 104 | 'args': [ 105 | 'authSessionId', 106 | 'public_key', 107 | 'nonce' 108 | ] 109 | }, 110 | 'setPassword': { 111 | 'args': [ 112 | 'authSessionId', 113 | 'password', 114 | 'private_key', 115 | 'public_key', 116 | 'nonce', 117 | 'server_public_key', 118 | 'server_nonce' 119 | ] 120 | }, 121 | 'registerPrimaryUsingPhone': { 122 | 'args': [ 123 | 'authSessionId' 124 | ] 125 | } 126 | } 127 | 128 | for method in METHODS: 129 | def create_method(method_name, method_data): 130 | def wrapper(cls, *args, **kwargs): 131 | data = {} 132 | if 'args' in method_data: 133 | for index, arg in enumerate(args): 134 | data[method_data['args'][index]] = arg 135 | for key, value in kwargs.items(): 136 | assert key not in data or key not in method_data['args'], '%s already set or %s is invaild args' % (key, key) 137 | data[key] = value 138 | if 'self' in method_data: 139 | for s_arg in method_data['self']: 140 | data[s_arg] = getattr(cls, s_arg) 141 | return cls.parse(method_name, cls.post(cls.gen(method_name, data))) 142 | return wrapper 143 | setattr(LineRegister, method, create_method(method, METHODS[method])) 144 | 145 | del METHODS 146 | 147 | if __name__ == "__main__": 148 | print(""" 149 | LINE register by LRTT 150 | """) 151 | phoneNumber = input("Phone Number: ") # 080xxxxxxx 152 | countryCode = input("Country Code: ") # TH (example) 153 | client = LineRegister(phoneNumber, countryCode) 154 | 155 | openSession = client.openSession() 156 | authSessionId = openSession["authSessionId"] 157 | 158 | getPhoneVerifMethod = client.getPhoneVerifMethod(authSessionId) 159 | if 2 not in getPhoneVerifMethod["availableMethods"]: 160 | raise Exception("Can't Register With This Phone Number :(") 161 | 162 | sendPinCodeForPhone = client.sendPinCodeForPhone(authSessionId, 2) 163 | if sendPinCodeForPhone["status"] != 200: 164 | raise Exception("Fail to sendPinCodeForPhone") 165 | 166 | while True: # verify pin (phone) 167 | try: 168 | PIN = input("Pin Code: ") 169 | verifyPhone = client.verifyPhone(authSessionId, PIN) 170 | break 171 | except Exception as err: 172 | err = str(err) 173 | if 'code=45' in err or 'code=2' in err: # (INVALID_PIN_CODE, DB_FAILED) 174 | print('invaild pin Code') 175 | continue 176 | raise err 177 | 178 | validateProfile = client.validateProfile(authSessionId) 179 | 180 | e2ee = E2EE() 181 | 182 | private_key = base64.b64encode(e2ee.Curve.private_key).decode() 183 | public_key = base64.b64encode(e2ee.Curve.public_key).decode() 184 | nonce = base64.b64encode(e2ee.Curve.nonce).decode() 185 | 186 | exchangeEncryptionKey = client.exchangeEncryptionKey(authSessionId, public_key, nonce) 187 | 188 | while True: # set password 189 | try: 190 | password = input('Password: ') 191 | setPassword = client.setPassword(authSessionId, password, private_key, public_key, nonce, exchangeEncryptionKey["public_key"], exchangeEncryptionKey["nonce"]) 192 | break 193 | except Exception as err: 194 | err = str(err) 195 | if 'code=1' in err: # (ILLEGAL_ARGUMENT), maybe invaild password format 196 | print(err.split("alertMessage='")[1].split("',")[0]) 197 | continue 198 | raise err 199 | 200 | registerResult = client.registerPrimaryUsingPhone(authSessionId) 201 | 202 | print("Auth Key: " + registerResult["authKey"]) 203 | print("Auth Token: " + registerResult["authToken"]) 204 | --------------------------------------------------------------------------------