GUI_client.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import asyncio
  2. from telethon import events
  3. from telethon import TelegramClient
  4. import time
  5. import sqlite3
  6. from tkinter import *
  7. import threading
  8. import random
  9. from Crypto.PublicKey import RSA
  10. from Crypto.Random import get_random_bytes
  11. from Crypto.Cipher import AES, PKCS1_OAEP
  12. db = sqlite3.connect('Account.db', timeout=30)
  13. cur = db.cursor()
  14. window = Tk()
  15. messages = Text(window)
  16. input_user = StringVar()
  17. input_field = Entry(window, text=input_user)
  18. cur.execute(f"SELECT API_ID FROM Account WHERE ID = '{1}'")
  19. api_id = str(cur.fetchone()[0])
  20. time.sleep(1)
  21. cur.execute(f"SELECT API_HASH FROM Account WHERE ID = '{1}'")
  22. api_hash = str(cur.fetchone()[0])
  23. time.sleep(1)
  24. session = "anon31"
  25. client = TelegramClient("anon31", api_id, api_hash).start()
  26. client.start()
  27. time.sleep(1)
  28. cur.execute(f"SELECT ID_SOB FROM Account WHERE ID = '{1}'")
  29. id_sob = str(cur.fetchone()[0])
  30. zorro = int(id_sob)
  31. time.sleep(1)
  32. def Enter_pressed(event):
  33. input_get = input_field.get()
  34. print(input_get)
  35. print("Зашифровка")
  36. sms = str(input_get)
  37. chars = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
  38. smssKa = ""
  39. for i in range(40):
  40. smssKa += random.choice(chars)
  41. print(smssKa)
  42. data = sms.encode("utf-8")
  43. binx = str(smssKa) + ".bin"
  44. file_out = open(binx, "wb")
  45. cur.execute(f"SELECT MY_ID FROM Account WHERE ID = '{1}'")
  46. my_id = str(cur.fetchone()[0])
  47. my_key = str(my_id) + ".pem"
  48. recipient_key = RSA.import_key(open(my_key).read())
  49. session_key = get_random_bytes(16)
  50. cipher_rsa = PKCS1_OAEP.new(recipient_key)
  51. enc_session_key = cipher_rsa.encrypt(session_key)
  52. cipher_aes = AES.new(session_key, AES.MODE_EAX)
  53. ciphertext, tag = cipher_aes.encrypt_and_digest(data)
  54. [ file_out.write(x) for x in (enc_session_key, cipher_aes.nonce, tag, ciphertext) ]
  55. file_out.close()
  56. print("Отправка шифровки")
  57. cur.execute(f"SELECT NAME FROM Account WHERE ID = '{1}'")
  58. name = str(cur.fetchone()[0])
  59. async def main():
  60. await client.send_file(name, binx)
  61. client.loop.run_until_complete(main())
  62. messages.insert(INSERT, '%s\n' % input_get)
  63. input_user.set('')
  64. return "break"
  65. frame = Frame(window)
  66. frame.pack()
  67. messages.pack()
  68. input_field.pack(side=BOTTOM, fill=X)
  69. input_field.bind("<Return>", Enter_pressed)
  70. def run_bot_events():
  71. loop = asyncio.new_event_loop()
  72. asyncio.set_event_loop(loop)
  73. loop.run_until_complete(async_run_events(loop))
  74. async def async_run_events(loop):
  75. eventing_client = await TelegramClient("anon32", api_id, api_hash, loop=loop).start()
  76. @eventing_client.on(events.newmessage.NewMessage(from_users=zorro))
  77. async def handler(event):
  78. if event.media is not None:
  79. chars1 = 'abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
  80. smssKa1 = ""
  81. for i in range(50):
  82. smssKa1 += random.choice(chars1)
  83. print(smssKa1)
  84. biny = str(smssKa1) + ".bin"
  85. task = eventing_client.loop.create_task(event.download_media(biny))
  86. await task
  87. print("Дешефровка!")
  88. file_in = open(biny, "rb")
  89. private_key = RSA.import_key(open("private.pem").read())
  90. enc_session_key, nonce, tag, ciphertext = \
  91. [ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
  92. cipher_rsa = PKCS1_OAEP.new(private_key)
  93. session_key = cipher_rsa.decrypt(enc_session_key)
  94. cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
  95. data2 = cipher_aes.decrypt_and_verify(ciphertext, tag)
  96. print(data2.decode("utf-8"))
  97. enk = data2.decode("utf-8")
  98. messages.insert(INSERT, '%s\n' % enk)
  99. await eventing_client.run_until_disconnected()
  100. threading.Thread(target=run_bot_events).start()
  101. window.mainloop()