Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from pyrogram import Client
- from Crypto.Cipher import AES
- from base64 import b64encode, b64decode
- from pytun import TunTapDevice
- import threading
- tun = TunTapDevice(name='teleproxy')
- tun.addr = '10.8.0.1'
- tun.dstaddr = '10.8.0.2'
- tun.netmask = '255.255.255.0'
- tun.mtu = 1500
- tun.up()
- started = False
- api_id = 1
- api_hash = "sdfsdf"
- app = Client("proxy", api_id, api_hash)
- peer_id = 2131233
- key = b'Sixteen byte key'
- def send_message(data):
- print(1, data)
- cipher = AES.new(key, AES.MODE_EAX)
- nonce = cipher.nonce
- ciphertext, tag = cipher.encrypt_and_digest(data)
- text = nonce + tag + ciphertext
- del nonce, tag, ciphertext, data
- text = b64encode(text).decode()
- app.send_message(peer_id, text)
- def listen_tunnel(tun):
- while True:
- read = tun.read(tun.mtu)
- print(0, read)
- send_thread = threading.Thread(target=send_message, args=(read, ))
- send_thread.start()
- @app.on_message()
- async def hello(client, message):
- if message['chat']['id'] == peer_id and message['from_user']['id'] == peer_id:
- text = b64decode(message['text'])
- nonce = text[:16]
- tag = text[16:32]
- cipher = AES.new(key, AES.MODE_EAX, nonce=nonce)
- plaindata = cipher.decrypt(text[32:])
- print(plaindata)
- try:
- cipher.verify(tag)
- print("The message is authentic:", plaindata)
- except ValueError:
- raise Exception("Key incorrect or message corrupted")
- tun.write(plaindata)
- tunnel = threading.Thread(target=listen_tunnel, args=(tun, ))
- tunnel.start()
- app.run()
Add Comment
Please, Sign In to add comment