Remote-Code-Command-execution

A naive ssh clone, with screen sharing
git clone https://github.com/abdulrahim2002/Remote-Code-Command-execution

Log | Files | Refs | README

client.py (2759B)


      1 import socket
      2 import threading
      3 import time
      4 import utility
      5 IP = utility.get_ip_address()
      6 
      7 c_obj = threading.Condition()
      8 PORT = 5566
      9 ADDR = (IP, PORT)
     10 SIZE = 1024
     11 FORMATmsg = "utf-8"
     12 USERNAME = None
     13 PIN = None
     14 client = None
     15 S_PORT = None
     16 
     17 
     18 def send_message():
     19     # c_obj.acquire()
     20     while True:
     21         msg = input("")
     22         globals()['client'].send(msg.encode(FORMATmsg))
     23 
     24 
     25 def recieve_messsage():
     26     # c_obj.acquire()
     27     while True:
     28 
     29         msg = globals()['client'].recv(SIZE).decode(FORMATmsg)
     30 
     31         print(f"[SERVER] {msg}")
     32         pass
     33 
     34 
     35 def startClient():
     36     print(f"[CONNECTING] Client connecting to server at {IP}:{PORT}")
     37     globals()['client'] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     38     globals()['client'].connect(ADDR)
     39     print(f"[CONNECTED] Client connected to server at {IP}:{PORT}")
     40 
     41 
     42 def main():
     43     utility.printUI()
     44 
     45     while True:
     46         startClient()
     47 
     48         # [TAB] for inputting, sending and verifyin username
     49         if globals()['USERNAME'] == None or globals()['USERNAME'] == "!NOTACCEPTED":
     50             while True:
     51                 globals()['USERNAME'] = input("[LOGIN] INPUT USERNAME: ")
     52 
     53                 globals()['client'].send(
     54                     globals()['USERNAME'].encode(FORMATmsg))
     55                 temp_msg = globals()['client'].recv(SIZE).decode(FORMATmsg)
     56                 if (temp_msg == globals()['USERNAME']):
     57                     print(f"[SERVER] Username accepted")
     58                     break
     59                 else:
     60                     print("[NAME ERROR] Try another username")
     61                     continue
     62 
     63         if globals()['PIN'] == None:
     64             globals()['PIN'] = input("[LOGIN] Input PIN: ")
     65         globals()['client'].send(globals()['PIN'].encode(FORMATmsg))
     66 
     67         temp_msg = globals()['client'].recv(SIZE).decode(FORMATmsg)
     68         print(f"[SERVER] {temp_msg}")
     69         if temp_msg == "try again":
     70             print(
     71                 '[SERVER]: PIN not accepted:(\n[SERVER]: Connection failed:(\nTerminating:(\n')
     72             globals()['client'].close()
     73             exit()
     74 
     75         print(
     76             f"[AUTHENTICATED] credentials are verified by server at {IP}:{PORT}")
     77 
     78         print(f"[Waiting] Waiting for port number from {IP}:{PORT}")
     79         globals()['client'].send("PORT".encode(FORMATmsg))
     80         temp_msg = globals()['client'].recv(SIZE).decode(FORMATmsg)
     81         globals()['S_PORT'] = int(temp_msg)
     82         print(f"[SERVER] Your port number is {globals()['S_PORT']}")
     83         # input("end")
     84         break
     85 
     86     thread_recv = threading.Thread(target=recieve_messsage, args=())
     87     thread_recv.start()
     88     time.sleep(0.1)
     89     thread_send = threading.Thread(target=send_message, args=())
     90     thread_send.start()
     91 
     92     pass
     93 
     94 
     95 if __name__ == "__main__":
     96     main()