/ simple_cnc.py
simple_cnc.py
 1  import socket
 2  
 3  def main():
 4      # Create a TCP/IP socket
 5      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 6      
 7      # Bind the socket to the port
 8      server_address = ('localhost', 12345)
 9      print('starting up on {} port {}'.format(*server_address))
10      sock.bind(server_address)
11  
12      # Listen for incoming connections
13      sock.listen(1)
14      
15      while True:
16          # Wait for a connection, then concurrently process the request on a new thread
17          print('waiting for a connection')
18          client, address = sock.accept()
19          print('connection from', address)
20          
21          # Execute command on client's request
22          while True:
23              try:
24                  data = client.recv(1024).decode("utf-8")
25                  if not data:
26                      break
27                  print