-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcovertele.py
85 lines (65 loc) · 2.57 KB
/
covertele.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# LabunskyA wrote this file
# Distributed under the Simplified BSD License
import socks, sys, getpass, string
from telethon import functions, errors, sync
from cochannel import CovertChannel, CoverChannelStateAPI
api_id = 0
api_hash = ''
proxy = None
# proxy = (socks.HTTP, "163.172.220.221", 8888)
class TelegramBlockingAPI(CoverChannelStateAPI):
def __init__(self, user, phone: string = None, on_code=None, on_2fa=None, proxy=None):
client = sync.TelegramClient(user, api_id, api_hash, proxy=proxy)
client.connect()
if not client.is_user_authorized():
if phone is None:
phone = input("Enter your phone number: ")
client.send_code_request(phone)
try:
if on_code is None:
client.sign_in(phone, input("Enter auth code: "))
else:
client.sign_in(phone, on_code())
except errors.SessionPasswordNeededError:
if on_2fa is None:
client.sign_in(password=getpass.getpass())
else:
client.sign_in(password=on_2fa())
self.__client = client
def send_bit(self, bit: bool, dest: string):
if bit:
return self.__client(functions.contacts.BlockRequest(id=dest))
else:
return self.__client(functions.contacts.UnblockRequest(id=dest))
def receive_bit(self, src: string) -> bool:
status = self.__client(functions.users.GetUsersRequest([src]))[0].status
if status is None:
return True
else:
return False
def get_state(self, dest) -> bool:
return self.__client(functions.users.GetFullUserRequest(dest)).blocked
def usage():
print("Usage: python3", sys.argv[0], "[-s/-r] [your username] [other username] [message]")
print("If there is no connection (nothing is happening), try setting proxy in the scrypt file")
if len(sys.argv) != 4 and sys.argv[1] == "-r" or len(sys.argv) < 5 and sys.argv[1] == "-s":
usage()
exit(-1)
user = sys.argv[2]
friend = sys.argv[3]
channel = CovertChannel(TelegramBlockingAPI(user, proxy=proxy), friend, verbose=True)
if sys.argv[1] == "-s":
message = ""
i = 4
while i < len(sys.argv) - 1:
message += sys.argv[i] + " "
i += 1
message += sys.argv[i]
print("Started message transmission...")
channel.send(message)
print("Done, exiting...")
elif sys.argv[1] == '-r':
print("Listening for the message...")
message = channel.receive()
print("Automatically decoded:", message)
exit(0)